[mercury-users] Where is MR_list_cons declared? (`MR_mr5' undeclared)

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 25 21:27:17 AEST 2001


On 25-Oct-2001, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> Hello.
> 
>   I'm trying to call C++ code from Mercury. Now, I managed to compile a
> hello-world (using a C interface, extern "C" wrapped), but I need to share
> a list(int) structure across the codes (there and back again).
> 
>   I'm able to send the list(int) data to the C function and to parse it
> with MR_list_* macros.
> 
>   Unfortunately, I'm not able to create a list(int) in the C code:
> 
> MR_Word myoutlist;
> int i;
> 
> myoutlist = MR_list_empty();
> for(i=20; i>10; i--) {
>     myoutlist =  MR_list_cons(i, myoutlist);
> }
> 
> 
> ...reports MR_mr5 undeclared on the line where MR_list_cons is used.
> 
>   What should I #include? (I include only a "mercury_lib.h", a header file
> generated automatically when compiling mercury_lib.m in the
> cplusplus_calls_mercury samples directory.)

Those macros are only usable from C code, not from C++ code.

If you want the same thing for C++, you can just define some simple
functions in Mercury and export them, e.g. like this:

	:- interface.

	:- func nil = list(int).
	:- func cons(int, list(int)) = list(int).

	:- implementation.

	nil = [].
	cons(X, Y) = [X|Y].

	:- pragma export(nil = out, "my_nil").
	:- pragma export(cons(in, in) = out, "my_cons").

Then you can call the exported functions my_nil() and my_cons()
instead of the macros MR_list_empty() and MR_list_cons().

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  | "... it seems to me that 15 years of
The University of Melbourne         | email is plenty for one lifetime."
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- Prof. Donald E. Knuth
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list