[eclipse-users] help embebing C/C++ and CHR in eclipse

From: J. Manuel Velasco <jvelasco_at_...4...>
Date: Wed, 8 Nov 2006 16:44:52 +0100
El Miércoles, 8 de Noviembre de 2006 03:01, Joachim Schimpf escribió:
> J. Manuel Velasco wrote:
> > // Try  to call the prolog main function defined in prologCode
> > post_goal(term(EC_functor("main",4), A,B,C,D, Result));
>
> main/4 has 4 arguments, but you are giving 5: A,B,C,D,Result.

Yes, thank you. I realised that after. This is my current C/C++ code:

% ----------------------
% prologCode.pl
% ----------------------
:- [orientacion_main,orientacion].
main(A,B,C,D) :- ctr_orient(C,A,B,[lm]),ctr_orient(D,C,B,[lm]).
:- main(A,B,C,D).

% -------------------------------------
% - cc_orientacion.cc
% C/C++ file
% -------------------------------------

#include "eclipseclass.h"
#include <iostream>

using namespace std;

main()
{

ec_init();

post_goal(term(EC_functor("compile",1),"prologCode"));

if (EC_resume() != EC_succeed)
{
  cout << "Compilation failed\n";
  exit(-1);
}

EC_ref Result;
EC_ref A,B,C,D;

post_goal(term(EC_functor("main",4), A,B,C,D));
if (EC_resume() == EC_succeed)
{
  // somebody told me that I need that to allow backtracking   
  post_goal(EC_atom("fail"));  
  }
else
 {
   cout << "goal failed" << endl;
 }

ec_cleanup();    

}
%----------

In the orientacion.chr file I write into a file when a constraint is 
triggered, like that:

% Initialize

ctr_orient(C,A,B,Rel) <=> length(Rel,N) | ctr_orient(N,C,A,B,Rel,1), 
open(file, write, S), write(S, ctr_orient(N,C,A,B,Rel,1)), close(S).

% Intersection

ctr_orient(N1,C,A,B,R1,I), ctr_orient(N2,C,A,B,R2,J) <=> 
intersection(R1,R2,R3), length(R3,N3), K is min(I,J) | 
ctr_orient(N3,C,A,B,R3,K), open(file, append, S), write(S, 
ctr_orient(N3,C,A,B,R3,K)), close(S).

.
.
.

% Composition

ctr_orient(N1,C,A,B,R1,I),ctr_orient(N2,D,B,C,R2,J) ==> I=1, 
composition_op(R1,R2,R3), length(R3,N3), K is I+J | 
ctr_orient(N3,D,A,B,R3,K), open(file, append, S), write(S, 
ctr_orient(N3,D,A,B,R3,K)), close(S).
but only one line is written.

.
.
.

But the result of the execution is that only first line is written:

% "file" content
ctr_orient(1, A, B, C, [lf], 1)

and the result of the executoin in prolog environment is:

[eclipse 2]: main(A,B,C,D).

A = A
B = B
C = C
D = D


Constraints:
(2) ctr_orient(1, C_280, A_294, B_308, [lm], 1)
(4) ctr_orient(1, D_1244, C_280, B_308, [lm], 1)
(5) ctr_orient(3, D_1244, A_294, B_308, [lf, l, lm], 2)
(9) ctr_orient(5, D_1244, C_280, A_294, [lm, ibl, bl, sb, br], 2)

We would like to write into the file the constraints 2,4,5 and 9

I don't know why there are not written.

Excuse me to bother you so much. Your advices and guide are really welcome. I 
feel really gratefull.

Thanks a lot.

To write a new line, i found nl(fileId) commnad. It's ok, thanks.

Best Regards and good luck.
Received on Wed Nov 08 2006 - 15:44:18 CET

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST