[mercury-users] choicepoint IDs in the C interface

Peter Biener pbi at info.fundp.ac.be
Wed Apr 29 02:25:35 AEST 2009


Hello,

I have a question about the foreign interface with C. The reference 
manual says that the MR_current_choicepoint_id() function returns the ID 
of the most recent choicepoint. I tried it with a very simple code, just 
wrote a predicate in C that writes the id to the output. If this 
predicate called several times, it writes different choicepoint IDs each 
time. Since in this code every predicate, including print/3 and nl/2 are 
deterministic, I think I should always get the same id. Instead I got 
this output:

a1
b1: 21
a2
b2: 25
b3: 26
a3

Can you help me on what I think wrong?

Best regards,
Peter Biener



:- module cptest.

:- interface.
:- import_module io.

:- pred main(io__state, io__state).
:- mode main(di, uo) is det.


:- implementation.

:- pragma foreign_decl("C",
"
    #include ""mercury_trail.h""
").


main(!IO):-
    print("a1", !IO), nl(!IO),
    write_current_choicepoint_id("b1", !IO),
    print("a2", !IO), nl(!IO),
    write_current_choicepoint_id("b2", !IO),
    write_current_choicepoint_id("b3", !IO),
    print("a3", !IO), nl(!IO).


:- pred write_current_choicepoint_id(string, io__state, io__state).
:- mode write_current_choicepoint_id(in, di, uo) is det.

:- pragma promise_pure(write_current_choicepoint_id/3).

:- pragma foreign_proc("C", write_current_choicepoint_id(Key::in, 
IO0::di, IO::uo),
    [will_not_call_mercury],
"
    printf(\"%s: %i\\n\", Key, MR_current_choicepoint_id());
    IO = IO0;
").
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cptest.zip
Type: application/zip
Size: 802 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/users/attachments/20090428/6c3e123c/attachment.zip>


More information about the users mailing list