[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Programmatically consulting a prolog file

From: josh b
Subject: Programmatically consulting a prolog file
Date: Fri, 9 Apr 2010 23:31:13 +1000


I'm trying to access Prolog from within my C++ code (Using Visual C++ 2008 Express). I have it mostly working now. I am able to successfully write a C++ program, build it (In MSVC, not using glpc) and call predicates like write/1 and absolute_file_name/2. However, I have my own Prolog files I wish to consult from within the C ++code.

I figured I'd just call the consult/1 predicate with the name of the .pl file. But the Pl_Query_Call returns a PL_EXCEPTION. I even tried using absolute_file_name/2 to construct the filename for consult/1 (To be 100% sure I was using the right name). Sure enough, absolute_file_name/2 can find the file, but consult/1 still fails.

Here is an excerpt from my code:
int func;
PlTerm arg[10];
int res;

Pl_Start_Prolog(argc, argv);

//This correctly unifies arg[1] with the absolute file name of, e:/
func = Pl_Find_Atom("absolute_file_name");
arg[0] = Pl_Mk_String("");
arg[1] = Pl_Mk_Variable();
res = Pl_Query_Call(func, 2, arg);

//This should load in all predicates in the file
func = Pl_Find_Atom("consult");
arg[0] = arg[1];
res = Pl_Query_Call(func, 1, arg);

Yet, it just returns and exception. Even if I try to proceed and try to Pl_Find_Atom on any of the predicates from the file, they just fail.

I also tried adding the argument "--init-goal consult('e:/')" to argv in Pl_Start_Prolog. No dice there either.

I'd really like to do my work from with the MSVC IDE, so any help with programmatically consulting the prolog file would be much appreciated.


Meet local singles online. Browse profiles for FREE!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]