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

Tags by LogicalCaptain

backquotesatom_codes/2
bit_operationxor/2, \/1, /\/2, \//2, <</2, >>/2
bit_shift_operation<</2, >>/2
caretbagof/3
coroutinesSec. 4.9
datatypesSec. 4.5
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.51, [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.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, atomic/1, Sec. 5.3.3, compound_name_arity/3, compound_name_arguments/3, get_dict_ex/3, Sec. 7.6, atom_string/2, acyclic_term/1, is_list/1, Sec. 5, Sec. 2.2.5, string_chars/2, Sec. 8.1, ord_intersection/2, expand_file_name/2, Sec. 12.4.11, Sec. 12.4.10, Sec. 12.4.16, Sec. 12, Sec. 12.3.1, Sec. 12.8.1, Sec. 12.4.17, Sec. 12.8.2, abolish/1, Sec. A.36, Sec. 4.9, Sec. 4.17.1, Sec. A.37, load_test_files/1, !/0, reset/3, write_canonical/1, numbervars/3
docs-needs-helpSec. 4.1, Sec. 5.4.1, read_stream_to_codes/3
dollar_var_notationnumbervars/3
exceptionsSec. A.16, throw/1, catch/3, Sec. 4.10.3, assertion/1
floundering\+/1
fluentsSec. 11
hashesSec. 5.4
if_then_else->/2
interactorsSec. 11
joinatomic_list_concat/3
limit-solutionsonce/1
listlengthlength/2
mapsSec. 5.4
mode-indicatorsSec. 4.1
modesSec. 4.1
multiline-stringsSec. 5.3
naf\+/1
negation\+/1
plunit
predicate-modesSec. 4.1
search-in-listnth0/3
single_quoted_characterinteger/1
toplevel_result_bufferSec. 2.9
trimsplit_string/4
try_finallysetup_call_cleanup/3
type_assertionmust_be/2
typesSec. 4.5
typetreeSec. 4.5
unit-tests

Comments by LogicalCaptain

Sec. 11## Some text fixes needed "Asking an engine for the next answer attaches the eng ...
[wiki] SWI-Prolog copyrightThis is the https://opensource.org/licenses/BSD-2-Clause with one slight differe ...
numbervars/3## documentation needs help The output has changed: ``` ?- Term = f(X,Y,X), numb ...
numbervars/3## Recap to fight confusion! **numbervars** Rewrites the term.
write_canonical/1## documentation needs help We read: "Equivalent to write_term/2 using the optio ...
Sec. 2.9``` ?- $X. ``` seems to ... evaluate to the value of the previous `X`?
tmp_file_stream/3## Watch out Getting an == Arguments are not sufficiently instantiated == error? Note that there are two tmp_file_stream/3 predicates which take parameters with different semantics!
tmp_file/2This predicate **does not really create a file**, it just creates a unique _name ...
Sec. 4.1The `+` also accepts unbound variables.
Sec. 4.1Actually "The argument mode indicator" should be "The parameter mode indicator". _A parameter is a variable in a method definition.
sort/2That ``` sort([B,A,1], [2,3,1]). ``` succeeds is a **rank abomination**.
Sec. 4.14.1.1This is pretty hot but maybe more adapted to CHR, which is based on a mutable da ...
>>/2Here is some functionality to transform integers into lists of 0,1 and the conve ...
>>/2The underlying bit pattern seems to be 2-complement with an infinite number of b ...
Sec. 4.9## Errata The paper "Schrijvers et al., 2013" has been published in [Theory and ...
reset/3## No matching `Ball` If the argument of shift/1 _cannot_ be unified with any `B ...
Sec. 4.8In this context, the following, though rather old, is highly readable: **Higher- ...
!/0## Doc-needs-help The expression == t4 :- \+(a, !, fail). == is invalid.
Sec. 4.33Of course, **all** variables of Prolog are **essentially global** (sometimes thr ...
call_with_inference_limit/3Try exceeding the limit: == ?- call_with_inference_limit( bagof(X,between(1,inf, ...
*->/2## In other words... Compared to `->/2` this construct backtracks over the "prem ...
option/3It's about the value found in the term: == ?- option(foo(X),[],none). X = none. ...
Sec. A.26Note in particular that you cannot backtrack over the list of options via option ...
Sec. A.15Equality of dicts (`==`) while disregarding differences in tags: == dict_equalit ...
Sec. 6.1## Modules are objects As noted by Paulo Moura "Prolog Modules" can be seen as " ...
partition/4A partition_freely/4 predicate which partitions into arbitrarily many partitions by accepting a "partitioning closure" as first argument, returning the result as an SWI-Prolog dict where the dict's keys are the partition keys: - [`partition_freely.pl`](https://github.com/dtonhofer/prolog_notes/blob/master/code/heavycarbon/utils/partition_freely.pl) - [`partition_freely.plt`](https://github.com/dtonhofer/prolog_notes/blob/master/code/heavycarbon/utils/partition_freely.plt) Example: Define a partitioning predicate taking 3 arguments == partition_by_length_modulo_m(Modulo,Atom,Key) :- atom_length(Atom,Length), Key is Length mod Modulo. == A "partitioning closure" might then be for exmaple `partition_by_length_modulo_m(5)`: a partially filled in predicate call. Then: == ?- partition_freely( partition_by_length_modulo_m(5), [silent,puffy,left,damaged,fascinated,deafening, wistful,whip,nest,inquisitive,imperfect,jog,unwieldy,provide,locket,reign], result_tag, DictOut). DictOut = result_tag{ 0:[puffy, fascinated, reign], 1:[silent, inquisitive, locket], 2:[damaged, wistful, provide], 3:[jog, unwieldy], 4:[left, deafening, whip, nest, imperfect]}. ==
Sec. A.37The header says: "Built-in function random/1: A is random(10)" but the correspon ...
[wiki] The SWI-Prolog HOWTO collectionThis page does not list all the available howtos tht can presumably be found in ...
Sec. 4.14.1See also the howto page: [How to deal with the Prolog dynamic database?](https:/ ...
[wiki] Issues with gmpMore on GMP at [gmplib.org](https://gmplib.org/) and the [Wikipedia GMP entry](h ...
Sec. 4.17.1"Initially, these are bound to the same stream as user_input and user_error." Sh ...
atom_length/2## Something for the toolbox: What is a character? == character(A) :- atom(A),at ...
normalize_space/2As Jan says in the hierarchically-above page (which took me some time to click o ...
atom_number/2See also number_string/2
number_string/2The corresponding "atomikky" predicate, however, is called atom_number/2 Note th ...
crypto_n_random_bytes/2The appropriate man page would be "man RAND_bytes" https://www.openssl.org/docs/ ...
div/2See also divmod/4 (_not_ visible in the function in the header list because it i ...
Sec. A.36## File under "docs need help" _"SyntaxName is the principal functor of the quas ...
with_output_to_chars/2Note that, in spite of the name, the output is a list of (unicode) code points, ...
Sec. A.42For quasi-quotation syntax as used here (defined for the keyword `string`), see ...
writeq/1Escape sequences are inserted into the ouput as appropriate: ``` ?- writeq('hel\ ...
Sec. 5.3_There does not seem to be a good place to put this remark:_ Multi-line strings ...
var/1Some notes on the ambiguity concerning the word "variable" can be found [**here* ...
Sec. 4.17.5IRI is an URI, but internationalized: - https://en.wikipedia.org/wiki/Internatio ...
abolish/1We read: "all clauses of a predicate with functor Functor and arity Arity" Howev ...
PL_set_engine()In jpl.c there is a call == PL_set_engine(NULL, NULL); == What does that do?
Sec. 12.8.2"Portable" in the sense of "if it works here, it works there" as opposed to "eve ...
Sec. 12.4.17The correct format from `SWI-Prolog.h` is ``` int PL_warning(const char *fmt, .. ...
Sec. 12.8.1For `PL_check_data` and `PL_check_stacks` the formulation is incomplete: I suppo ...
Sec. 12.3.1"Creates a new term reference to the same term as the argument.
Sec. 12## Pretty important and not standardized In [this discussion](https://groups.goo ...
Sec. 12.4.16Why can one call `PL_set_prolog_flag` for `PL_BOOL`, `PL_ATOM`, `PL_INTEGER`, bu ...
Sec. 12.4.15The relevant man page for POSIX OS-level signals is - man 7 signal - man 2 sigac ...
Sec. 12.4.10In predicate_t PL_predicate(const char *name, int arity, const char* module) how is the encoding of "name" and "module" specified (is it always UTF-8?) (nit pick: note the inconsistent sidedness of *) In int PL_call(term_t t, module_t m) the link to "figure 8" is dead.
Sec. 12.4.11We read: "See figure 8 for an example." But the link for "figure 8" (i.e.
getenv/2Background reading: https://en.wikipedia.org/wiki/Environment_variable On Linux, the environment variables, as attributes of the process, can be manually inspected by reading file `/proc/$PID/environ` like a normal text file.
read_stream_to_codes/3"creates a difference-list" should be "creates an open list ending in Tail if Ta ...
expand_file_name/2## References Note that this is based on "csh" filename expansion.
open/4Note that the "~" notation (used on Unix to indicate the user's home directory) ...
random/1## Sample application: Generate random atoms - [`random_atom.pl`](https://github ...
Sec. 11There is also a pack for UUIDs: https://eu.swi-prolog.org/pack/list?p=pluuid Exp ...
random_float/0An example that uses random_float/1 to generate a random atom: - [`random_atom.p ...
ord_intersection/2The first argument is not the/a [PowerSet](https://en.wikipedia.org/wiki/Power_s ...
Sec. 8.1## Explainer & Rewritten code For an explainer and rewritten code, go [**here**] ...
list_to_ord_set/2This predicate should probably be named list_to_ordset/2 instead of list_to_ord_ ...
Sec. 8.1.1Note that you can "put" to an unbound variable: == ?- put_attr(X,module,Y),get_a ...
attr_unify_hook/2"Triska 2016" is right here: https://www.metalevel.at/swiclpb.pdf "The Boolean C ...
put_attr/3On the toplevel, the predicate prints itself.
More on Communicating FSMs here: https://en.wikipedia.org/wiki/Communicating_fin ...
Sec. 4.10## My notes Personal notes on exceptions handling: - [About Exceptions](https:// ...
split_string/4The example as test case: == :- begin_tests(split_string). test("A simple split" ...
Reference manual## Sometimes the documentation website is confusing. Main elements: - [*The SWI- ...
[wiki] XPCE: the SWI-Prolog native GUI libraryFor some reason this page shows up in no "list of contents", one finds it throug ...
statistics/0There is a full-fat statistics/1 from `library(statistics)` (file `swipl/lib/swi ...
time/1This prints something like == % 4,623,232 inferences, 1.223 CPU in 1.229 seconds (99% CPU, 3780625 Lips) == But why aren't those values returned in variables?!? They can't even be caught using `with_output_to/2`: == ?- with_output_to(string(S),time(sleep(1))). % 1 inferences, 0.000 CPU in 1.000 seconds (0% CPU, 24841 Lips) S = "". == Time to go take a look at that code... (Also, what exactly is a "logical inference" ... is it a clause call?
integer/1This doesn't _really_ belong here but: A special way to generate integers is by ...
string_chars/2See also atom_chars/2
atom_concat/3For concatenating more than one atom in one operation, see atomic_list_concat/2 ...
shell/2This is actually _not_ a good approach. The command is passed as a string to the Bourne shell and is thus subject to the vagaries of the interpreter breaking it apart into command + args etc, i.e.
jpl_class_to_classname/2== :- begin_tests(jpl_class_to_classname). instance_ref_to_entity_name(InstanceR ...
Sec. 10See also: - https://en.wikipedia.org/wiki/POSIX_Threads - https://computing.llnl ...
threads/0Example: == ?- threads. % Thread Status Time Stack use allocated % ------------- ...
Sec. 2.2.5The latest output for the test given is: == ?- run_tests. % PL-Unit: test ERROR: /home/user/tests.pl:3: test a: assertion failed Assertion: float(8) ERROR: /home/user/tests.pl:3: test a: assertion failed Assertion: 8==9 A done % 2 assertions failed % 1 test failed % 0 tests passed false. ==
Sec. 7The Twiki idea of == =code= Typeset text fixed font for identifiers (see running text).
acyclic_term/1How expensive is this test?
get_dict/5This predicate is misnamed.
discontiguous/1Note that making one predicate (for example, a lookup predicate) discontiguous a ...
Sec. 4.10.3## ISO standard exceptions The ISO standard ISO/IEC 13211-1 is VERY paywalled (I won't say anything more about the reasonableness/ethics/sustainability of this), so: - The following page substantially _is_ the ISO Standard text: https://www.deransart.fr/prolog/exceptions.html - Ulrich Neumerkel lists the various error classes here: http://www.complang.tuwien.ac.at/ulrich/iso-prolog/error_k - The context is a discussion leading up to the second corrigendum of the ISO standard. ## More info I'm trying to keep [**this opinionated page**](https://github.com/dtonhofer/prolog_notes/blob/master/swipl_notes/about_exceptions/README.md) updated with info on Prolog exceptions. ## About the backtrace How do we get a backtrace and how does the exception term have to look to get one? The backtrace is filled in according to SWI-Prolog conventions because the ISO Standard has nothing to say about this. SWI-Prolog wants the second argument of the `error/2` term (given in the ISO standard as `Imp_def`) to look like `context(Location,Message)`.
type_error/2A little diagram to discuss the "instantiation & type & domain verification pipe ...
-- ## Something for the toolbox: What is a character? == character(A) :- atom(A),at ...
is_list/1## Some unit tests for this predicate [`test_is_list.pl`](https://github.com/dto ...
reverse/2Instead of reverse/2 after a successful recursion, consider using the correct [l ...
Sec. 4.21[**This page**](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_note ...
setarg/3Position is 1-based and the predicate fails if _Value_ is out-of-bounds: == ?- X ...
Sec. 2.2The example init.pl file is in lib/swipl/customize/init.pl in the installation d ...
load_files/2## Load from where? "The specification for a source file is handed to absolute_f ...
Sec. 6.5Noet that this works for complex goals too. For example, in one module: == :- mo ...
use_module/1use_module/1 is of course the wrong name for this functionality - it should be u ...
load_test_files/1## What does it do? The source code (click on the ':-' symbol) reveals that it c ...
string_length/2It actually accepts Numbers on "String" position: == ?- string_length(1r2,Len). ...
with_output_to/2## If the goal emitting output fails... Evidently, if the goal fails, and you ou ...
run_tests/0This predicate succeeds if all the tests succeeed and fails otherwise (i.e.
Sec. 4.39## "The Byrd Box Model" aka.
atomic_list_concat/3Shouldn't there be a "stringy_list_concat" which generates a string?
ground/1Notice that the anonymous variable stays unground as every new occurrence is rea ...
Sec. 7.6Here is an excellent explanatory paper for Well-Founded Models by Teodor Przymus ...
Sec. 9"In the current system, test units are compiled into sub-modules of the module i ...
get_dict_ex/3This predicate no longer exists (and this page will be removed in a future updat ...
debug/1Please read important note on **debug topics** in the comment section of **[debu ...
Sec. A.14## An important note on topics (I will add this to the manual text later): Jan w ...
Sec. 5.4.1.2## Documentation improvements - The parameter for .put/1 should be called "NewKe ...
Sec. 5.4.1## Doc needs help The `New` in `put(+New)`should really be called `NewKeyValuePa ...
dict_create/3The difference between dict_create/3 and dict_pairs/3 is: - dict_create/3 takes ...
-- Special case: When you create a module to host dict method calls, you don't list those in the "public list" section: Here, just the predicate is listed: == :- module(point, [point_length/2]). M.multiply(F) % Method ".multiply/1" on dict M := point{x:X, y:Y} % Returns a "point" dict :- X is M.x*F, Y is M.y*F.
list_debug_topics/0This is a user-oriented predicate: == ?- list_debug_topics. -------------------- ...
:</2## Naming IMHO, "select" is not the appropriate name here, the more so because " ...
sub_string/5Time for test cases! == :- begin_tests(sub_string). test(find_single_bravo,[true ...
min/2## Possible extension This should really be extended to take vectors: == Min is ...
forall/2Related reading: "Logical Loops" by Joachim Schimpf (2002) PDF downloadable here ...
is_dict/2A random atom is not a dict == ?- is_dict(atom,X). false. == A dict tagged "foo" is tagged "foo" indeed == ?- is_dict(foo{},foo). true. == Extracting the tag of a dict == ?- is_dict(foo{},X). X = foo. == An "anonymous dict" is a dict tagged as "foo" (this actually sets the tag of the anonymous dict to "foo" but we will never be able to ascertain this because there is no intruction to the right of the is_dict/2 call). == ?- is_dict(_{},foo). true. == Making another variable to denote the "hole" of an "anonymous dict" == ?- is_dict(Y{},X), X == Y. Y = X. == Setting/Binding/Refining the still fresh tag of the dict?
put_dict/3## Improvement The argument `New` should really be called `Updates` or `NewKeyVa ...
dict_pairs/3## Need doc fix "ordered list of pairs" means (probably) "ordered by natural ord ...
random_between/3## Example of selecting an id between 0 and 6 that is not in a (small) dict yet. This is an example of a "failure-driven loop". == clashfree_id_selection(Dict,Id) :- repeat, random_between(0,6,Id), (true;(format("CLASH for ~q\n",[Id]),fail)), % print CLASH on backtracking \+ get_dict(Id,Dict,_), format("FOUND ~q\n",[Id]), !. == Then == ?- clashfree_id_selection(_{3:x,4:x,5:x,6:x,7:x},Id). CLASH for 3 CLASH for 3 CLASH for 3 FOUND 1 Id = 1. == Philosophically, it is weird that that random_between/3 is "semidet" (i.e.
Sec. 4.32## For those looking for the correct predicate to use: - [Relevant predicates fo ...
Sec. 4.20For those looking for the predicate to use: - [Relevant predicates for generatin ...
debug_message_context/1The flag =message_context= is explained on the page for current_prolog_flag/2
is/2is/2 is **arithmetic function evaluation** from the original Prolog But in SWI-P ...
atomic/1The complement of atomic/1 is compound/1.
compound/1[**This page**](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_note ...
aggregate/3## Beware of the empty solution "The aggregate/3 version performs bagof/3 on Goa ...
findall/4Useful when you want to append to a list using several calls to findall/4. For e ...
number_codes/2## Getting the number from the list of character codes == ?- number_codes(N,[49, 50, 51]).
- [Cheatsheet for Perl Regular Expressions](https://perlmaven.com/regex-cheat-s ...
number_chars/2This tests whether the "serialized representation" doesn't lose digits: == ?- X ...
atom_chars/2See also string_chars/2 ## Tests are good Unit test code for atom_chars/2, also ...
debug/3## Topics Please read important note on **debug topics** in the comment section ...
Sec. 4.13Introduction 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".
-- ## Doc needs fix "Prolog is described in Schrijvers et al., 2013 (preprint 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) ). ==
Note the following outcomes of calling a CHR constraint from Prolog: - The call ...
"Committed Choice" very concretely means there is no backtracking over the CHR r ...
The 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 We read: _Finally, if A and B can unify, goals are del ...
throw/1I put together some comments on exceptions (especially on ISO standard exception ...
Sec. 2.10 ## "The Byrd Box Model" aka.
Sec. 4.14## Doc needs help Please provide the link to [`library(persistency)`](https://ww ...
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 I made on `freeze` [**Right here**](https://github.com/dtonhofer/p ...
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.2## Compound terms of arity 0 vs.
## Works "out of the box"! As an example, try 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/ ...
[wiki] SWI-Prolog downloadsTL;DR for "Install development version on Linux" (**official description** is [h ...
must_be/2## When to use must_be? This predicate should be used exclusively to perform con ...
include/3Example: We want the _Keys_ of _Key-Value_ pairs which match a certain _Value_. ...
## Test cases are your track bed through the swampland You do not want to haphaz ...
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 is unit test code for between/3**](https ...
compound_name_arguments/3[**This page**](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_note ...
=../2## A bit surprising perhaps == % works for atoms and strings ?- atom =.. X. X = ...
Sec. A.51## Don't forget the bracy part A question that often comes up is due to differen ...
\+/1I have some notes on the Prolog `\+` [**here**](https://github.com/dtonhofer/pro ...
[wiki] SWI-Prolog datatypesThe SWI-Prolog documentation has more on SWI-Prolog datatypes test predicates he ...
Sec. 4.5## If you have a a Prolog term denoted by variable name `T`, what could it be? = ...
repeat/0## See also forall/2 as a better alternative to the failure-driven loop ## Alter ...
once/1Definitely prefer once/1 over ->/2.
-- I put together some comments on exceptions here: [On Exceptions](https://github. ...
get_assoc/5Jan, why not add your comment to the documentation directly. This approach has t ...
length/2## See also same_length/2 - useful if you have the length of two lists to compar ...
atomic_list_concat/2The second argument is always from the set of atoms: == ?- atomic_list_concat([a ...
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/3## Bad naming!
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.3I had some fun writing =foldl/4= and =foldr/4=, including an implementation of = ...
mod/2See also divmod/4 (_not_ visible in the function in the header list because it i ...
foldl/4## Companion README A companion README with several examples can be found [**her ...
maplist/4All three lists must be the same length (or at least, must be able to be the sam ...
current_prolog_flag/2I'm always looking for the way make the: ### toplevel printer print lists in ful ...
same_length/2## Missed opportunity There is room for same_length/3 which not only checks same ...
nth0/3 ## Tips & Tricks This can also be used for *searching in a list* (and thus for ...
-- 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 syntax tree the parser has created fr ...
functor/3[**This page**](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_note ...
compound_name_arity/3[**This page**](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_note ...
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## See also nth0/3 which performs the same task, put also spits out the index: D ...
Sec. 5.1Do not be confused by '[|]'.
Sec. 5.4## Some additional documentation Notes I took: [**About Dicts**](https://github. ...
\==/2Application: membership check in a difference list, to check whether we have rea ...
atom_codes/2## Testing atom_codes(_,_) Unit test code is here [`test_atom_codes.pl`](https:/ ...
sleep/1## Example sleeptimes Run: == bagof([Sleep,Delta] ,T_begin^T_end^(member(Sleep,[ ...
random/1Watch out for confusion: ## Built-ins Obtaining a pseudo-random float using the ...
get_dict/3## Some demo code [`dict_getting_testing.pl`](https://github.com/dtonhofer/prolo ...
-- 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.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) ...
current_prolog_flag/2For the next iteration of the website, the flags listed really need their indivi ...
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.1See also: - https://www.swi-prolog.org/pldoc/man?section=glossary - https://stac ...
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`atom_t` may point to static memory or garbage-collectable memory if I understan ...
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.
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/2It is intuitively clear what "renamed (fresh) variables" means but it's not real ...
\=/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 construct 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 ...
Sec. 4.36Also 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/3## Another example: The example given in the text is hard to understand.
deterministic/1Example: == ory :- format("1st clause:\n"), deterministic(D1), format(" Det at ( ...
atom/1See also: https://www.swi-prolog.org/pldoc/man?section=text-representation Atoms ...
[wiki] SWI-Prolog -- Installation on Linux, *BSD (Unix)Note that contrary to the statement in the text: "Installing from source is ofte ...
Sec. 6.2## Do not export predicates if you just want to access them from test code It se ...
Sec. GThis above just the list of references that appear in the Documentation. I have ...
get_time/1Returns a float! Compare with Unix `date` command's "seconds since 1970-01-01 00 ...
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]). == If yo ...
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 ...
[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/2## Explainer Explainer including examples for the use of maplist/2 (and maplist/ ...
string_concat/3An application of string_concat/3: Creating strings consisting only of spaces. F ...
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 ...
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## Problematic Naming While the `Goal` argument is correctly named, `Catcher` is a confusing name for what is the exception term against which a thrown exception shall be against.
float/1## See also - [`float/1`](https://eu.swi-prolog.org/pldoc/man?function=float/1) ...
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/2## Cheatsheet A cheatsheet for format/2 can be grabbed here: - [PDF](https://git ...
atom_string/2## Text needs fixing - This predicate takes general numbers, including non-ratio ...
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 here: [Examples for the Prolog predicate ...
Sec. 4.6Note that "==" and "\==" are really tests about the current state of the computa ...
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.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/3## Notes about findall "My notes may well be of use to you, developer": [**Notes about findall/3**](https://github.com/dtonhofer/prolog_notes/blob/master/swipl_notes/about_findall/README.md)
Sec. 2.12I'm always looking for the way make the ### Prolog Toplevel printer print lists ...
Sec. 5.2.1Regarding the traditional "string": Wikipedia says at https://en.wikipedia.org/w ...
call/1## Backtracking works as expected == ?- call(member(X,[1,2,3])). X = 1 ; X = 2 ; X = 3. == ## Doc changes The 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 Worksho ...
bagof/3## No solutions for Goal lead to failure, instead of an empty bag. == ?- bagof(X ...
^/2Outside of arithmetic contexts, the ^/2 operator is used to mark variables as "e ...
==/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/1Example: == obtain_cyclic(L) :- L=[1,2,3,4,5|T],L=[1,2|T]. :- begin_tests(cyclic ...
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 Gr ...
assertion/1## When to use this? Jan Wielemaker writes: > Public APIs should not use asserti ...
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 ...