From lains@caramail.com  Thu Aug 10 11:20:29 2000
Received: from mail.caramail.com (mail.caramail.com [195.68.99.70])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id LAA19825
	for <prolog@swi.psy.uva.nl>; Thu, 10 Aug 2000 11:20:13 +0200 (MET DST)
Received: from caramail.com (www18.caramail.com [195.68.99.38])
	by mail.caramail.com (8.8.8/8.8.8) with SMTP id LAA17876
	for prolog@swi.psy.uva.nl; Thu, 10 Aug 2000 11:27:06 +0100 (WET DST)
Date: Thu, 10 Aug 2000 11:27:06 +0100 (WET DST)
Posted-Date: Thu, 10 Aug 2000 11:27:06 +0100 (WET DST)
From: Lionel Ains <lains@caramail.com>
To: prolog@swi.psy.uva.nl
Message-ID: <965902782015837@caramail.com>
X-Mailer: Caramail - www.caramail.com
Mime-Version: 1.0
Subject: Foreign language interface : PL_new_term_ref()
Content-Type: multipart/mixed; boundary="=_NextPart_Caramail_015837965902782_ID"

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--=_NextPart_Caramail_015837965902782_ID
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

Just a quick question.
I believe that any term created by PL_new_term_ref() is automatically destructed when it goes out of 
scope. Could someone confirm?

Lionel

PS: So far, I'm creating handle terms from an integer (which is a table index):

static int unify_dictionary_handle_with_index(term_t handle_out, int index_in) {
 term_t index_in_term;
 
 if (PL_unify_functor(handle_out, FUNCTOR_dictionary1)) {
 index_in_term =3D PL_new_term_ref();
 PL_get_arg(1, handle_out, index_in_term);
 return (PL_unify_integer(index_in_term, index_in));
 }
 else {
 PL_fail;
 }
}

static int get_index_from_dictionary_handle(term_t handle_in, int *index_out) {
 term_t index_out_term;
 
 if (PL_is_functor(handle_in, FUNCTOR_dictionary1)) { /* Check if handle follows the '$dictionary'(...) 
template */
 index_out_term =3D PL_new_term_ref(); /* Create a term to contain the integer */
 if (!PL_get_arg(1, handle_in, index_out_term))
 PL_fail; /* Error, the handle doesn't follow the right template */
 if (!PL_get_integer(index_out_term, index_out))
 PL_fail; /* Error, the parameter for '$dictionary'/1 is not an integer! */
 if (*index_out>=3DNB_DICTIONARIES)
 PL_fail; /* Error, the index is greater than the dict_table size */
 }
 else
 PL_fail; /* Error, the handle is invalid because it is not a '$dictionary'/1 functor-based compound */
}

Thi relies on the fact that FUNCTOR_dictionary1 has been declared this way:
static functor_t FUNCTOR_dictionary1;
And has been create inside Prolog like that:
FUNCTOR_dictionary1 =3D PL_new_functor(PL_new_atom("$dictionary"), 1);

The two functions included just allow to create a handle from an index 
(unify_dictionary_handle_with_index) or an index from the handle 
(get_index_from_dictionary_handle).
This way, a '$dictionary'(1) term as the input of get_index_from_dictionary_handle will result by 
outputting the integer 1 and the index 3 as the input of unify_dictionary_handle_with_index will result 
by creating a handle term '$dictionary'(3).
______________________________________________________
Bo=EEte aux lettres - Caramail - http://www.caramail.com


--=_NextPart_Caramail_015837965902782_ID--

