|
|
|
|
|
by jodrellblank
34 days ago
|
|
> "but the ";" at the top-level is not the same as the ;/2 disjunction operator. At the top-level the ";" is just a switch to say "give me more"." I understand that's the experience of using it, but I mean if I open the SWI Prolog toplevel and query: ?- X = 1 ; X = 2.
Then press space, I get: X = 1 ;
X = 2.
which is exactly the same Prolog term, two unifications, each is a solution to the query, a disjunction between them, terminated with a full stop.Is that really not the same semicolon usage/meaning/semantics in the query as in the answers? |
|
All that'll probably get me lynched because it flies in the face of a lot of fudging perpetrated by Prolog courses and even some textbooks that should know better, and that tell you that e.g. a set of rules is like an if-then-else and that when you get more results at the top-level those are alternatives. That's just wrong and I don't know why people teach Prolog like this, all it does is confuse students and make them hate Prolog more, but the formal definition of a logic program is that it's a conjunction of definite program clauses; where a definite program clause is a ... clause, therefore a disjunction. So a logic program is a conjunction of disjunctions, i.e. basically a formula in conjunctive normal form.
So the ";" that appears automatically at the end of your query when you press space is not an "OR", otherwise it wouldn't appear when the results of the query are the members of a conjunction. What is it then?
Try this. Instead of pressing ";" after the first result of your query (after the X = 1) press "h" for "help". On SWI-Prolog you'll get this menu:
Thus finally* revealing the meaning of ";" at the top-level: it instructs the listener (i.e. the Prolog REPL) to enter the redo port. The ";" at the top-level means "redo" not "OR".And that's true even in your query which is explicitly formulated as a disjunction. With an ";". It's confusing.
_______________
* I know, sorry.