[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: reading prolog terms
From: |
Fumio Aoki |
Subject: |
Re: reading prolog terms |
Date: |
Thu, 21 Nov 2002 12:26:32 -0500 |
Thank you, Lindsey.
I changed the C code as you adviced, I got all the items in the prolog list.
I greatly appreciate your help.
Here is the C program:
---
PlTerm itemsListTerm = arg[2];
if( Blt_List(itemsListTerm) )
{
int itemsListLength = List_Length(itemsListTerm);
PlTerm * itemTerms = calloc( sizeof(void*), itemsListLength );
Rd_Proper_List(itemsListTerm, itemTerms);
for( ofst = 0; ofst < itemsListLength; ofst++ )
{
sol[i] = Rd_String(itemTerms[i]);
/* do interesting stuff with 'term' here. */
printf("%s\n",sol[i]);
}
}
----
Best regards,
Fumio
---
Fumio Aoki, Ph.D., Department of Ecology and Evolution,
State University of New York at Stony Brook, Stony Brook, NY 11794-5245
Email: address@hidden, Phone: (631) 632-8539, Fax: (631) 632-7626
URL: http://life.bio.sunysb.edu/~aoki/ or http://cauchy.bio.columbia.edu/fumio/
----- Original Message -----
From: "Lindsey Spratt" <address@hidden>
To: "Fumio Aoki" <address@hidden>
Cc: <address@hidden>
Sent: Thursday, November 21, 2002 11:50 AM
Subject: Re: reading prolog terms
> Here are some thoughts:
>
> I assume your 'arg[2]' is filled in by a call to gprolog, and that you
> are now trying to extract the list assumed to be in arg[2]. The
> following code gets pointers to the terms in 'arg[2]' into an array
> 'itemTerms'. Then you can walk over this array getting each 'term' and
> processing it (e.g. converting an atom to a string).
>
> PlTerm itemsListTerm = arg[2];
>
> if( Blt_List(itemsListTerm )
> {
> int itemsListLength = List_Length(itemsListTerm);
> PlTerm * itemTerms = calloc( sizeof(void*), itemsListLength );
> PlTerm term = NULL;
>
> Rd_Proper_List(itemsListTerm, itemTerms);
>
> for( ofst = 0; ofst < itemsListLength; ofst++ )
> {
> term = itemTerms[ofst];
> /* do interesting stuff with 'term' here. */
> }
> }
>
> Hope this helps,
> Lindsey Spratt
> http://homepage.mac.com/lspratt
>
>
>