Did you know ... Search Documentation:
Profile for user LogicalCaptain

Tags by LogicalCaptain

backquotesatom_codes/2
coroutinesSec. 4.9
deprecatedlibrary_directory/1, reconsult/1
doc-needs-helpis_of_type/2, assertion/1, , memberchk/2, cyclic_term/1, [wiki] Wiki page at "FAQ/reconsult.txt", ?=/2, dif/2, ==/2, Sec. A.50, [wiki] XPCE: the SWI-Prolog native GUI library, [wiki] Fix incomplete installation due to missing dependencies, [wiki] SWI-Prolog future directions, [wiki] Program Development Tools, call/1, format/2, Sec. 2.12, Sec. 2.16.1, maplist/2, writef/2, Sec. 2.16.1.3, Sec. 1.1, pengine_event_loop/2, Sec. 4.13, Sec. A.30, float/1, Sec. A.21, end_tests/1, Sec. 6.1, setup_call_cleanup/3, Sec. A.38, open/3, \=/2, \==/2, meta_predicate/1, Sec. 12.3, PL_register_foreign_in_module(), PL_get_atom_chars(), number/1, keysort/2, predicate_property/2, clause/2, Sec. G
docs-needs-helpSec. 4.1
exceptionsSec. A.16, throw/1, catch/3, Sec. 4.10.3, assertion/1
naf\+/1
negation\+/1

Comments by LogicalCaptain

number_chars/2This tests whether the "serialized representation" doesn't lose digits: == ?- X ...
atom_chars/2## Testing atom_chars(_,_) == :- begin_tests(atom_chars). test(listwards_atom ,[ ...
debug/3The debug output goes to STDERR (when on a TTY, they are printed in blue) debug/ ...
Sec. 4.12Introduction and tutorials: - [DCG Primer](https://www.metalevel.at/prolog/dcg) ...
char_code/2Remember that a Prolog "character" is an atom of length 1. However, this predica ...
phrase/3## Example == :- use_module(library(dcg/basics)). :- begin_tests(dcg). % Parsing the (unicode) codepoints in "Codes" with the callable % integer(X) which actually resolves to predicate integer/3, taking % itself "Codes" and "Rest" in addition to "X".
Sec. 4.9## Reading The link to "Schrijvers et al., 2013." just goes to the bibliography ...
Sec. GSome of the above can be live linked directly to (legit) Internet-available PDFs In particular, there's one right here on this server Delimited continuations for Prolog: https://www.swi-prolog.org/download/publications/iclp2013.pdf
initialization/1Example for when you want to call =main= of your source file **immediately after the source file has been loaded** (from swipl-devel/man/select.pl): == :- initialization ( catch(main, E, ( print_message(error, E), fail )) -> halt ; halt(1) ). ==
Sec. 9.1Note the following outcomes of calling a CHR constraint from Prolog: - The call ...
Sec. 9.1"Committed Choice" very concretely means there is no backtracking over the CHR r ...
Sec. 9.1The links to "further information" should probably not be as in an academic pape ...
term_expansion/2A simple example to print out whatever is read during consultation. In this case ...
Sec. 9Working on unconfusing myself on CHR/Prolog interaction. Here is some reading of interest: [Abductive reasoning in Prolog and CHR A short introduction for the KIIS course, autumn 2005](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.602.3397)
unify_with_occurs_check/2"That is, a variable only unifies to a term if this term does not contain the va ...
dif/2## Needs text improvement "Finally, if A and B can unify, goals are delayed that prevent A and B to become equal." doesn't sense to me. The text in **library(dif)** is much clearer: "Among the most important coroutining predicates is dif/2, which expresses disequality of terms in a sound way.
Sec. 4.10.3I'm trying to keep [**this page**](https://bit.ly/31lzhFx_prolog) updated with d ...
throw/1I put together some comments on exceptions (especially on ISO standard exception ...
Sec. 2.10 ## "The Byrd Box Model" aka.
Sec. 4.13Relative to **4.13.5 Update view**, Richard A.
instantiation_error/1The ISO exception term has no information (see also throw/1) and is completely u ...
module/1This predicate should probably also be able to retrieve the name of the current ...
freeze/2## Some notes 1.
succ/2In fact, succ/2 is made to order for natural numbers. - What is the predecessor ...
setof/3See bagof/3 for some commentary.
false/0## Zero-effect clauses Note that writing clauses like == p(1,2) :- false. == has absolutely no effect on the meaning of Prolog program - you might as well leave them out (because everything that is left out is considered false - Closed World Assumption) For example: == p(2,4) :- false. p(A,B) :- between(1,4,A),B is 2*A. == Result: == ?- p(2,4). true. ?- bagof([X,Y],p(X,Y),Bag). Bag = [[1, 2], [2, 4], [3, 6], [4, 8]]. == and it is exactly the same for == p(A,B) :- between(1,4,A),B is 2*A. p(2,4) :- false. == or == p(A,B) :- between(1,4,A),B is 2*A. == ## And now for some inconsistency Using `false` and the cut means you can write Bad and Inconsistent Programs: == f(X,X) :- !, false. f(0,1). == Now you are in trouble: == ?- f(0,1).
Sec. 5.3.2And also: == a :- write(a1),nl. a() :- write(a2),nl. ?- a. a1 true ; a2 true. == == b :- c,c(). c :- write(c),nl. ?- b. c c true. == But an atom is not a compound term: == ?- pi == pi(). false. ?- pi = pi(). false. ==
## Works "out of the box"! Try it with a few test cases.
retractall/1This predicate never fails. "If Head refers to a predicate that is not defined, ...
clause/2Jan Burse writes: "According to ISO core standard clause/2 is also only allowed ...
retract/1"logical update view" would be more correctly called "transactional update view" ...
dynamic/1See also: [Database Section](https://www.swi-prolog.org/pldoc/man?section=db) wh ...
flag/3From the [Database](https://eu.swi-prolog.org/pldoc/man?section=db) page: "flag/ ...
## Documentation The only book on JNI seems still to be Rob Gordon's "Essential ...
[wiki] SWI-Prolog downloadsTL;DR for "Install development version on Linux" With bash. Building is done usi ...
must_be/2This predicate should be used exclusively to perform contract checks and asserti ...
include/3Example: We want the _Keys_ of _Key-Value_ pairs which match a certain _Value_. ...
## Example A unit test to provide examples. == :- begin_tests(choicepoints). tes ...
domain_error/2An example for a "domain error": == ?- catch(length(L,-1),C,true). C = error(dom ...
between/3## Unit test code for "between" [**Here**](https://bit.ly/3bD7yBC_prolog) is uni ...
compound_name_arguments/3[This page](https://bit.ly/3e5p4Aw_prolog) provides a short overview of the "ana ...
=../2[This page](https://bit.ly/3e5p4Aw_prolog) provides a short overview of the "ana ...
Sec. A.50## Don't forget the bracy part A question that often comes up is due to differen ...
\+/1## Interpretation Read \+ p(X) as "there is no evidence for p(X)" or "there is n ...
[wiki] SWI-Prolog datatypesThe SWI-Prolog documentation has more on SWI-Prolog datatypes test predicates he ...
Sec. 4.5## The Type Tree in ASCII == any T | +-------------------------+---------------- ...
repeat/0Alternative to the failure-driven loop as long as the compiler can do tail-call ...
once/1If there is a =once/1=, there should probably be a =twice/2= etc.
-- I put together some comments on exceptions here: [On Exceptions](https://github. ...
var/1This predicate is named in a very unfortunate fashion. The correct name should b ...
get_assoc/5Jan, why not add your comment to the documentation directly. This approach has t ...
length/2See also the description of length/2 in "A Prologue for Prolog (working draft)" ...
atomic_list_concat/2The second argument is always from the set of atoms: == ?- atomic_list_concat([a ...
foldl/4Example: Creating a list of integers 0..5: == ?- length(List,6), % create a list of 6 fresh variables foldl( [Item,XCur,XNext]>>(succ(XCur,XNext),Item=XCur), % predicate in yall notation List,0,_XFinal). List = [0, 1, 2, 3, 4, 5], _XFinal = 6. ==
list_to_assoc/2Missed opportunity: The predicate **fails** if =Assoc= is set but =Pairs= is fre ...
max_list/2Unexpectedly, it is `max_list(List,Max)` on one hand but `max_member(Max,List)` ...
append/3From the description of flatten/2 : "Ending up needing flatten/2 often indicates ...
sort/2I have gone through the available sorting predicates and assembled some unit tes ...
keysort/2There should be a link to library(pairs): https://www.swi-prolog.org/pldoc/man?s ...
Sec. A.1"aggregate" needs a "limit" option whereby you can select up to "Limit" results ...
Sec. A.3I had some fun writing =foldl/4= and =foldr/4=, including an implementation of = ...
mod/2A little exercise to compare the pairs == div,mod == and == //,rem == can be fou ...
foldl/4I had some fun explaining and writing a =foldl/4= and =foldr/4=, complete with t ...
maplist/4All three lists must be the same length otherwise the predicate fails (this is q ...
current_prolog_flag/2I'm always looking for the way make the: ### toplevel printer print lists in ful ...
same_length/2Behaves like a bidirectional length/2, same as: == ?- length(L,3). L = [_22942, ...
nth0/3A "vector nth0" vector_nth0/3, based on nth0/3 and which retrieves several entri ...
nth0/3This can also be used for *searching in a list* (and thus for checking whether a ...
-- Powerful append/2 is powerful.
list_to_set/2See also library(ordset) https://www.swi-prolog.org/pldoc/man?section=ordsets an ...
select/3== ?- select(10,[1,2,3],R). false. ?- select(2,[1,2,3],R). R = [1, 3] ; % maybe ...
write_canonical/1Quite an interesting predicate to see what AST the parser has created from the s ...
functor/3This image provides a short overview of the "assembly/disassembly" predicates: h ...
compound_name_arity/3[This page](https://bit.ly/3e5p4Aw_prolog) provides a short overview of the "ana ...
number/1Rational Numbers are "numbers" and "atomic" (latest in SWI-Prolog 8.1.24, ration ...
append/2How to remove an element from a list (which must contain it) using append/2 once ...
member/2## Some text vagueness "provides determinism on the last element" should be "pro ...
Sec. 5.1Do not be confused by '[|]'.
Sec. 5.4There is an additional == library(dicts) == https://www.swi-prolog.org/pldoc/man ...
\==/2Application: membership check in a difference list, to check whether we have rea ...
atom_codes/2## Testing atom_codes(_,_) == :- begin_tests(atom_codes). test(listwards_atom ,[ ...
sleep/1Oh important: You can sleep a float time! == % 5 seconds sleep ?- Sleep=5,get_ti ...
random/1Watch out for confusion: Obtaining a pseudo-random float using the *built-in ran ...
select_dict/3Trying to use dicts as "named varargs" here... Picking a value from a dict, and ...
get_dict/3== ?- get_dict(x,_{x:1, y:2},R). R = 1. ?- get_dict(y,_{x:1, y:2},R). R = 2. ?- ...
-- I have been looking for a predicate to split a list L into three pieces: - Front (a list) - Element at Index N (0-based) - Back (a list) such that: == append([Front,[Element],Back],L). == Here is one.
nth0/4Replacing an element in a list (with 0-based indexing) from https://stackoverflo ...
foreach/2The "foreach" example is confusing because "dif/2" freezes until a decision can ...
Sec. 2## Errors on reloading source code Note that all the predicates (including helpe ...
Sec. 4.26.2.1Links to the GMP library: https://gmplib.org/ https://en.wikipedia.org/wiki/GNU_ ...
predsort/3This absolutely needs to be extended to `predsort(+Pred, +List, -Sorted, +Flags) ...
current_prolog_flag/2For the next iteration of the website, the flags listed really need their indivi ...
compare/3This is Prolog's "spaceship operator" (three-way compariosn): https://en.wikiped ...
predsort/3Here is another example of predsort in a rather disconcerting duplicate-killing ...
Sec. 12.2.3Once you have compiled an .so file, make it discoverable by swipl using == asser ...
Sec. 12.2.3Try == swipl-ld -help == for help information (for some reason, not -h or --help ...
Sec. 4.1I just noticed that there is a description of functor//arity in that paragraph s ...
PL_get_atom_chars()Returns 1 on success, 0 on failure (e.g.
PL_register_foreign_in_module()"After this call returns successfully" means... it returns 0?
Sec. 12.3_As of SWI-Prolog 7.3.12, the arity of terms has changed from int to size_t._ It ...
sleep/1"On most non-realtime operating systems we can only ensure execution is suspende ...
meta_predicate/1Confused by "The argument is a term that is used to reference a predicate with N more arguments than the given argument term.
Sec. 6.5Confused by "The argument is a term that is used to reference a predicate with N more arguments than the given argument term.
Sec. 6.1As noted by Paulo Moura "Prolog Modules" (SWI-Prolog Modules?) can be seen as "o ...
current_prolog_flag/2This is not the user's home directory: == ?- current_prolog_flag(home, X). X = ' ...
nan/0== ?- NAN is nan, write_canonical(NAN). 1.5NaN NAN = 1.5NaN. == Weird! I suppose one can test against NaN using =:= ?
max/2This should really be extended to take vectors: == Big is max(ListOfExpressions) ...
=:=/2Some examples: Everything must be known at the time of evaluation: == ?- 2*2 =:= X. ERROR: Arguments are not sufficiently instantiated ?- X=4.0, 2*2 =:= X. X = 4.0. ?- cos(X) =\= sin(X). ERROR: Arguments are not sufficiently instantiated % Ok, then! ?- X=pi, cos(X) =\= sin(X). X = pi. == Sadly =:= is a bit fussy.
\==/2For clarity, this should be written with complimentary parentheses: == \+(Term1 ...
copy_term/2An example: == ?- X=f(A,b),Y=f(a,B),copy_term(X,Y). X = f(A, b), Y = f(a, b), B ...
\=/2We read: _"In other cases, such as `?- X \= Y.`, the predicate fails although th ...
\=/2It would be clearer to write == \+(Term1 = Term2) == rather than than == \+Term1 = Term2 == Although of course: == ?- write_canonical(\+Term1 = Term2). \+(=(_,_)) ==
->/2## Naming Do not call this particular beast an "implication".
initialization/2Regarding "main", note that an exit status of 0 indicating "success" is a conven ...
Sec. 2.11.2.1Contra Carlo Capelli's note, the "shebang" is not at all overengineered. As a co ...
option/2I'm not sure why, but this predicate is indeed semi-deterministic. This means yo ...
Sec. 4.35Also consider library "filesex" ("extended operations on files", damned PhDs doi ...
Sec. A.22For the shebang trick where swipl is started indirectly through =env= == #!/usr/ ...
Sec. A.22For the "initialization" directive, see: https://www.swi-prolog.org/pldoc/doc_fo ...
open/3What does an empty option list assume about the encoding of the file? See: https ...
setup_call_cleanup/3The example given in the text is incomprehensible, here is another one: == alty ...
setup_call_cleanup/3Demo of determinism in the cleanup procedure: == ?- setup_call_cleanup(true,memb ...
setup_call_cleanup/3== intro :- format("intro\n").
deterministic/1Example: == ory :- format("1st clause:\n"), deterministic(D1), format(" Det at ( ...
setup_call_cleanup/3This is a bit like try-with-resources in Java: https://docs.oracle.com/javase/tu ...
atom/1See also: https://www.swi-prolog.org/pldoc/man?section=text-representation Atoms ...
Sec. 2.12This page could really become more legible if the flags were divided up by subje ...
option/3Example: Give me the option for =foramt=, but use =html= if it is missing == ?- ...
[wiki] SWI-Prolog -- Installation on Linux, *BSD (Unix)You may want to ensure that environment variable SWI_HOME_DIR is unset before co ...
Sec. 6.2## Module naming _Modules are organised in a single and flat namespace and there ...
Sec. 6.1The page of "library(prolog_xref)" seems to be here: https://www.swi-prolog.org/ ...
Sec. GThis above just the list of references that appear in the Documentation. I have ...
get_time/1I wonder why this isn't == T is get_time() == possibly == T is get_time(now) == ...
begin_tests/1Note that if you add tests from the command line using [user]., you can do so on ...
end_tests/1What is the rationale behind having to repeat the test name in the block termina ...
consult/1You can actually also pass a series of files: consult([foo,roo])
consult/1Edge case: If there are files "roo", "foo", "foo.pl" and "foo.pl.pl" Then [foo] ...
Sec. A.21I would also point the user to https://www.swi-prolog.org/pldoc/man?section=ords ...
predicate_property/2This may not be directly clear from the description: Perhaps surprisingly, the t ...
Sec. 6.3Some example for loading a library (in this case, the lynx library): https://bit ...
Sec. 2.12An example for SWI Prolog reading ",," as a "," followed by a separating ",", wh ...
[wiki] Eat Your Own Dog FoodThis should really be linked from the "Documentation" intro page.
Sec. 3ISO Prolog only defines the "% ..." comments and the "/* ... */" comment block i ...
maplist/2Major explainer including examples for the use of maplist/2 here: https://bit.ly ...
string_concat/3Prolog just needs a syntax extension so that you can write: Name = "John", Cand ...
float/1"When used around the 2nd argument of is/2, the result will be returned as a flo ...
Sec. A.30This needs more explanation on the attached "database file". Is it a text file w ...
Sec. 4.13Please provide the link to library(persistency) in the second paragraph of "Usin ...
pengine_event_loop/2I think the use of "Closure" here is a bit misleading.
Sec. 1.1The link = http://www.swi-prolog.org/pldoc/doc/home/vnc/prolog/lib/swipl/library ...
catch/3## Example 1 Example, catching format/2 complaining about a lack of arguments: = ...
float/1What is a "float"?
Sec. 2.16.1.3This section applies to Strings, too == ?- format(">\c | hello<"). >hello< true. == Jan Wielemaker writes: "Although incomplete in the implementation, the overall idea is that predicates that require text input accept all text representations and produce the documented type as output." ---- The \uXXXX encoding (really, NAMING of a glyph in the Unicode BMP) is called "UCS-2" https://en.wikipedia.org/wiki/Universal_Coded_Character_Set More on Unicode here: https://en.wikipedia.org/wiki/Unicode#Architecture_and_terminology ---- Note that the unicode escapes are meant to be used in the context of strings, atoms or chars (atoms of length 1).
writef/2As noted on the page of format/2, the escape sequences one uses in practice are ...
format/2I'm trying to write an **overview of printing possibilities** in SWI Prolog here ...
atom_string/2A question of having wide characters in an atom and a string: == ?- S="s\u2200", string(S), atom_string(A,S), atom(A). S = "s∀", A = 's∀'. == A question of having ASCII characters in encoded form: == ?- S="s\x5E", string(S), atom_string(A,S), atom(A). S = "s^", A = 's^'. == A question of displaying ' in an atom and a string: == ?- S="s\'", string(S), atom_string(A,S), atom(A). S = "s'", A = 's\''. == == ?- S="s'", string(S), atom_string(A,S), atom(A). S = "s'", A = 's\''. ==
read/1This corresponds to "serialization/deserialization" in Java and other languages. You CAN but shouldn't use this for reading input typed in by the user. Example: ?- with_output_to(string(Buf),write_term(a(b,c,[1,2,3],var(ZZ)),[])), read_term_from_atom(Buf, T, []). Buf = "a(b,c,[1,2,3],var(_7256))", T = a(b, c, [1, 2, 3], var(_7848)). Use readutil for user querying: https://www.swi-prolog.org/pldoc/man?section=readutil Example: format("Answer me!\n"), read_line_to_string(user_input,S1), string_lower(S1,S2), (member(S2,["yes","1","ok","y","ja","oui"]) -> format("OK!") ; (format("NOK"), fail)). Answer me! |: YES OK!
maplist/3Some examples for the use of maplist/3: https://bit.ly/2KCDpao_prolog
Sec. 4.6Note that "==" and "\==" are really tests about the current state of the computa ...
Sec. 2.12I tried to write up some info on "double quotes".
Sec. 2.1"Getting started quickly" should point the user to a description/tutorial/howto ...
Sec. 2.16.1.9See also: https://eu.swi-prolog.org/pldoc/man?section=widechars
Sec. 2.12For "double_quotes": "This flag determines how double quoted strings are read by Prolog and is ---like character_escapes and back_quotes--- maintained for each module." Better: "...scoped to each module, which means that the interpretation of the source code of the module is read according to the value of that flag." (although, thinking a bit about this, when you call foo("xyz") of a predicate from a module that has the "double_quotes" flag set to "chars", will that predicate be called with a list of characters instead of a String?
Sec. 2.16.1The title of this section is "ISO Syntax Support" but should probably be "Extens ...
Sec. 2.16.1.5This is not ISO Prolog, but quite useful. Compare with Java where this trick is ...
findall/3Note that findall/3 is limited by the Goal predicate.
Sec. 2.12I'm always looking for the way make the ### toplevel printer print lists in full Instead of: == OutColl = [0xE3,0x82,0xA2,0xE3,0x82,0xA4,0xE3,0x82,0xA6|...]. == I want == OutColl = [0xE3,0x82,0xA2,0xE3,0x82,0xA4,0xE3,0x82,0xA6,0xE3,0x82,0xA8,0xE3,0x82,0xAA]. == And the command is: == set_prolog_flag(answer_write_options,[max_depth(100)]). set_prolog_flag(debugger_write_options,[max_depth(100)]). == or even unset any depth limit: == set_prolog_flag(answer_write_options,[max_depth(0)]). set_prolog_flag(debugger_write_options,[max_depth(0)]). == Note that: - "answer_write_options" is somehow lost in between "toplevel_print_factorized" and "toplevel_prompt". - also, the option names are **not found** when searching and/or have no links that can be used to refer to them: "answer_write_options" -> no matches.
Sec. 5.2.1Regarding the traditional "string": Wikipedia says at https://en.wikipedia.org/w ...
Sec. 4.1Searching for "mode flag" or "mode indicator" does not bring up this page in the search results, but should.
call/1The text should probably be changed from Note that clauses may have variables as subclauses, which is identical to call/1. to Note that clauses may have variables as goals.
[wiki] Program Development ToolsThere is nothing for IntelliJ JetBrains plugin repository: https://plugins.jetbr ...
[wiki] Program Development ToolsCurrently trying "ProDT"... Trying with Eclipse Oxygen (Eclipse 4.7, 2017-12) on Linux Fedora with JDK 1.8.0 The original site is http://prodevtools.sourceforge.net/ - the instructions on that site are a bit stale.
[wiki] Program Development ToolsThe link to "Prolog Development Tool - PDT" and the link to "Prolog Development ...
[wiki] SWI-Prolog future directionsIt might be helpful to indicate when this entry was written.
[wiki] Fix incomplete installation due to missing dependenciesDead link in the line "Redo the build.
[wiki] Wiki page at "build/issues/xpce.txt"Compiling on Fedora: At first sight, the error log seems to indicate that there ...
[wiki] XPCE: the SWI-Prolog native GUI librarySadly, the link The design of the XPCE/Prolog interface (Publication in Workshop on Logic Programming Environments, 2002) http://hcs.science.uva.nl/projects/SWI-Prolog/articles/wlpe-02.pdf is dead. However, there is https://arxiv.org/abs/cs/0207053 - "An Architecture for Making Object-Oriented Systems Available from Prolog"
bagof/3## No solutions for Goal lead to false, instead of an empty bag. == ?- bagof(X,( ...
^/2Outside of arithmetic contexts, the ^/2 operator is used to mark variables as "n ...
==/2Confusingly, the explanations uses two adjectives: "equivalent" and "identical".
?=/2I think the text "Succeeds if the syntactic equality of Term1 and Term2..." shou ...
[wiki] Wiki page at "FAQ/reconsult.txt"The link to "Initialising and Managing.." has to be changed to http://www.swi-pr ...
cyclic_term/1What is the cost of detecting that a term is cyclic (a rational tree).
memberchk/2This predicate does not backtrack, which is the idea.
Sec. 5See also http://eu.swi-prolog.org/pldoc/man?section=preddesc from the reference ...
Sec. 4.1See also the description in the package of the Prolog documentation generator: h ...
Sec. A.4.3Actually missing a way to get the number of elements in the association list...
Reference manual#### SWI-Prolog Wiki entry There is a wiki entry at the SWI-Prolog Discourse Gro ...
assertion/1Example: Executing on the Prolog toplevel: == ?- assertion(false). ERROR: Assert ...
call/2In this context, the following, though rather old, is highly readable: "Higher-o ...
file_search_path/2Thanks @Jan.
[wiki] Representation and printing of floating point numbersAnd here is the [reference for floating-point notation](http://www.dcc.fc.up.pt/ ...
[wiki] Representation and printing of floating point numbersHere is a another link of interest that predigests the "What Every Computer Scie ...
file_search_path/2The definition should be "file_search_path(?Alias, ?Path)" as the following work ...