Questions tagged [iso-prolog]

ISO/IEC has standardized Prolog. The standard is maintained by ISO/IEC JTC1/SC22/WG17.

ISO/IEC has standardized Prolog. The standard is maintained by ISO/IEC JTC1/SC22/WG17.

The currently valid Prolog standard documents can be obtained from national member bodies like ANSI or directly from ISO. Overview of defined features.

Stack Overflow contributions about the standard documents:

143 questions
2
votes
1 answer

Prolog: declaring an operator

I have defined ! (factorial) function and registered it as arithmetic function and an operator, so that I can execute: A is 6!. Now I'd like to define !! (factorial of odd numbers), but the same way - writing clauses, registering arithmetic_function…
Clueless
  • 605
  • 3
  • 10
  • 19
2
votes
3 answers

Sometimes I don't know what the "/" means in Prolog

I see slashes used like this in code: solution([X/Y|Others]) :- noattack(X/Y, Others). But then sometimes I see "/1" "/2" etc. in Prolog. What do these statements (characters) mean?
XIA Yang
  • 445
  • 1
  • 5
  • 11
2
votes
2 answers

Prolog infix operator definition

I am recently learning about Prolog and I find the three types used for defining infix operators confusing. What are the differences between xfx, xfy and yfx when specifying the type of an operator? I have googled about the problem and haven't found…
JasonLi
  • 182
  • 2
  • 8
2
votes
3 answers

Best way to define predicate in Prolog

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…
Evgenii.Balai
  • 939
  • 13
  • 30
2
votes
1 answer

Prolog Functor - Computing x^y

I am new to prolog and trying out to learn how to program. I want to know how to compute x^y in Prolog both being integers. I know for a fact that it goes something like this: % exp(y,x,z) <- z is x**y
Amjad
  • 1,627
  • 5
  • 21
  • 41
2
votes
2 answers

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 which is one of the following atoms: '=' iff X and Y are…
repeat
  • 18,496
  • 4
  • 54
  • 166
2
votes
3 answers

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: tag_negative_len(Str, NegLen-Str) :- atom_length(Str,…
Flux
  • 9,805
  • 5
  • 46
  • 92
2
votes
2 answers

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: :- initialization(main). :-…
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
2
votes
1 answer

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 set of tuples from this…
Koinos
  • 151
  • 3
  • 14
2
votes
1 answer

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 of once in SICStus? Thank you.
Toma Radu-Petrescu
  • 2,152
  • 2
  • 23
  • 57
2
votes
0 answers

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 term T: a) If N is zero then T is the atom P. b) If N…
2
votes
1 answer

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 correct way to do it with gprolog ? Maybe with format ?
damio
  • 6,041
  • 3
  • 39
  • 58
2
votes
2 answers

`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: Errors type_error(integer, Index) if Index is…
pasaba por aqui
  • 3,446
  • 16
  • 40
2
votes
3 answers

Why must facts be grouped together in Prolog?

Say I am listing facts: letter(a). letter(b). letter(c). ... letter(z). vowel(a). consonant(b). consonant(c). consonant(d). vowel(e). consonant(f). ... consonant(z). If I declare the rules in 'alphabetical' order, I get the following warnings in…
chris Frisina
  • 19,086
  • 22
  • 87
  • 167
2
votes
1 answer

Prolog, getting right answer in terminal, but wrong answer when running a program

Typing "prolog" in terminal gets: GNU Prolog 1.3.0 By Daniel Diaz Copyright (C) 1999-2007 Daniel Diaz | ?- Typing: | ?- member(2, [1,2,3]). Gets: true ? Then pressing enter gets: yes Typing: | ?- member(4, [1,2,3]). gets: no When i…
user3573388
  • 191
  • 1
  • 6