Subject: Re: [SWIPL] Is there another way to assert ?

From: Jan Wielemaker <[email-masked]>
Date: Mon, 7 May 2001 17:12:13 +0200

On Mon, 07 May 2001, andris r wrote:
>This works fine:
>term_t term;
>...put something in term
>predicate_t assert=PL_predicate('assert',1,'user');
>PL_call_predicate(nil,PL_Q_NORMAL,assert,term);
>
>But is there a way to assert a term with no construction of it in C, like
>assert a string and let prolog handle it ?

You can have a look at the C++ interface that contains high-level
support.  Alternatively, the simplest way is to write a Prolog
predicate

assert_from_text(Text) :-
	term_to_atom(Term, Text),
	assert(Term).

Now call this predicate rather then assert.

Another alternative is to call PL_chars_to_term() to make the
translation:

{ term_t t = PL_new_term_ref();

  PL_chars_to_term("hello(world)", t);
  <assert t>
}

	--- Jan