Subject: Re: [SWIPL] Problem with dynamic facts

From: Jan Wielemaker <[email-masked]>
Date: Tue, 26 Feb 2002 11:57:52 +0100

[Please keep things on the mailing list (and don't send attachments)]

On Tuesday 26 February 2002 11:44, zze-PEX SOR balc031 FTRD/DTL/CAE wrote:

> Here are information about my program!
>
> ------------------------------------------------------------------
> predicate_t assert_pred = PL_predicate("assert", 1, "user");
> term_t      h0 = PL_new_term_refs(1);
> String 	line =  "deduce([status], [none], [], [], signature).";
>
> PL_put_atom_chars(h0, (char*) line.c_str());
> PL_call_predicate(NULL, PL_Q_NORMAL, assert_pred, h0);

If you examine the database, you'll find a predicate

'deduce([status], [none], [], [], signature).'.

Note the quotes!  PL_put_atom_chars() creates an atom, not a term,
so you are calling

assert('deduce([status], [none], [], [], signature).').

You have to create a term and fill the arguments if you use the
C-interface.  The real C++ interface (see home page; there are
two now) allows for creating terms using the Prolog parser.  Note
however that this is a lot slower than creating the term using the
primitives and in most cases your term doesn't come from a fixed
string (otherwise you could have placed it in the Prolog code
right away).  If your term comes from something generated, building
the term becomes even more attractive as you don't have to deal
with quoting rules, allocate space for the string, etc.

	--- Jan