I try to implement a C interface using a Prolog script based on GNU Prolog. My problem is to get single elements of a nested Prolog list.
Actually my C code looks like
...
int func;
PlTerm arg[10];
PlTerm *sol_gb;
PlBool res;
int nmb;
char *strHead;
char *strTail;
PlLong nummero;
PlTerm pl_nummero;
Pl_Start_Prolog(argc, argv);
Pl_Query_Begin(PL_TRUE);
arg[0] = Pl_Mk_String(strRName);
arg[1] = Pl_Mk_Variable();
arg[2] = Pl_Mk_Variable();
arg[3] = Pl_Mk_String("true");
res = Pl_Query_Call(func, 4, arg);
sol_gb = Pl_Rd_List(arg[2]);
nmb = Pl_List_Length(sol_gb[0]);
strHead = Pl_Write_To_String(sol_gb[0]);
printf("strHead = %s\n",strHead);
strTail = Pl_Write_To_String(sol_gb[1]);
printf("strTail = %s\n",strTail);
...
The Prolog list returned in arg[2] looks like
[ [ Spezial Bolognese,
[2, ,Zwiebeln,300,gramm,Hackfleisch,10, ,Tomaten,
100,ml,Sahne,500,gramm,Spaghetti]
],
[ Spaghetti Bolognese,
[2, ,Zwiebeln gehackt,300,gramm,Hackfleisch,10, ,Fleischtomaten,
100,ml,Sahne,500,gramm,Spaghetti]
]
]
The output of the conversion into a String is
strHead = [Spezial Bolognese,[2, ,Zwiebeln gehackt,300,gramm,Hackfleisch,
10, ,Fleischtomaten,100,ml,Sahne,500,gramm,Spaghetti]]
strTail = [[Spaghetti Bolognese,[2, ,Zwiebeln gehackt,300,gramm,Hackfleisch,
10, ,Fleischtomaten,100,ml,Sahne,500,gramm,Spaghetti]]]
So I assume, I am "nearly there" but as I have to re-activate my C knowledge I do not get the solution how to enter in the next level of the list to get finally each element as string ("Spezial Bolognese", next step: "2", "Zwiebeln" etc.).
How can I step through the Prolog list in C?
I would be very happy about every hint, thank you again!