iso-prolog

'if' in prolog?

雨燕双飞 提交于 2019-11-27 04:27:21
问题 Is there a way to do an if in prolog, e.g. if a variable is 0, then to do some actions (write text to the terminal). An else isn't even needed, but I can't find any documentation of if. 回答1: A standard prolog predicate will do this. isfive(5). will evaluate to true if you call it with 5 and fail(return false) if you run it with anything else. For not equal you use \= isNotEqual(A,B):- A\=B. Technically it is does not unify, but it is similar to not equal. Learn Prolog Now is a good website

Meaning of instantiation mode indicators in arguments of Prolog predicates

被刻印的时光 ゝ 提交于 2019-11-27 02:06:14
Looking at Prolog documentation, predicate signatures are sometimes written as following: foo(:Bar, +Baz, -Qux, ?Mop) What are : , + , - and ? for and how do I interpret them? Also, are these the only ones that exist or are there more of them? Paulo Moura Those prefix operators, in this context, represent instantiation modes, i.e. they tell you which arguments should be variables or instantiated when calling the predicate. They also tell you if an argument will be (possibly further) instantiated by the call. They can also be used to tell you that an argument is going to be meta-interpreted in

Prolog systems in Javascript [closed]

血红的双手。 提交于 2019-11-27 01:22:21
问题 Javascript seems to become popular as an implementation language for other programming languages. The article Lightweight compilation of (C)LP to JavaScript. ICLP 2012 drew my attention on this. There are a lot of proof-of-concept prototypes for Prolog systems written in Javascript around on the Web. What are current, actively maintained, preferably ISO conforming Prolog systems written in Javascript? 回答1: The only Prolog in JavaScript I know is YieldProlog, but I haven't tried it extensively

How to define (and name) the corresponding safe term comparison predicates in ISO Prolog?

Deadly 提交于 2019-11-26 16:48:46
问题 Standard term order (ISO/IEC 13211-1 7.2 Term order) is defined over all terms — including variables. While there are good uses for this — think of the implementation of setof/3 , this makes many otherwise clean and logical uses of the built-ins in 8.4 Term comparison a declarative nightmare with imps (short form for imperative constructs) all around. 8.4 Term comparison features: 8.4 Term comparison 8.4.1 (@=<)/2, (==)/2, (\==)/2, (@<)/2, (@>)/2, (@>=)/2. 8.4.2 compare/3. 8.4.3 sort/2. 8.4.4

Complexity of ISO Prolog predicates

狂风中的少年 提交于 2019-11-26 16:45:32
Are there any guarantees for upper bounds on the time complexity of the standard Prolog predicates? For example: is it certain that sort(+List, ?SortedList) runs in O(nlog(n)) time (n being the length of List ) in any standard compliant Prolog system? false tl;dr: No and no. Let's start with sort/2 which ideally would need n ld( n ) comparisons. Fine, but how long does one comparison take? Let's try this out: tails(Es0, [Es0|Ess]) :- Es0 = [_|Es], tails(Es, Ess). tails([],[[]]). call_time(G,T) :- statistics(runtime,[T0|_]), G, statistics(runtime,[T1|_]), T is T1 - T0. | ?- between(12,15,I), N

Meaning of instantiation mode indicators in arguments of Prolog predicates

▼魔方 西西 提交于 2019-11-26 09:54:38
问题 Looking at Prolog documentation, predicate signatures are sometimes written as following: foo(:Bar, +Baz, -Qux, ?Mop) What are : , + , - and ? for and how do I interpret them? Also, are these the only ones that exist or are there more of them? 回答1: Those prefix operators, in this context, represent instantiation modes, i.e. they tell you which arguments should be variables or instantiated when calling the predicate. They also tell you if an argument will be (possibly further) instantiated by

What is the difference between &#39; and " in Prolog?

≡放荡痞女 提交于 2019-11-25 22:07:31
问题 I am new to Prolog and noticed that \' and \" give different behavior, but am curious as to why. Specifically, when loading a file, ?- [\'test1.pl\']. works, while ?- [\"test1.pl\"]. doesn\'t. 回答1: Single quoted items are always atoms. The meaning of double quotes depends on the Prolog flag double_quotes : atom — with this value "a" = a . Nowadays, this is rarely used. But you will find Prolog books where ["abc.pl"] is written. codes — a list of character codes. This is frequently the default