Questions tagged [iso-prolog]
ISO/IEC has standardized Prolog. The standard is maintained by ISO/IEC JTC1/SC22/WG17.
135
questions
4
votes
1answer
50 views
Is !/0 supposed to cut through (\+)/1 or not?
On the one hand:
$ sicstus
SICStus 4.6.0 (x86_64-linux-glibc2.17): Mon Apr 6 09:23:37 PDT 2020
[...]
| ?- \+ (!,false) ; X = 1.
yes
... on the other hand ...
$ gprolog
GNU Prolog 1.4.5 (64 bits)
[...
4
votes
3answers
125 views
Proper handling of denormal floats in ISO-Prolog
Denormal floats are something special:
What does the ISO-Prolog standard say on how these should be handled?
It is clear to me that raising a evaluation_error(underflow) exception whenever these ...
2
votes
1answer
56 views
current_predicate in SICStus Prolog
SICStus Prolog offers both current_predicate/1 and current_predicate/2.
The manual page states:
current_predicate(?PredSpec)
Unifies PredSpec with a predicate specifications of the form Name/...
0
votes
1answer
70 views
Get index of a Term's argument in Prolog
I need to get the index of a term's argument in Prolog. Predicate arg/3 seems to do the opposite of what I need:
arg(Index, Term, Value).
arg/3 fails if Index is a variable, so it's not possible to ...
1
vote
1answer
43 views
What are legitimate / proper System Errors in ISO-Prolog?
TL;DR: This question is about Prolog implementation details. Proceed at your own risk. You've been warned:)
According to ISO/IEC 13211-1995 "7.12 Errors":
7.12.2 Error classification
[...]
...
2
votes
2answers
59 views
Relational operator symbols in Prolog 3-way comparison
The Prolog standard ISO/IEC 13211-1:1995/Cor.2:2012
features compare/3:
8.4.2 compare/3 – three-way comparison
8.4.2.1 Description
compare(Order, X, Y) is true iff Order unifies with R ...
2
votes
3answers
240 views
How to sort a list of strings “a”, “bcd”, “ef”, and “ghij” in descending order of length?
Paul Graham asked:
In your favorite programming language, how do you sort a list of the strings "a", "bcd", "ef", and "ghij" in descending order of length?
One proposed solution was:
...
1
vote
0answers
52 views
Unclear phrase in the definition of retract/1
There is something about retract/1 that doesn't make sense to me.
According to ISO/IEC 13211-1:1995:
8.9.3 retract/1
8.9.3.1 Description
retract(Clause) is true iff the database ...
4
votes
3answers
127 views
The smallest `max_arity` of compound terms in ISO Prolog programs
Prolog systems aiming at iso-prolog conformity do not have to support compound terms with arbitrarily large arities. The Prolog flag max_arity reflects this.
According to ISO/IEC 13211-1:1995:
7.11.2....
3
votes
2answers
124 views
Prolog jargon: id(X,X). fact or rule?
In Prolog, this is unambiguously a fact:
foo(bar).
And this is unambiguously a rule:
foo(X) :- bar(X).
But what about a clause that has both non-singleton variables and no :- such as
identity(X,X)...
7
votes
2answers
231 views
Space-efficient writing of functional notation
Writing functional notation is often quite costly in terms of auxiliary space consumption. This is particularly critical for canonical writing of lists.
First consider the size of the output: Whereas ...
2
votes
1answer
105 views
Matching patterns without unification in Prolog
I need to match one pattern with several different terms in Prolog, but I don't want to unify any of the variables when matching them. I found one possible way to do this, but it seems inefficient:
:-...
1
vote
1answer
331 views
SWI Prolog description of call/1: “clauses may have variables as subclauses”?
The description of call/1 says:
call(:Goal)
Invoke Goal as a goal. Note that clauses may have variables as
subclauses, which is identical to call/1.
I don't understand "clauses may have ...
1
vote
1answer
66 views
create_mutable/2 in SICStus Prolog
The SICStus Prolog manual page on mutable terms states that:
[...] the effect of unifying two mutables is undefined.
Then, why does create_mutable(data,x) fail?
Shouldn't that rather raise an ...
4
votes
2answers
116 views
Disjunction G1 ; G2 vs. If-then-else Cond -> G1 ; G2
I encountered a Prolog program containing a nested if-then-else of the form
p(X,Y) :-
(cond1(X,Y) -> q(X)); true,
(cond2(X,Y) -> q(Y)); true.
that had unexpected answers. The reason ...
1
vote
0answers
47 views
Layouting Prolog terms
One of my art projects is about visual aspects of Prolog terms. My current focus is on
alignment / padding—not on syntactic variations1.
Let's assume I have something like write_tokens....
Between ...
1
vote
1answer
58 views
Space / time requirements for ISO-Prolog processor compliance
All implementations of the functional programming language scheme are required to perform tail-call-optimization whenever it is applicable.
Does iso-prolog have this one and / or similar requirements?...
6
votes
2answers
140 views
Equivalence of disjunction operator and definition with several rules
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 ...
7
votes
2answers
179 views
Is it possible to preserve variable names when writing and reading term programatically?
I'm trying to write an SWI-Prolog predicate that applies numbervars/3 to a term's anonymous variables but preserves the user-supplied names of its non-anonymous variables. I eventually plan on adding ...
2
votes
1answer
184 views
precedence of negation in SWI prolog
Here is quote from from Blackburn and Bos book "Representation and Inference for Natural Language".
:- op(900,yfx,>). % implication
:- op(850,yfx,v). % disjunction
:- op(800,yfx,&). % ...
6
votes
3answers
374 views
What is the difference between :- and ?- in Prolog?
This Prolog program prints Hello:
main :-
write('Hello'), nl.
:- main.
I changed (:-)/1 to (?-)/1:
main :-
write('Hello'), nl.
?- main.
This produces exactly the same result. This also ...
2
votes
1answer
254 views
Prolog - check the end of the stream doesn't work
I have a file memo.dat , with these terms:
memo(verdi,11).
memo(rossi,7).
memo(bianchi,9).
memo(blu,7).
memo(neri,11).
memo(carli,11).
memo(rapini,8).
I wrote a prolog program in order to obtain a ...
5
votes
3answers
1k views
Is this Prolog terminology correct? (fact, rule, procedure, predicate, …)
Getting the terminology correct is part of the success to communicating a concept and when the wrong terminology is used here at SO with the Prolog tag the respondents nicely point out the mistake.
...
1
vote
0answers
66 views
Semantic difference between one rule where conditions are seperated with ';' (or) and rules written down seperatly
Let b, c and d be facts or rules
x(A) :- b(A);c(A);d(A)
vs
x(A) :- b(A)
x(A) :- c(A)
x(A) :- d(A)
Is there a difference in semantics between the two definition of the rule x ? In my opinion I ...
8
votes
1answer
201 views
Different results in swi-prolog and yap
The sample program enumerates and counts the number of 8-queen solutions. (sorry if the code is hard to read; this is machine-generated from an S-expression. The original code is https://www.cpp.edu/~...
2
votes
3answers
173 views
Escaped Characters Outside the Basic Multilingual Plane (BMP) in Prolog
For reference, I'm using Prolog v7.4.2 on Windows 10, 64-bit
Entering the following code in the REPL:
write("\U0001D7F6"). % Mathematical Monospace Digit Zero
gives me this error in the output:
...
7
votes
2answers
480 views
Prolog DCG set_prolog_flag double_quotes source code directive location matters; documentation?
I learned the hard way that with SWI-Prolog the location for the Prolog directive set_prolog_flag matters in a source code file.
The only documentation I found of value about loading source code ...
3
votes
1answer
589 views
Why is prolog unification depth-first-search instead of breadth-first-search?
I just started learning about prolog and I was wondering why it's dfs instead of bfs and why there isn't an easy way to change it.
Does ISO prolog mandate it?
2
votes
1answer
76 views
Once in SICStus Prolog?
How can I use once in SICStus?
In SWI Prolog, the following works:
test(X, Y, abc) :- once(X == 'true' ; Y == 'true').
but in SICStus Prolog, once seems to be unrecognized. What is the equivalent ...
3
votes
1answer
174 views
How is a integer created as a character code constant?
I am building some test cases for integer/1 using SWI-Prolog.
ISO/IEC 13211-1 gives a BNF definition for integer and one of the alternatives for integer is for a character code constant.
I am able ...
6
votes
4answers
468 views
How can I simulate a soft cut in Prolog?
How can I simulate a soft cut I *-> T; E in ISO Prolog? I has side effects, so I can not call it multiple times.
Except for the last requirement, I think the following definition works:
if_(I, T, E)...
2
votes
1answer
100 views
ISO error classification for multiple definition in Prolog DSL
I'm building a DSL that uses names for procedures (essentially) that must be unique.
It's unclear what sort of error term to use to represent a second definition.
existence_error sorta kinda fits, ...
2
votes
0answers
93 views
How does the ISO Prolog standard require the preservation of variable identity when converting from a clause to a term?
I am missing something in my reading of ISO/IEC 13211-1, subclauses 7.6.3 and 7.6.4:
7.6.3 Converting the head of a clause to a term
A head H with predicate indicator P/N can be converted to a ...
5
votes
1answer
95 views
Why did Technical Corrigendum 2 to ISO/IEC 13211-1:1995 omit “bar” from the “token” rule?
Cor.2 says (only) the following about clause 6.4:
6.4 Tokens
Add as the last syntax rule:
bar (* 6.4 *)
= [ layout text sequence (* 6.4.1 *) ] ,
bar token (* 6.4.8 *) ;
Surely ...
1
vote
1answer
1k views
How can I write key-value pairs in Prolog?
Imagine I have the following predicate, which states that the ID loc1 designates a location.
isLocation('loc1', 'Location 1').
I want to provide translations for the second text (Location 1), i. e. ...
6
votes
1answer
717 views
Prolog error arguments
I'm wondering how to go about adding error checking in Prolog.
For instance I have a program that will find how long a list is:
listlen([],0).
listlen([_|T],N) :-
listlen(T,X),
N is X+1.
How ...
3
votes
1answer
91 views
Behavior of cuts in negation
The following code, as expected, outputs 123 because of backtracking:
between(1,3,X), write(X), false.
This one with the cut outputs 1, also as expected:
between(1,3,X), write(X), !, false.
But ...
17
votes
3answers
842 views
sort/2, keysort/2 vs. samsort/3, predsort/3
ISO-Prolog provides sort/2 and keysort/2 which relies on term order (7.2) often called "standard term order".
The common way to sort a list with a different order is to map each element El of that ...
3
votes
1answer
141 views
Listing predicates within a given library module
Is there a means to list all the predicates that are defined in a given library module for SICStus Prolog?
e.g. if I load the lists module:
| ?- use_module(library(lists)).
is there another ...
14
votes
2answers
342 views
Why are round brackets not needed for atoms that are high priority operators?
In older textbooks1 one frequently encounters operator declarations like the following:
?- op(1200,fx,(:-)).
^ ^
These round brackets used to be necessary. But today, they are no ...
2
votes
1answer
159 views
ANSI escape characters in gprolog
Trying to print bold and underlined text in prolog but can't write them
write('\033[1mbold\033[0m')
Makes this (expected) error:
syntax error: \ expected in \constant\ sequence
What's the ...
2
votes
1answer
489 views
Why was the ISO module standard for prolog a failure? [closed]
In the introduction here, it states that the ISO module standard for Prolog was a failure. Can anyone elaborate on this?
37
votes
5answers
686 views
Unification with STO detection
In ISO Prolog unification is defined only for those cases that are NSTO (not subject to occurs-check). The idea behind is to cover those cases of unifications that are mostly used in programs and ...
2
votes
2answers
196 views
`nth0/3` behaviour when N is unbound
If I type in SWI Prolog a "nth0" query, the result is:
?- nth0(N,X,a).
N = 0,
X = [a|_G282] ;
N = 1,
X = [_G281, a|_G285] ;
N = 2,
X = [_G281, _G284, a|_G288] ;
... etc
however, the SWI manual says:
...
3
votes
2answers
1k views
Representation of negative integers
Does ISO-Prolog have any prescriptions / recommendations
regarding the representation of negative integers and operations on them? 2's complement, maybe?
Asking as a programmer/user: Are there any ...
0
votes
0answers
75 views
WARNING: The predicate =/2 is unknown
I'm trying to transfer a file written for SICStus Prolog into TuProlog.
I get the error message:
WARNING: The predicate =/2 is unknown.
(The code works in SICStus, but not in TuProlog).
What ...
5
votes
1answer
87 views
Testing “Safe term order” predicate
In a recent question (How to define (and name) the corresponding safe term comparison predicates in ISO Prolog?) @false asked for an implementation of the term ordering predicate lt/2, a variant of ...
5
votes
3answers
448 views
Implementing user-defined arithmetic functions
How can I add a function (e.g., hammingweight) and use it in expressions occuring in the right-hand side is some (is)/2 goal?
Could something like goal_expansion or term_expansion help here?
I ...
4
votes
2answers
539 views
Unable to create Fact in Jekejeke Prolog
I'm using the Seven Languages In Seven Weeks Prolog tutorial and trying to run through some examples using the Android Jekejeke Runtime.
For example, if I add
likes(wallace, grommit).
from the ...
5
votes
2answers
1k views
How Prolog's logical update view works for assert and retract?
Can someone please explain the Prolog logical view about assert and retract in details?
For example in code below, in the first run Prolog returns true and in subsequent runs returns false. I don't ...