Is it possible to write the results of time/1 to file or have them returned as a variable to automate the runtime comparison?
Or is there another predicate to do this?
The solution to this is to use the statistics/2 predicate.
http://www.swi-prolog.org/pldoc/man?predicate=statistics%2F2
Related
In SWI-Prolog, I want to load differente files based on input in a predicate, and use rules defines in this file in this predicate, but it didn't work. I wonder if there's a way to load file that rules in this file could take effect immediately.
The thing I want to achieve is like:
rule.pl:
classify(X,Y):-X('1'),Y('2').
main.pl:
RuleFile('rule')
initClassify(X,Y):-load_files(RuleFile),classify(X,Y).
When I call initClassify/2, it complained that classify/2 undefined procedure.
I'm having a problem with a program that I'm writing. The program takes an input and generates a prolog program based on it. It generates something like this:
test(A):-condA(A),condB(A).
condA(val).
condB(val).
My problem is that sometimes, there is no condB(val), or condB anywhere in the program, except in the above definition of test. In that case, I got existence_error for condB, when I try to ask test(val), for example. Is there a way to add something to the prolog program that would define condB as false for all values of it's argument?
I'm sorry if this is stupid question, as I'm new to prolog.
You can tell the prolog processor that condB/1 is dynamic:
:-dynamic condB/1.
Answer to your question is simple.
condB(_):-fail.
the symbol '_' is free variable.
I am looking for something like the predicate halt/0 or abort/0.
I do not want to use abort/0 because of the % Execution aborted message at the console and I do not want to use halt/0 because it terminates the Sicstus Prolog program.
Is there any other predicates that can be used to stop the program execution?
I already checked the documentation for this topic and I do not seem to find the result I want to see.
Maybe throw an exception with throw/1?
– mat
I managed to achieve what I wanted using that predicate.
Thank you mat.
I wrote a Prolog predicate that generates a Latex file, and I am looking for a way to be able to compile such a file automatically, within Prolog, to return instead the associated PDF file. I have found the shell predicate (http://www.swi-prolog.org/pldoc/man?predicate=shell/2) but I can't figure out how to properly make it work.
In case it is of any relevance, I am using SWI-Prolog 7.1.33 in a Mac.
Thanks in advance!
The traditional predicate to execute shell commands is system/1 that works in Unix-like and MS-Windows systems. For instance
?- system('echo a').
writes a a in a Unix-like system.
In prolog, if I assert some fact, for example:
assert(boy(john4)).
assert(boy(john3)).
assert(boy(john2)).
assert(boy(john1)).
How can I save this fact in file?
If you are using SWI-Prolog then one alternative is the persistency.pl library. You need to declare persisted predicates and their argument types. Then you can use assert_mypred and retract_mypred. More info: http://www.swi-prolog.org/pldoc/doc/swi/library/persistency.pl