<div dir="ltr">Zoltan, thank you...that sounds good to me...I am reading as much source code as and when I can but I still have less than about 30 hours of exposure to Mercury so far and the FFI etc is particularly challenging.<div><br></div><div>Fortunately my limited brain power completely understands your response, that feels a good clean wholesome way to go about it.</div><div><br></div><div>Thanks again,</div><div>Sean.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 10 Jul 2019 at 10:19, Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com">zoltan.somogyi@runbox.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On Wed, 10 Jul 2019 09:46:31 +0100, emacstheviking <<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>> wrote:<br>
> Any clues in the documentation as to where I can find out how to do this?<br>
<br>
If by "this" you mean "how to construct Mercury terms from C", the answer is:<br>
there is no clue in the documentation, because this is not supported.<br>
<br>
As I said a few days ago, there are a few C macros for accessing Mercury lists,<br>
but that is all. Even those are there only because they are needed for the<br>
implementation of other parts of the Mercury system. <br>
<br>
> It's just knowing what the "way" is?!?!<br>
<br>
The standard way in cases like this is, where the C code may or may not succeed,<br>
is to have two predicates.<br>
<br>
The inner predicate is implemented in C, and returns two things:<br>
the item you want to compute (in this case, a non-null pointer), and a bool that says<br>
whether you succeeded. (The two values of bools in C are MR_TRUE and<br>
MR_FALSE.)<br>
<br>
The outer predicate calls the inner predicate, tests the bool, and returns either "no"<br>
if the bool is no, or "yes(Item)" if the bool is yes. Crucially, the yes() wrapper is added<br>
by Mercury code, not C code.<br>
<br>
In general, the values passing through the Mercury /Cinterface fall into three categories:<br>
(1) values of primitive types such as integers, floats, chars, strings, and bools;<br>
(2) values of types defined in Mercury that are opaque to C, and (c) values of types<br>
defined in C that are opaque to Mercury.<br>
<br>
Zoltan.<br>
</blockquote></div>