Very general question about collaboration of C++/Mercury

Ulrich Mayring u at 123.org
Fri May 8 06:58:49 AEST 1998


Hello there,

first off, I'm a Prolog programmer and know next to nothing about Mercury. 
However, I read on the web-site that Mercury doesn't build executables, 
but generates C code. This has given me an idea on whose feasibility I 
would ask you to comment:

I am currently writing an application that on one hand has a rich and 
complex GUI, which should be very responsive and flexible as well. I am 
doing this part in Metrowerks CodeWarrior/PowerPlant, which is a C++ 
framework for the Macintosh (which is my target platform).

On the other hand at the bottom (or, if you will, at the top) of my app 
there exists data - not much now, but in the future there will be many 
types of various data that should be able to interact with each other 
intelligently. (Ultimately I might even want to have a visual modeller 
that generates that data, much like a 3D modeller that might generate 
OpenGL code or somesuch) Therefore I need to represent my data ideally in 
a declarative programming language, because that is just so much better 
than having some stupid C-style arrays and structs. On the other hand C 
compiles well and is fast. So, here's the scoop:

Does it sound like a good idea to do my knowledge representation in 
Mercury, compile the code to C and integrate the C code in my C++ app? 

To me two general questions arise (however, to you many more might):

1) Mercury-generated C ==> C++
How do I interface between Mercury-generated C and my C++ application 
classes? Are there standardized accessor functions or something like that? 
Or does it depend entirely on the code I write in Mercury? I realize it 
may be hard to answer this question, when the person who asks it doesn't 
know Mercury. Should I get to know it and come back later, maybe?

2) C++ ==> Mercury
The user might want to change data by manipulating some GUI elements. I 
can of course write these changes to my C++ data structures, but how do I 
get it back to Mercury?

Maybe I'm completely off target with my idea and should do everything 
totally different, but I thought to simply ask you Mercury guys, before 
going to the language reference (and getting an Intel-based PC ;)

Thanks a lot in advance for any comments,

Ulrich




More information about the users mailing list