Can we use foldl with bool values?

I’m using SWI-Prolog.

When I type make., I get the following…

Warning: The predicates below are not defined. If these are defined
Warning: at runtime using assert/1, use :- dynamic Name/Arity.
Warning:
Warning: =</3, which is referenced by
Warning:        c:/users/username/documents/prolog/ex 03.pl:247:8: 1-st clause of ord/1

…which I just realised is a warning, not an error. My mistake.

However, if I try to use it, I get an error…

ERROR: Unknown procedure: (=<)/3
ERROR:   However, there are definitions for:
ERROR:         (=<)/2
ERROR:
ERROR: In:
ERROR:   [13] =<(2,1,_1434)
ERROR:   [12] apply:foldl_([2,3],user:(=<),1,true) at c:/program files/swipl/library/apply.pl:316
ERROR:   [11] apply:foldl(user:(=<),[2,3],1,true) at c:/program files/swipl/library/apply.pl:312
ERROR:   [10] ord([1,2|...]) at c:/users/username/documents/prolog/ex 03.pl:246
ERROR:    [9] toplevel_call(user:user: ...) at c:/program files/swipl/boot/toplevel.pl:1173

Sorry for the confusion.

I read the top-level “true” or “false” as “the query is true” (or “is false”), not “the query returns true” (or “returns false”). In the case of “is false”, there is no derivation tree, which is different from a derivation tree that has a value of “false”.

(There’s a separate notion of “reification”, which does use “true” and “false” as a kind of return value, but that’s a different discussion and has its own pluses and minuses)

Perhaps :poop: is more easily understood than :pinched_fingers:t5: (on my laptop, I couldn’t figure out what this symbol is).

Or :x: – although the opposite of that is :o:, which might not be understood everywhere.

These things are called residual variables, i.e., variables that are not connected to the solution but still carry constraints. If you want them printed, use

?- set_prolog_flag(toplevel_residue_vars, true).

or call_residue_vars/2. The toplevel behavior uses this predicate. It is not free though as it introduces administration of the attributed variables around and tells the garbage collector to not collect these. Still, for educational and development scenarios it is a good idea to switch this flag on.

That is part of the well founded semantics introduced by tabling. The whole idea remains that the answer is a valid Prolog goal that behaves as the original query. You could see it as partial evaluation, though that term is a bit misleading here as it usually refers to simplification of a program based on static analysis rather than running it.

1 Like