quek / paiprolog

forked Christophe Rhodes's PAIProlog that an update of Peter Norvig's "Prolog in Common Lisp".
Other
18 stars 6 forks source link

Example from PAIP not working #19

Open psilord opened 4 years ago

psilord commented 4 years ago

Hello,

I'm trying to use paiprolog for something, but have run into this issue:

Suppose we do this:

Linux violet > rlwrap ecl
;;; Loading "/home/psilord/quicklisp/setup.lisp"
;;; Loading #P"/usr/local/lib/ecl-16.1.3/asdf.fas"
ECL (Embeddable Common-Lisp) 16.1.3 (git:e3b9919ffaddbeb8d5f16c394fb70b813c5f0d94)
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
Copyright (C) 2016 Daniel Kochmanski
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.  
Top level in: #<process TOP-LEVEL 0x230af80>.
> (ql:quickload :paiprolog)
To load "paiprolog":
  Load 1 ASDF system:
    paiprolog
; Loading "paiprolog"

(:PAIPROLOG)
> (in-package :paiprolog)

#<"PAIPROLOG" package>
(<- (likes Kim Robin))

LIKES
(<- (likes Sandy Lee))

LIKES
(<- (likes Sandy Kim))

LIKES
(<- (likes Robin cats))

LIKES
(<- (likes Sandy ?x) (likes ?x cats))

LIKES
(<- (likes Kim ?x) (likes ?x Lee) (likes ?x Kim))

LIKES
PAIPROLOG> (<- (likes ?x ?x))

LIKES

Now here is what happens when we run this:

PAIPROLOG> (prove-all '((likes sandy ?who)) no-bindings)

((?WHO . LEE))

But what I'm expecting is an output that looks something like this:

(((?WHO . LEE))
  ((?WHO . KIM))
  ((?X2856 . ROBIN) (?WHO .?X2856))
  ((?X2860 . CATS) (?X2857 CATS) (?X2856 . SANDY) (?WHO ?X2856)
  ((?X2865 . CATS) (?X2856 ?X2865)((?WHO . ?X2856))
  (?WHO . SANDY) (?X2867 . SANDY)))

Any idea why I'm only getting a SINGLE result?

Thank you!

psilord commented 4 years ago

Well, I have new information.

If we do this:

* (ql:quickload :paiprolog) (in-package :paiprolog)
To load "paiprolog":
  Load 1 ASDF system:
    paiprolog
; Loading "paiprolog"

(:PAIPROLOG)
* #<PACKAGE "PAIPROLOG">
* (<- (likes a b)) (<- (likes a c)) (<- (likes a f))
LIKES
* LIKES
* LIKES
* (prolog-collect (?x) (likes sandy ?x))
NIL
* (prolog-collect (?x) (likes a ?x))
(F C B)

Than I get more of what I expect. So, in terms of me needing all solutions to a query, this solves my issue.

I was just surprised cause this doesn't appear to be a construct in PAIP's chapter 11.

Thank you.