API functions that initiate Prolog execution or unification return TF, a Prolog true/false. Most other functions return RC, an error checkable function return.
Many API functions require you to specify the type of the Prolog term, pTYPE. pTYPE is an enumerated constant with these values.
Other API functions require you to specify the type of the host language variable, cTYPE. cTYPE is an enumerated constant with these values.
Other defined types are
A few API functions manipulate Prolog I/O streams. They use the enumerated constant STREAM to identify the streams. Values of STREAM are
The exectipn types, ExType, are:
See amzi.h for the exact implementations of all data types.
Description:
void AddLSX(STRptr lsxname, VOIDptr vp);
RC lsAddLSX(ENGid cureng, STRptr lsxname, VOIDptr vp);
Remarks:
Causes the Logic Server to load the specified LSX file. Like other API functions that initialize extended predicates, lsAddLSX() must come after a call to lsInit() and before a call to lsLoad().
See Extended Predicate Libraries (LSXs) and Writing Extended Predicates
Return Value:
OK if everything worked
Example:
try { Init("dbgene"); AddLSX("ls4odbc", NULL); // Load the LSX file Load("dbgene"); } catch(CLSException &E) { PrologError(E); }
Description:
void AddPred(STRptr functor, ARITY arity, ExtPred fp, VOIDptr vp);
RC lsAddPred(ENGid cureng, STRptr functor, ARITY arity, ExtPred fp, VOIDptr
vp)
Remarks:
Adds the predicate functor/arity to the extended predicate table, mapping it to the function pointed to by fp. Like lsInitPreds(), lsAddPred() must be called between the calls to lsInit() and lsLoad().
The fourth argument is used in the callback. This argument is passed as the first argument to the extended predicate. This feature allows you to implement call backs to member functions of class. The extended predicate becomes a dispatch function, that uses the argument as a pointer to an object that is used to implement the extended predicate. See the C++ PetsCB and Rubik's cube samples for an example of this technique.
NOTE that when lsInitPreds is called, this fourth argument is automatically generated to be the engine ID, so call back functions get the engine ID passed as a parameter.
See Extended Predicate Libraries (LSXs) and Writing Extended Predicates
Return Value:
Returns OK if it worked.
Example:
This code adds an extended predicate called msgbox that takes one argument.
TF p_msgbox(){...} ... rc = lsInit... rc = lsAddPred(eid, "msgbox", 1, p_msgbox); rc = lsLoad...
Description:
void Asserta(TERM term);
RC lsAsserta(ENGid cureng, TERM term);
Remarks:
Asserts the term to the dynamic database as the first clause under the key which is the term's functor. Same as Prolog asserta/1 and assert/1.
See Asserting and Retracting to and from the Prolog Database
Return Value:
Returns OK if it worked, NOTOK if some indeterminate error happened, and an atom (small positive integer) if the term redefined a protected predicate.
Description:
void AssertaStr(STRptr str);
RC lsAssertaStr(ENGid cureng, STRptr str);
Remarks:
A convenient form of lsAsserta() that uses a string instead of a term. Asserts the term to the dynamic database as the first clause under the key which is the term's functor. Same as Prolog asserta/1 and assert/1.
See Asserting and Retracting to and from the Prolog Database
Return Value:
Returns OK if it worked, NOTOK if some indeterminate error happened, and an atom (small positive integer) if the term redefined a protected predicate.
Example:
/* Assert the name of the .xpl file (used to load the logic-base) */ strcpy(strbuf, "system('XPL File', '"); strcat(strbuf, xplname); strcat(strbuf, "')"); rc = lsAssertaStr(CurEng, strbuf);
Description:
void Assertz(TERM term);
RC lsAssertz(ENGid cureng, TERM term);
Remarks:
Asserts the term to the dynamic database as the last clause under the key which is the term's functor. Same as Prolog assertz/1.
See Asserting and Retracting to and from the Prolog Database
Return Value:
Returns OK if it worked, NOTOK if some indeterminate error happened, and an atom (small positive integer) if the term redefined a protected predicate.
Example:
/* Assert facts to the Prolog dynamic database */ /* Read them from the test file for now */ fp = fopen(sTestFile, "r"); for (i=0; i<16; i++) { fgets(buf, 80, fp); lsStrToTerm(CurEng, &t, buf); lsAssertz(CurEng, t); }
Description:
void AssertzStr(STRptr str);
RC lsAssertzStr(ENGid cureng, STRptr str);
Remarks:
A convenient form of lsAssertz() that uses a string instead of a term. Asserts the term to the dynamic database as the last clause under the key which is the term's functor. Same as Prolog assertz/1.
See Asserting and Retracting to and from the Prolog Database
Return Value:
Returns OK if it worked, NOTOK if some indeterminate error happened, and an atom (small positive integer) if the term redefined a protected predicate.
Example:
/* Assert facts to the Prolog dynamic database */ /* Read them from the test file for now */ fp = fopen(sTestFile, "r"); for (i=0; i<16; i++) { fgets(buf, 80, fp); lsAssertzStr(CurEng, buf); }
Description:
TF Call(TERMptr termp);
TF lsCall(ENGid cureng, TERMptr termp);
Remarks:
Once a term has been created it can be passed to the Amzi! interpreter with lsCall(). This is equivalent to the Prolog statement call(X) where X is a Prolog term.
See Calling Terms
Return Value:
Returns TRUE/FALSE
Example:
ENGid cureng; TERM t; TF tf; lsStrToTerm(cureng, &t, "parent(elaine,mary)"); tf = lsCall(cureng, &t); if (tf) printf("Elaine is Mary's parent"); else printf("Elaine is not Mary's parent");
Description:
TF CallStr(TERMptr termp, STRptr str);
TF lsCallStr(ENGid cureng, TERMptr termp, STRptr str);
Remarks:
lsCallStr() is a more convenient form of lsCall() that lets you use the string representation of a Prolog term or query.
Return Value:
Returns TRUE/FALSE
Example:
ENGid cureng; TERM t; TF tf; tf = lsCallStr(cureng, &t, "parent(elaine,mary)"); if (tf) printf("Elaine is Mary's parent"); else printf("Elaine is not Mary's parent");
Description:
RC ClearCall();
RC lsClearCall(ENGid cureng)
Remarks:
A call to lsCall() or lsCallStr() causes the Prolog engine to build a backtracking choice point on the Prolog control stack. Successive calls to lsRedo() will cause the choice point to be removed when there are no more choices.
If you do not exhaust all the choices with lsRedo() calls, then a call to lsClearCall() can be made to remove the choice point from the stack. It is not in general necessary, but is good form and might be required if the lsCall() is in a tight loop, thus using up the control stack.
lsCall() and lsCallStr() should not be used when the call is intended to be executed only once. For those situations lsExec() and lsExecStr() should be used, which do not add a choice point to the Prolog control stack.
See Scope of Logic Server Terms
Return Value:
OK
Description:
void Close();
RC lsClose(ENGid cureng);
Remarks:
Closes down the Prolog environment, closing Prolog streams and freeing all memory allocated by Prolog.
Return Value:
OK
Example:
lsClose(cureng);
Description:
void ErrRaise(STRptr msg);
RC lsErrRaise(ENGid cureng, STRptr msg)
Remarks:
Causes an Exec type Prolog error to be raised with the specified error message.
See Error Handling
Description:
TF Exec(TERMptr termp);
TF lsExec(ENGid cureng, TERMptr termp);
Remarks:
lsExec() and lsExecStr() are similar to lsCall() and lsCallStr(). The only difference is the Exec functions are intended to be called only once and not backtracked into. That is, you cannot call lsRedo() after lsExec(), but you can after lsCall().
The advantage of lsExec() calls over lsCall() calls is they do not add anything to the Prolog execution stack, so they can be called with no overhead. The disadvantage, of course, is you can't backtrack through them.
See Calling Terms
Return Value:
Returns TRUE/FALSE
Description:
TF ExecStr(TERMptr termp, STRptr str);
TF lsExecStr(ENGid cureng, TERMptr termp, STRptr str);
Remarks:
lsExecStr() is a more convenient form of lsExec() that lets you use the string representation of a Prolog term or query.
Return Value:
Returns TRUE/FALSE
Example:
if ( TRUE == (tf = lsExecStr(e2, &t, "pet(X)")) ) { lsGetArg(e2, t, 1, cSTR, buf); printf("Engine two's pet is a %s\n", buf); }
Description:
void GetArg(TERM term, int iarg, cTYPE ctype, VOIDptr valp);
RC lsGetArg(ENGid cureng, TERM term, int iarg, cTYPE ctype, VOIDptr valp);
Remarks:
Used to extract arguments from complex structures.
Visual Basic Note: When retrieving strings from VB, you must specify 'ByVal' for the VOIDptr val argument.
See Mapping Prolog Arguments to Host Variables
Return Value:
OK if it worked, NOTOK if it didn't.
Example:
tf = lsCall(CurEng, &t); while(tf) { lsGetFA(CurEng, t, sRelation, &arity); lsGetArg(CurEng, t, 1, cSTR, sSib1); lsGetArg(CurEng, t, 2, cSTR, sSib2); printf("%s is %s of %s\n", sSib1, sRelation, sSib2); tf = lsRedo(CurEng); }
Description:
pTYPE GetArgType(TERM term, int iarg);
pTYPE lsGetArgType(ENGid cureng, TERM term, int iarg);
Remarks:
Gets the type of the iargth argument of term, assuming term is a structure.
See Mapping Prolog Arguments to Host Variables
Return Value:
pTYPE, see the Data Types section for possible values.
Description:
void CLSException::GetCallStack(STRptr str, int len);
RC lsGetExceptCallStack(ENGid cureng, STRptr str, int len)
Remarks:
Gets the call stack when the current exception occurred.
See Error Handling
Return Value:
OK
Description:
void CLSException::GetMsg(STRptr str, int len);
RC lsGetExceptMsg(ENGid cureng, STRptr str, int len);
Remarks:
Gets the message for the current error.
See Error Handling
Return Value:
OK
Example:
rc = lsLoad(CurEng, xplname); if (rc != 0) { lsGetExceptMsg(CurEng, errmsg, 1024); printf("Fatal Error #%d loading Amzi! Logic Server .xpl file:\n%s", rc, errmsg); }
Description:
void CLSException::GetReadBuffer(STRptr str, int len);
RC lsGetExceptReadBuffer(ENGid cureng, STRptr str, int len)
Remarks:
Gets the current read buffer which includes the words "<-Near Here->" to indicate the location of the read error, or at least where the Prolog reader realized it was in trouble.
See Error Handling
Return Value:
OK
Description:
void CLSException::GetReadFileName(STRptr str, int len);
RC lsGetExceptReadBuffer(ENGid cureng, STRptr str, int len)
Remarks:
Gets the name of the file, if any, that was open when a read error occurred. The name is an empty string if the read error occurred during string I/O or console I/O.
See Error Handling
Return Value:
OK
Description:
int CLSException::GetReadLineno();
int lsGetExceptReadLineno(ENGid cureng)
Remarks:
If the read error occurred during file I/O, this function returns a line number in the file close to where the error occurred.
See Error Handling
Return Value:
OK
Description:
ExType CLSException::GetType();
ExType lsGetExceptType(ENGid cureng)
Remarks:
Returns the type of the current exception. See the section on Data Types for the values of ExType.
See Error Handling
Return Value:
The exception type.
Description:
RC CLSException::GetRC();
RC lsGetExceptRC(ENGid cureng)
Remarks:
Returns the return code of the current exception.
See Error Handling
Return Value:
The return code
Description:
void GetFA(TERM term, STRptr functor, ARITYptr, arityp);
RC lsGetFA(ENGid cureng, TERM term, STRptr functor, ARITYptr arityp);
Remarks:
This function lets you determine the functor and arity of a term. If the term is an atom, then the arity will be 0. If the term is a list then the functor will be "." and the arity 2.
Return Value:
Returns OK for the three types of terms described above, returns NOTOK if the term is not a legal atom, structure or list.
Example:
ENGid cureng; TERM t; char sBuf[80]; ARITY ar; ... lsMakeTerm(cureng, &t, "parent(elaine,mary)"); ... lsGetFA(cureng, t, sBuf, ar); printf("Term was %s/%i", sBuf, ar); ... /* code fragment prints: Term was parent/2 */
Description:
void GetHead(TERM term, cTYPE ctype, VOIDptr valp);
RC lsGetHead(ENGid cureng, TERM term, cTYPE ctype, VOIDptr valp)
Remarks:
The term representing the head of the list is stored in valp. See the Data Types section for legal values of cTYPE.
Return Value:
OK if everything worked, NOTOK if it failed. Note that it will fail if term does not represent a list or if term represents the empty list.
Description:
void GetParm(int iparm, cTYPE ctype, VOIDptr valp);
RC lsGetParm(ENGid cureng, int iparm, cTYPE ctype, VOIDptr valp);
Remarks:
When implementing extended predicates, lsGetParm() gets the C/C++ value of the iparmth parameter, where 1 is the first parameter. See the Data Types section for legal values of cTYPE.
See Writing Extended Predicates
Return Value:
OK if successful.
Example:
/* get address of array */ lsGetParm(CurEng, 1, cADDR, &iArray); /* get index of element */ lsGetParm(CurEng, 2, cINT, &I);
Description:
pTYPE GetParmType(int iparm);
pTYPE lsGetParmType(ENGid cureng, int iparm);
Remarks:
When implementing extended predicates lsGetParmType() gets the parameter type of the iparmth parameter.
See Writing Extended Predicates
Return Value:
pTYPE, see the Data Types section for legal values of pTYPE.
Examples:
pt = lsGetParmType(eid, 3); /* figure out type of third parameter */ if (pt == pINT) /* third parameter was instantiated */ { lsGetParm(eid, 3, cINT, &iElem); /* get its value */ iArray[i] = iElem; /* put it in the array */ } else if (pt == pVAR) /* third parameter was a variable */ { lsMakeInt(eid, &t, iArray[i]); /* fill its value from the array */ lsUnifyParm(eid, 3, cTERM, &t); } else return FALSE; /* third parameter wasn't right */
Description:
int GetStream(STREAM stream);
int lsGetStream(ENGid cureng, STREAM stream);
Remarks:
Gets the current integer handle of the stream specified by stream. See the section on Data Types for the legal values of STREAM.
Return Value:
The integer handle of the stream.
Description:
TERM GetTail(TERM term);
TERM lsGetTail(ENGid cureng, TERM term)
Remarks:
The term representing the tail of the list is returned.
Return Value:
The term representing the tail. Returns 0 if term does not represent a list or if term represents the empty list.
Description:
Remarks:
Copies the value of the term into the variable of type ctype pointed to by valp. See the Data Types section for legal values of cTYPE.
See Handling Varying Prolog Types
Return Value:
OK if it worked.
Description:
pTYPE GetTermType(TERM term);
pTYPE lsGetTermType(ENGid cureng, TERM term);
Remarks:
Get the type of the term.
Return Value:
Returns the Prolog type of the term. See the Data Types section for legal values of pTYPE.
See Handling Varying Prolog Types
Example:
lsGetParm(CurEng, 1, cTERM, &t); ptype = lsGetTermType(CurEng, t); if (ptype == pLIST) ...
Description:
void GetVersion(STRptr str);
RC lsGetVersion(ENGid cureng, STRptr str);
Remarks:
Copies the current version information into the string s.
See Miscellaneous API Functions
Return Value:
OK
Description:
void Init(STRptr ininame);
RC lsInit(ENGid *cureng, STRptr ininame);
Remarks:
Initializes the Prolog environment, using <filename>.cfg if present. If it's not present, then it uses amzi.cfg and system defaults. It can be called with an empty string, "", if you don't care to look for an application specific .cfg file. Must be called once, and before lsLoad() is called.
Return Value:
OK if everything worked.
Example:
rc = lsInit(cureng, "ducks"); if (rc != OK) ... rc = lsLoad(cureng, "ducks.xpl"); if (rc != OK) ...
Description:
void Init2(STRptr iniparams);
RC lsInit2(ENGid *cureng, STRptr iniparams);
Remarks:
Initializes the Prolog environment, using the .cfg parameters specified in the iniparams string. The string is of the format "parm1=val1, parm2=val2..". The .cfg parameters can be specified using their full name or with their abbreviation. See the section on INI parameters for a list.
Either lsInit() or lsInit2 must be called once, and before lsLoad() is called.
Return Value:
OK if everything worked.
Example:
// This try/catch is designed to catch Logic Server exceptions // and deal with them in the member function error. Note it // catches a reference to the exception object that is thrown // by the Logic Server. try { // Use Init2 rather than Init in order to set the // .cfg parameters from an argument instead of a // .cfg file. In this case, the heap, local, control // and trail are set to small numbers because we have // a small program. Init2("h=100, l=100, c=100, t=100"); // Tell the engine prompt/2 is implemented by // calling the global dispatch function, p_prompt, // with the argument 'this', used to get control // back in this instance of petID. AddPred("prompt", 2, &::p_prompt, this); Load("pets"); } catch(CLSException &e) { error(e); }
Description
void InitLSX(VOIDptr p);
RC lsInitLSX(ENGid cureng, VOIDptr p);
Remarks:
Causes the Logic Server to look for the 'loadlsx' .cfg file parameter, and load any .lsx files listed there.
See Extended Predicate Libraries (LSXs) and Writing Extended Predicates
Return Value:
OK if everything worked
Description:
Remarks:
Initializes the predicate table pointed to by predtabp. An application can initialize any number of predicate tables. This should be called after the call to lsInit() and before calling any Prolog functions.
See Extended Predicate Libraries (LSXs) and Writing Extended Predicates
Return Value:
OK if everything worked.
Example:
... /* function prototypes */ TF pMakeArray(ENGid); TF pArrayElem(ENGid); /* extended predicate table definitions */ PRED_INIT arrayPreds[] = { {"make_array", 2, pMakeArray}, {"array_elem", 3, pArrayElem}, {NULL, 0, NULL} }; /* extended predicates definitions */ ... void main() { ENGid cureng; lsInit(&cureng, "xarray"); lsInitPreds(cureng, arrayPreds); lsLoad(cureng, "xarray"); lsMain(cureng); lsClose(cureng); }
Description:
void Load(STRptr xplname);
RC lsLoad(ENGid cureng, STRptr xplname);
Remarks:
Loads the compiled and linked Prolog program, xplname. You must call lsLoad() at least once after calling lsInit(). If you want to load multiple compiled Prolog files, the rest need to be loaded as .plm files using lsExecStr() to call the load predicate with the name of the .plm file to load.
Return Value:
OK if it worked.
Example:
try { // Initialize the Logic Server engine Init(""); // Load the compiled Prolog program, hello.xpl Load("hello"); return TRUE; } catch(CLSException &E) { error(E); return FALSE; }
Description:
TF Main();
TF lsMain(ENGid cureng);
Remarks:
Calls main/0 of the loaded Prolog .xpl file.
Return Value:
Prolog TRUE/FALSE depending on success or failure.
Example:
tf = lsMain(CurEng); if (tf == FALSE) ...
Description:
void MakeAddr(TERMptr termp, VOIDptr valp);
RC lsMakeAddr(ENGid cureng, TERMptr termp, VOIDptr valp);
Remarks:
Creates a term of type pADDR from the pointer valp.
Return Value:
OK if it worked.
Description:
void MakeAtom(TERMptr termp, STRptr str);
RC lsMakeAtom(ENGid cureng, TERMptr termp, STRptr str);
Remarks:
Creates a term of type pATOM from the string str.
Return Value:
OK if it worked.
Description:
void MakeFA(TERMptr termp, STRptr functor, ARITY arity);
RC lsMakeFA(ENGid cureng, TERMptr termp, STRptr functor, ARITY arity);
Remarks:
Creates a term with the specified functor and arity. The arguments are all unbound variables which may be left as is or set to specific values using lsUnifyArg().
Return Value:
OK if it worked.
Example:
/* create structure bar(one,two) */ lsMakeFA(CurEng, &tInner, "bar", 2); lsUnifyArg(CurEng, &tInner, 1, cATOM, "one"); lsMakeAtom(CurEng, &tArg, "two"); /* another way */ lsUnifyArg(CurEng, &tInner, 2, cTERM, &tArg);
Description:
void MakeFloat(TERMptr termp, double f);
RC lsMakeFloat(ENGid cureng, TERMptr termp, double f);
Remarks:
Creates a term of type pFLOAT from the double float f.
Return Value:
OK if it worked.
Description:
void MakeInt(TERMptr termp, intC i);
RC lsMakeInt(ENGid cureng, TERMptr termp, intC i);
Remarks:
Creates a term of type pINT from the integer i.
Return Value:
OK if it worked.
Description:
void MakeList(TERMptr termp);
RC lsMakeList(ENGid cureng, TERMptr termp);
Remarks:
Creates an empty list pointed to by tp.
Return Value:
OK if it worked.
Description:
void MakeStr(TERMptr termp, STRptr str);
RC lsMakeStr(ENGid cureng, TERMptr termp, STRptr str);
Remarks:
Creates a term of type pSTR from the string str.
Return Value:
OK if it worked.
Description:
void PopList(TERMptr listp, cTYPE ctype, VOIDptr valp);
RC lsPopList(ENGid cureng, TERMptr listp, cTYPE ctype, VOIDptr valp);
Remarks:
Pops the term of type ctype from the head of the list and save it in valp. See the Data Types section for possible values of cTYPE.
Return Value:
OK if everything worked, NOTOK if it failed. Failure will occur if tp does not point to a list.
Description:
void PushList(TERMptr listp, TERM term);
RC lsPushList(ENGid cureng, TERMptr listp, TERM term)
Remarks:
The term is pushed on the head of the list and listp points to this new head of list.
Return Value:
OK if everything worked, NOTOK if it failed. Failure will occur if tp does not point to a list.
Description:
TF Redo();
TF lsRedo(ENGid cureng);
Remarks:
Causes Prolog to backtrack and retry the last lsCall(), lsvCallStr(), or lsRedo(). The term used in the initiating lsCall() or lsvCallStr() is unified with a new value if the redo is successful. lsRedo can be used in a while loop to get all the solutions to a Prolog query.
Return Value:
TRUE/FALSE. A loop that has the TF return code as its condition will loop until there are no more solutions.
See String Passing Interface and Scope of Logic Server Terms
Example:
printf("Elaine's children:\n"); tf = lsCallStr(cureng, &t,"parent(elaine,X)"); while (tf) { lsvScanTerm(cureng, t,"parent(elaine,%s)",buffer); printf(" %s\n", buffer); lsRedo(cureng); }
Description:
void Reset();
RC lsReset(ENGid cureng);
Remarks:
Resets the Prolog stacks and runtime environment. Leaves the dynamic database unchanged, so all load programs and assert terms are still present.
See Error Handling
Return Value:
OK if successful.
Description:
TF Retract(TERM term);
TF lsRetract(ENGid cureng, TERM term);
Remarks:
Retracts the first term in the database that unifies with the specified term; term has the unified value, so lsRetract() can be used to retrieve and process terms as they're being retracted.
See Asserting and Retracting to and from the Prolog Database
Return Value:
TRUE/FALSE
Example:
... TERM t; lsvMakeTerm(cureng, &t, "foo(one)"); lsAsserta(cureng, t); lsvMakeTerm(cureng, &t, "foo(X)"); lsRetract(cureng, t); lsTermToStr(cureng, &t, buf, 40); printf("Removed %s", buf); ... /* This fragment prints: Removed foo(one) */
Description:
TF RetractStr(STRptr str);
TF lsRetractStr(ENGid cureng, STRptr str);
Remarks:
Retracts the first term in the database that unifies with the term represented by the string str.
See Asserting and Retracting to and from the Prolog Database
Return Value:
TRUE/FALSE
Example:
lsAssertaStr(cureng, "foo(one)"); lsRetractStr(cureng, "foo(X)");
Description:
void SetCommandArgs(int argc, char** argv);
RC lsSetCommandArgs(ENGid cureng, int argc, char** argv);
Remarks:
Passes the values of argc and argv to the Prolog engine so it can process command line arguments if desired. It is necessary to do this if the Prolog code uses the predicate 'command_line/1'.
See Miscellaneous API Functions
Return Value:
OK
Example:
void main(int argc, char** argv) { ... lsSetCommandArgs(cureng, argc, argv), ... }
Description:
void SetInput(int (* mygetc)(VOIDptr vp), void(*myungetc)(VOIDptr vp,
int c));
RC lsSetInput(ENGid cureng, int (* mygetc)(VOIDptr vp), void(*myungetc)(VOIDptr
vp, int c));
Remarks:
When any input stream is set to 3, Amzi! Prolog uses these functions for reading user input from that stream.
Return Value:
OK if it worked.
Description:
void SetIOArg(VOIDptr vp);
RC lsSetIOArg(ENGid cureng, VOIDptr vp);
Remarks:
When any input stream is set to 3, the vp argument is included in the calls to the getc, ungetc, putc and puts functions defined by lsSetInput() and lsSetOutput().
Return Value:
OK if it worked.
Description:
void SetOutput(void (*myputc)(VOIDptr vp, int c), void (*myputs)(VOIDptr
vp, STRptr s));
RC lsSetOutput(ENGid cureng, void (*myputc)(VOIDptr vp, int c), void (*myputs)(VOIDptr
vp, STRptr s));
Remarks:
When any output stream is set to 3, Amzi! Prolog uses these functions for writing to the stream.
Return Value:
OK if it worked.
Description:
SetStream(STREAM stream, int handle);
RC lsSetStream(ENGid cureng, STREAM stream, int handle);
Remarks:
Sets the stream to the integer handle. Typically this will be used to set the stream to 3, reserved for user-defined function I/O. It might also be used to reset the stream to its old value, obtained from a prior call to lsGetStream(). See the section on Data Types for the legal values of STREAM.
Return Value:
OK if it worked.
Description:
int StrArgLen(TERM term, int iarg);
int lsStrArgLen(ENGid cureng, TERM term, int iarg);
Remarks:
Used to determine the length of string to be returned from a lsGetArg() where the argument is either a string or an atom.
See Mapping Prolog Arguments to Host Variables
Return Value:
The length of the string/atom at the iargth parameter, or NOTOK (-1) if term is not a string.
Description:
int StrParmLen(int iparm);
int lsStrParmLen(ENGid cureng, int iparm);
Remarks:
Used to determine the length of string to be returned from a lsGetParm() where the parameter is either a string or an atom.
See Writing Extended Predicates
Return Value:
The length of the string/atom at the iparmth parameter, or NOTOK (-1) if term is not a string.
Description:
int StrTermLen(TERM term);
int lsStrTermLen(ENGid cureng, TERM term);
Remarks:
Used to determine the length of string to be returned from a lsGetTerm() or lsGetHead() where the parameter is either a string or an atom.
Return Value:
The length of the string/atom at the iparmth parameter, or NOTOK (-1) if term is not a string.
Description:
void StrToTerm(TERMptr termp, STRptr str);
RC lsStrToTerm(ENGid cureng, TERMptr termp, STRptr str);
Remarks:
Reads the string and creates a term from it.
See Calling Terms
Return Value:
OK if it worked.
Example:
sprintf(buf, "%s(%s, Y)", sRelation, sIndividual); lsStrToTerm(CurEng, &t, buf); tf = lsCall(CurEng, &t);
Description:
void TermToStr(TERM term, STRptr str, int len);
RC lsTermToStr(ENGid cureng, TERM term, STRptr str, int len);
Remarks:
Writes the term to the string which is len bytes long.
Return Value:
OK if it worked.
Example:
lsGetParm(CurEng, 1, cTERM, &t); ptype = lsGetTermType(CurEng, t); if (ptype == pLIST) { while (OK == lsPopList(CurEng, &t, cTERM, &tm)) { lsTermToStr(CurEng, tm, buf, 80); printf("%s", buf); } } else { lsTermToStr(CurEng, t, buf, 80); printf("%s", buf); }
Description:
void TermToStrQ(TERM term, STRptr, str, int len);
RC lsTermToStrQ(ENGid cureng, TERM term, STRptr str, int len);
Remarks:
This function is the same as lsTermToStr(), except the string is created with quoted atoms where necessary. This makes it possible to feed the same string back to Prolog.
Return Value:
OK if it worked.
Description:
TF Unify(TERM term1, TERM term2);
TF lsUnify(ENGid cureng, TERM term1, TERM term2);
Remarks:
Unifies the two terms. lsUnify() does a full Prolog unification between the two terms. Unlike other functions which return TF, lsUnify() does not set and reset Prolog break and error handling.
Return Value:
TRUE/FALSE depending on whether the unification succeeded or failed.
Description:
TF UnifyArg(TERMptr termp, int iarg, cTYPE ctype, VOIDptr valp);
TF lsUnifyArg(ENGid cureng, TERMptr termp, int iarg, cTYPE ctype, VOIDptr
valp);
Remarks:
Used to build complex terms, lsUnifyArg() lets you individually set the arguments of term. Used in conjunction with lsMakeFA(), as well as Prolog terms picked up from calls to Prolog.
Return Value:
TRUE/FALSE depending on whether the unification succeeded or failed.
Example:
/* create structure bar(one,two) */ lsMakeFA(CurEng, &tInner, "bar", 2); lsUnifyArg(CurEng, &tInner, 1, cATOM, "one"); lsMakeAtom(CurEng, &tArg, "two"); /* another way */ lsUnifyArg(CurEng, &tInner, 2, cTERM, &tArg);
Description:
TF UnifyPartm(int iparm, cTYPE ctype, VOIDptr valp);
TF lsUnifyParm(ENGid cureng, int iparm, cTYPE ctype, VOIDptr valp);
Remarks:
Unify the iparmth parameter of an extended predicate with the 'variable. Note that there are two types for representing strings, cATOM and cSTR. While they are both strings, they unify as either a Prolog atom or a Prolog string depending on which is used.
See Writing Extended Predicates
Return Value:
TRUE/FALSE depending on whether the unification succeeded or failed.
Example:
int i; lsUnifyParm(cureng, 1, cATOM, "atomparam"); lsUnifyParm(cureng, 2, cINT, &i);
Copyright ©1987-2000 Amzi! inc. All Rights Reserved.