iso-prolog

DCG Expansion: Is Steadfastness ignored?

自古美人都是妖i 提交于 2019-12-17 19:59:54
问题 Assume I have the following DCG rule: factor(X) --> "(", expr(X), ")". Normally this would be translated to: factor(X, A, B) :- [40|C] = A, expr(X, C, D), [41|B] = D. Would a Prolog system be allowed to translate it as follows, i.e. to merge the unifications into the head and the goal? factor(X, [40|A], B) :- expr(X, A, [41|B]). If DCG expansion would not be steadfast, it wouldn't be allowed to put [41|B] in the third argument of the expr call. But I guess steadfastness is in place, so

A searchable Prolog language description online [closed]

久未见 提交于 2019-12-17 19:17:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Is there a description of Prolog language (syntax and semantics) available online? There are a lot of reference manuals for implementations. But neither of those is a language description. For example the SWI Prolog manual states This manual does not describe the full syntax and semantics of Prolog. And refers

Safer type tests in Prolog

北城以北 提交于 2019-12-17 06:15:35
问题 ISO-Prolog (ISO/IEC 13211-1:1995 including Cor.1:2007, Cor.2:2012) offers the following built-in predicates for testing the type of a term: 8.3 Type testing 1 var/1. 2 atom/1. 3 integer/1. 4 float/1. 5 atomic/1. 6 compound/1. 7 nonvar/1. 8 number/1. 9 callable/1. 10 ground/1. 11 acyclic_term/1. Within this group there are those whose purpose is solely to test for a certain instantiation, that is 8.3.1 var/1 , 8.3.7 nonvar/1 , 8.3.10 ground/1 , and those that assume that a term is sufficiently

What is the use of prolog pairs in or outside lists

柔情痞子 提交于 2019-12-14 01:17:07
问题 I encountered several times Key-Value pairs in the SWI-PL doc but couldn't get a good info about them. Is this something standard in prolog or is it just a swi pl only extension ? Mainly found here : http://www.swi-prolog.org/pldoc/doc_for?object=keysort/2 and here : http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%27A.3%27,swi%28%27/doc/Manual/assoc.html%27%29%29 The form of the pairs is a-5 for example, or in a list [a-5, b-7]. And if it is standard, is there any added value to

strange arithmetic with swi-prolog [duplicate]

不羁的心 提交于 2019-12-13 08:05:45
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 5 years ago . I find the result very strange. Why not 0.3? Can somebody tell me why this result? Is it possible to fix this. ?- X is 5.3-5. X = 0.2999999999999998. ?- My second question is how would I transform from 'hour' notation '13.45' ---->'15.30' into numbers of hours ? For example the period above calculated 15.30-13.45 would be 1.85. But I need to operate on parts of the hour and not the

Best way to define predicate in Prolog

◇◆丶佛笑我妖孽 提交于 2019-12-12 17:40:27
问题 I have a problem with defining procedures in Prolog. I have two source files and want to consult Prolog engine with both of them. This can be done by invoking Prolog as swipl -g “['1.pl','2.pl']. Both of the files are generated by another program written in another programming language and i can't predict the exact content of the files beforehand. The problem is that in one of the files there is always a rule predicate1(X):-predicate2(X). But,sometimes the rule predicate2(something):-body

Getting the minimum value of a list

元气小坏坏 提交于 2019-12-11 11:18:12
问题 I am trying to find the minimum value of a list (as a learning experience, so without min ). My approach is the following: minimo([X], X). minimo([X,Y|Tail], N):- (X > Y, minimo([Y,Tail], Y)); (X <= Y, minimo([X,Tail], X)). This gives me the following error: Syntax error: Operator expected So my questions are: What is causing the syntax error? I will try it myself once that is fixed if it actually gives the correct value back, but would this actually be a correct approach? Thanks in advance.

appendAll - Append a list to all lists within a list

孤街浪徒 提交于 2019-12-11 04:38:59
问题 I'm trying to find a way to append a list to all lists within a list. Something like: appendAll([a,b],[[q,w],[z,x]],X). X = [[a,b,q,w],[a,b,z,x]]. I'm still new to prolog and nested lists are throwing me off quite a bit. I've been staring at this for a few hours now: appendAll([], _, []). appendAll(_, [], []). appendAll([H1|T1], [H2|T2], X) :- append(H1,H2,R), appendAll(T1,[H2|T2],X). % recurse down to [], and append back up Any help is much appreciated Thanks! 回答1: What is difficult in

What do Prolog implementations mean by “float”?

梦想的初衷 提交于 2019-12-10 13:46:25
问题 I was looking through the SICStus manual's syntax description and there is a definition of "float". However, there is no indication of what the implementation of "float" actually is. IEEE single or double precision? Maybe even a BigDecimal ? In SWI Prolog (or at least SWISH), the "float" seems to be IEEE double precision, as can be determined via: planck_float(P) :- planck_float_descent(1.0,P). planck_float_descent(X,P) :- Xhalf is X / 2.0, Xtest is 1.0 + Xhalf, Xtest =\= 1.0, !, write(Xhalf)

Equivalence of disjunction operator and definition with several rules

让人想犯罪 __ 提交于 2019-12-10 13:39:45
问题 I just stumbled over the definition of ;/2 in the SWI Prolog Manual which states: The `or' predicate is defined as: Goal1 ; _Goal2 :- Goal1. _Goal1 ; Goal2 :- Goal2. Wouldn't that mean that ;/2 behaves exactly as if we wrote our own helper predicate consisting of two rules? I had memorized that ;/2 was an impure construct (but it's possible I'm mixing this up with if-then-else) but this definition is pure (although meta-logical). The semantics of ;/2 are defined in the ISO standard in