After the successful return of PrologNextSolution
, the values
assigned to the variables of the query can be retrieved by
specific functions of the interface. There are separate functions for
retrieving the variable values in string, quoted string and integer
formats.
The PrologGetLong
function retrieves the integer value of a given
variable within a query and assigns it to a variable. That is,
the value of the given variable is converted to an integer. Returns 1
on success.
Example:
The following code fragment assigns the value 2 to the variable v
:
Dim qid As Long Q = "member(X,[1,2,3]), X > 1" qid = PrologOpenQuery(Q) Call PrologNextSolution(qid) Call PrologGetLong(qid,"X",v)
The PrologGetString
function retrieves the value of a given
variable in a query as a string. That is, the value of the
variable is written out using the write/2
Prolog predicate,
and the resulting output is stored in a Visual Basic variable. Retuns 1
on success.
Example: let us suppose we have the following clause in a Prolog program:
capital_of('Sweden'-'Stockholm').
The code fragment below assigns the string "Sweden-Stockholm"
to the variable capital
:
Dim qid As Long Q = "capital_of(Expr)" qid = PrologOpenQuery(Q) If PrologNextSolution(qid) = 1 Then Call PrologGetString(qid,"Expr",capital) End if Call PrologCloseQuery(qid)
The PrologGetStringQuoted
function is the same as
PrologGetString
, but the conversion uses the writeq/2
Prolog predicate. Returns 1 on success.
Example:
if the function PrologGetStringQuoted
is used in the code above
instead of the PrologGetString
function, then the value assigned to
the variable capital
is "'Sweden'-'Stockholm'"
.
The only way of transferring information from Prolog to Visual Basic is
by the above three PrologGet...
functions. This means that,
although arbitrary terms can be passed to Visual Basic, there is
no support for the transfer of compound terms such as lists
or structures. We will show examples of how to overcome this limitation
later in the manual (see Examples).