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

Tags by LogicalCaptain

coroutinesSec. 4.10
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.48, [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.14, Sec. A.29, float/1, check/0, Sec. A.20, end_tests/1, Sec. 6.1, setup_call_cleanup/3, Sec. A.37, open/3, \=/2, \==/2, meta_predicate/1, Sec. 12.3, PL_register_foreign_in_module(), PL_get_atom_chars(), number/1
docs-needs-helpSec. 4.1

Comments by LogicalCaptain

append/2How to splinter a list at position N into a frontlist, the element at position N ...
-- 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 ...
sort/2The description of "Natural Merge Sort": https://en.wikipedia.org/wiki/Merge_sor ...
write_canonical/1Quite an interesting predicate to see what AST the parser has created from the s ...
functor/3Example for domain error: == ?- functor(a(),N,A). ERROR: Domain error: `compound ...
compound_name_arity/3"Only works for compound terms" means it throws a "Type error" (not a "Domain er ...
number/1Rational Numbers are numbers and atomic in SWI-Prolog 8.1.24 (not sure when the ...
append/2How to remove an element from a list (which must contain it) using append/2 once ...
member/2### Some examples and differences with `memberchk/2` Check member presence, whic ...
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/2It eats atoms and strings: == ?- A='Hello',atom(A),atom_codes(A,X). A = 'Hello', X = [72, 101, 108, 108, 111]. ?- S="Hello",string(S),atom_codes(S,X). S = "Hello", X = [72, 101, 108, 108, 111]. == It emits atoms: == ?- atom_codes(A,[72, 101, 108, 108, 111]),atom(A). A = 'Hello'. == The codepoints are UCS-2 (2 byte) in SWI Prolog: https://en.wikipedia.org/wiki/Universal_Coded_Character_Set == ?- atom_codes('アイウエオ',S). S = [12450, 12452, 12454, 12456, 12458]. == Morph them to hex (with_output_to/2 is SWI-Prolog specific) == ?- atom_codes('アイウエオ',Katakana), maplist( ([Num,Out]>>with_output_to(string(Out),format("0x~16R",[Num]))), Katakana, OutColl). Katakana = [12450, 12452, 12454, 12456, 12458], OutColl = ["0x30A2", "0x30A4", "0x30A6", "0x30A8", "0x30AA"]. == Morph them to UTF-8 == atom_codes('アイウエオ',KatakanaUCS2), phrase(utf8_codes(KatakanaUCS2),KatakanaUTF8), maplist( ([Num,Out]>>with_output_to(string(Out),format("0x~16R",[Num]))), KatakanaUTF8, OutColl). KatakanaUCS2 = [12450,12452,12454,12456,12458], KatakanaUTF8 = [227,130,162,227,130,164,227,130,166,227,130,168,227,130,170], OutColl = [0xE3,0x82,0xA2,0xE3,0x82,0xA4,0xE3,0x82,0xA6,0xE3,0x82,0xA8,0xE3,0x82,0xAA]. ==
format/2Unfortunately, format does not (yet) support "leading zeros" as in == printf("%0 ...
sleep/1Oh important: You can sleep a float time! == % 5 seconds sleep ?- Sleep=5,get_ti ...
random/1Watch out for confusion: ### Built-in Obtaining a pseudo-random float using the ...
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. ?- ...
Sec. A.20I 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.
-- 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. 2Note that all the predicates (including helper predicates) between `begin_tests( ...
between/3Creating a list of 100 0s: == findall(0,between(0,99,_),L),length(L,X). ==
length/2Completely unintuitive for the rank beginner: How to create a list of 5 fresh va ...
Sec. 4.27.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) ...
length/2length/2 is marked ISO but is this really true? I checked ISO/IEC 13211-1 and .. nothing.
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 ...
length/2Implementation-wise, does length/2 scan the whole list of a passed actual List o ...
length/2"List is neither a list nor a partial list.
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). \+(=(_,_)) ==
->/2Consider the expression: == test1(A) -> exec1(A,B); test2(A) -> exec2(A,B); else ...
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.36Also consider library "filesex" ("extended operations on files", damned PhDs doi ...
Sec. A.21For the shebang trick where swipl is started indirectly through =env= == #!/usr/ ...
Sec. A.21For 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 ...
Sec. 6.2There is also the predicate =module/1= which is used to set (but not query) the ...
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.2You **cannot** load two files defining the same module: =file1.pl= with: == :-mo ...
Sec. 6.2_"Modules are organised in a single and flat namespace and therefore module name ...
Sec. 6.1The page of "library(prolog_xref)" seems to be here: https://www.swi-prolog.org/ ...
Sec. GThis is just the list of references that appear in the Documentation (I think, b ...
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.20I 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: http://bit.ly/2wCxa2G_prolog
Sec. 2.12An example for "iso": f(A,B):-format("~w and then ~w\n",[A,B]). ?- f(,,a). , and then a true. ?- set_prolog_flag(iso,true). true. ?- f(,,a). ERROR: Syntax error: Operand expected, unquoted comma or bar found
check/0The checker/2 link is dead.
Sec. 6.2The notation for referencing a specific predicate of a specific module is: =modu ...
[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/2I put up a page on github with some examples: http://bit.ly/2IrNfuG_prolog
Sec. 4.27.2.5A little program to exercise the "mod,div" and "rem,//" function pairs on github ...
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.29This needs more explanation on the attached "database file". Is it a text file w ...
Sec. 4.14Please 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/3Example, catching format/2 complaining about a lack of arguments: == catch( form ...
float/1What is a "float"?
Sec. 2.16.1.3This section applies to Strings, too ?- format(">\c | hello<"). >hello< true.
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 in SWI Prolog here: http://bit.ly/2P ...
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/3I put up a page on github with some examples: http://bit.ly/2In2NQj_prolog
Sec. 4.7Note 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/3findall/3 does not deal well with free variables.
Sec. 2.12I'm always looking for the way make the toplevel printer print lists in full Ins ...
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 ...
Sec. A.48Finally, there is the package http://eu.swi-prolog.org/pack/file_details/lambda/ ...
[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"
Sec. A.48Please add the live link to "maplist:" http://eu.swi-prolog.org/pldoc/doc_for?ob ...
bagof/3At http://eu.swi-prolog.org/pldoc/man?section=yall the text says that the Var^Go ...
^/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: ?- findall(X, memberchk(X, [one,two,three]), ...
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### Intro #### Gentle introduction http://www.learnprolognow.org/ by Patrick Bla ...
Genius! The index is messed up though
assertion/1===The links here don't work. They should go to http://eu.swi-prolog.org/pldoc/d ...
call/2In this context, the following, though rather old, is highly readable: "Higher-o ...
is_of_type/2This is _probably_ an alias for must_be/2 ? No, wait it does not throw as does m ...
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 ...