From jan@swi.psy.uva.nl Mon May  7 17:33:18 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f47FXI321255;
	Mon, 7 May 2001 17:33:18 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f47FXHF16702;
	Mon, 7 May 2001 17:33:17 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "andris r" <rajano@my-deja.com>, prolog@swi.psy.uva.nl
Subject: Re: [SWIPL] Is there another way to assert ?
Date: Mon, 7 May 2001 17:12:13 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <200105071458.HAA04036@mail9.bigmailbox.com>
In-Reply-To: <200105071458.HAA04036@mail9.bigmailbox.com>
MIME-Version: 1.0
Message-Id: <01050717331704.04816@gollem>
Content-Transfer-Encoding: 8bit

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

