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
compare_stringy_thingsatom_string/2
concatenation_of_stringsatomics_to_string/2
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.52, [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, load_test_files/1, !/0, reset/3, write_canonical/1, numbervars/3, Sec. 2.10.1, Documentation, order_by/2, op/3, ./2, **/2, foldl/4
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
failure_driven_loopforall/2
floundering\+/1
fluentsSec. 11
foldrfoldl/4
functionality_needs_helpclumped/2
hashesSec. 5.4
here_documentsSec. A.42
if_then_else->/2
input_from_stringopen_string/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
semicontext_dcgcall_dcg/3
single_quoted_characterinteger/1
soft-cut*->/2
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

clumped/2## Missed opportunity This doesn't run in reverse, doing run-length decoding!?! ...
foldl/4## Doc needs help The example says: > the last two arguments [of foldl/4-7] form a typical difference pair That's definitely not right.
must_be/2## Reviewed list of keywords These expressions absolutely need to become composi ...
Sec. A.39## Note that This implementation seems to be **replaceable** by the built-in [SW ...
Sec. A.4assoc_to_list/2 doesn't take kindly to a mix-up in arguments: ``` ?- empty_assoc ...
call_dcg/3## Doc needs help The second paragraph is about this (I think): call_dcg/3 exist ...
nonground/2Grabbing an unbound variable from the term that appears as argument 1: **Standar ...
Sec. A.38Here is code to query the user with several questions and put the result into a ...
max_member/2Unexpectedly, it is == max_list(List,Max) == on one hand but == max_member(Max,L ...
min_member/2The surprises of Prolog due to the fact that one never knows whether variables a ...
not/1Note that not/1 is not declared as an operator: == ?- write_canonical(not true). ERROR: Syntax error: Operator expected == whereas \+ is, allowing nicer syntax: == ?- write_canonical(\+ true). \+(true) true. ==
\/1The ISO Standard says on page 124: > '\\'(B1) evaluates the expression B1 with v ...
**/2## Naming This operator is called "power" in the ISO standard of 1995, page 119. ## More on operators: As Wouter Beek says: > Notice that the precedence of (**)/2 is xfx, > which is different from that of (^)/2, which is xfy. These operators also have the same precedence, 200 (pretty strong), same as the precedence of unary `-`.
;/2From [Coding Guidelines for Prolog](https://arxiv.org/abs/0911.2899): ``` All bu ...
./2Does this still exist?
-/1Note that there is a parse difference between `-1` and `-(1)` aka `- 1`: ``` ?- ...
Sec. 7.2.2What is the difference between the "markdown backtick" and the "doxygen backtick ...
=/2## Docs neecs some help maybe? The text > It acts as if defined by the following fact `=(Term, Term).` does not make sense to me.
Sec. 4.25## Some examples and an explainer Right here: [**About Operators**](https://gith ...
min_list/2See comments at max_list/2
op/3## How do I... Find out from which module an operator comes from? ## Some exampl ...
permutation/2To (deterministically) select any permutation "at random" use random_permutation ...
random_permutation/2The predicate is indeed symmetric: ``` ?- random_permutation([1,2,3,4],L). L = [ ...
merge_options/3## This one is buggy ``` ?- merge_options( [max_depth(100),quoted(true),portray( ...
Sec. A.42## Doc needs help. The given example has a syntax error - the final parenthesis ...
random/1See also comments under https://eu.swi-prolog.org/pldoc/doc_for?object=f(random/ ...
random/3See also comments under https://eu.swi-prolog.org/pldoc/doc_for?object=f(random/ ...
random_float/0See also comments under https://eu.swi-prolog.org/pldoc/doc_for?object=f(random/ ...
crypto_n_random_bytes/2The appropriate OpenSSL man page for that would be (I think), "man RAND_bytes": ...
option/2You can use dicts!
call_with_depth_limit/3## Examples true/0 needs depth 1: ``` ?- call_with_depth_limit(true,0,R). R = de ...
\+/1This operator is a hard nut. I have some notes on the Prolog `\+` here: - [**Not ...
sum_list/2As per a remark made on stack overflow, this predicate's name expresses what it ...
arg/3Also raises type_error if Arg is not compound: ``` ?- arg(1,foo,X). ERROR: Type ...
duplicate_term/2New empty cells are allocated for any unbound variable in the original: ``` ?- G ...
order_by/2The description is mangled... > "Spec is a list of terms, where each element is ...
compare/3See https://eu.swi-prolog.org/pldoc/man?section=standardorder for the "Standard ...
DocumentationThe "paperback version" if for "SWI Prolog Reference Manual 6.2.2" That's too ol ...
read_string/5== ?- open_string("Hello@",Input), read_string(Input, ",@", "\t ", End, String) ...
text_to_string/2This behaves the same as atom_string/2, but only in "string direction" and doesn ...
nb_setarg/3Beware this little predicate [Unexpected result for predicate nb_setarg/3](https ...
Sec. D## Some corrections "A Prolog variable is a value that‘is not yet bound'." That ...
Sec. 2.10.1## Needs correction > "which models each predicate in a Prolog program as a stat ...
Sec. 11## For Pengines, see The section on [Pengines](https://eu.swi-prolog.org/pldoc/d ...
[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.1## Mode indicator cheat sheet / overview [Get it from here](https://github.com/d ...
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/3## You can use dicts!
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]}. ==
[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## Note that atom_length has tunable behaviour: [current_prolog_flag](https://eu ...
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.42## Here Documents This is a good way to implement [Here Documents](https://en.wi ...
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/1## That naming is confusing When you ask == var(X). == you are actually asking w ...
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) ...
Sec. 11There is also a pack for UUIDs: https://eu.swi-prolog.org/pack/list?p=pluuid Exp ...
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 original TWiki idea of == =code= Typeset text fixed font for identifiers (se ...
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/2> Suppose an argument must be a non-negative integer.
-- ## Something for the toolbox: What is a character? == character(A) :- atom(A),at ...
is_list/1## The mode indicator seems wrong The [mode indicator](https://eu.swi-prolog.org ...
reverse/2## The implementation (Click on the :- button in the doc) == reverse(Xs, Ys) :- ...
Sec. 4.21[**This page**](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_note ...
setarg/3The specification should probably be == setarg(+Arg, !Term, +Value) == Position ...
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 the wrong name for this functionality - it should be use_modu ...
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/3See also - atomics_to_string/2 - concatenate "anytext" list elements to a string - atomics_to_string/3 - join "anytext" list elements to a string with separator
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## See also The predicates min_list/2 and max_list/2 from library [library(lists ...
forall/2In particular: Àny binding is rolled back on success because it happens behind t ...
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## Extension? Would there be a usage for a ``` dict_size(+Dict,?Arity) ``` to de ...
random_between/3## See also The comments under https://eu.swi-prolog.org/pldoc/doc_for?object=f( ...
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## Companion info [**My notes on the Byrd Box model here**](https://github.com/d ...
Sec. 4.14## Also Not a "database" but allows to define "record-like terms": [`library(rec ...
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 predeces ...
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 ...
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## Some potentially useful notes [About `between∕3`](https://github.com/dtonhofe ...
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.52## A slight fix for the text of "closure" > The term's name is the name of a pre ...
-- This operator is a hard nut. I have some notes on the Prolog `\+` here: - [**Not ...
[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? T ...
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. ...
length/2## Doc needs fix Maybe change the parameter name from `Int` to `Length`. ## Note ...
atomic_list_concat/2## Another example Surround a list of characters with '<' and '>' to create an X ...
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,L ...
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 ...
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## Example In the same way that length/2 can generate lists of fresh unbound var ...
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 ...
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/1Let's make the distinction between the offer of built-in functions and library p ...
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 ...
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 ...
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/2## See also The predicates min_list/2 and max_list/2 from library [library(lists ...
=:=/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## Notes For - the if-then-else `->/2` + `;/2` and - the [soft-cut](https://eu.s ...
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## This is the "comparison operator for string things" Suppose you have received a "stringy thing".
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/3Note the use of clumped/2 in the "Counting word frequency" example. Explainer on maplist/3 and examples for the use of maplist/3 here: [**Examples for the Prolog predicate `maplist/3`**](https://github.com/dtonhofer/prolog_notes/blob/master/swipl_notes/about_maplist/maplist_3_examples.md)
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 [**Notes about findall/3**](https://github.com/dtonhofer/ ...
Sec. 2.12I'm always looking for the way make the ### Prolog Toplevel printer print lists ...
Sec. 5.2.2Regarding 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## See also [library(aggregate)](https://eu.swi-prolog.org/pldoc/man?section=agg ...
^/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 [SWI-Prolog's page on predicate descriptors](https://eu.swi-prolog.org/ ...
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 ...