Open pnathan opened 10 years ago
I don't know why, but on ABCL bound-p
returns T
for unbound variable created by (?)
.
If you re-evaluate the definition of bound-p
in REPL, this (bound-p's) problem disappears.
PAIPROLOG> (lisp-implementation-version)
"1.3.1"
"Java_HotSpot(TM)_Client_VM-Oracle_Corporation-1.8.0_20-b26"
"x86-Windows_XP-5.1"
PAIPROLOG> (<- (p 1))
P
PAIPROLOG> (?- (p ?x))
No.
; No value
PAIPROLOG> (bound-p (?))
T
PAIPROLOG> (defun bound-p (var) (not (eq (var-binding var) unbound))) ;; from prologc.lisp
STYLE-WARNING: redefining BOUND-P at top level
BOUND-P
PAIPROLOG> (bound-p (?))
NIL
PAIPROLOG> (?- (p ?x))
?X = 1;
No.
; No value
PAIPROLOG>
When you embed debugging code in bound-p, problem becomes apparent .
;;; prologcp.lisp
(defun bound-p (var)
(print-unreadable-object ((var-binding var) t :identity t :type t))
(terpri)
(print-unreadable-object (unbound t :identity t :type t))
(not (eq (var-binding var) unbound)))
PAIPROLOG> (bound-p (?))
#<(SIMPLE-BASE-STRING 7) {165B2C7}>
#<(SIMPLE-BASE-STRING 7) {184CA5F}>
T
PAIPROLOG>
Changing (defconstant unbound ...)
to (defvar unbound ...)
in prologc.lisp might be a workaround for this problem.
This is a simplified test case to show this workaround.
;;; test-bound-p.lisp
#-ABCL
(defconstant unbound "Unbound")
#+ABCL
(defvar unbound "Unbound") ;; workaround for ABCL
(defstruct var
(binding unbound))
(defun bound-p (var)
(print-unreadable-object ((var-binding var) t :identity t :type t))
(terpri)
(print-unreadable-object (unbound t :identity t :type t))
(not (eq (var-binding var) unbound)))
(defun run ()
(print (bound-p (make-var))))
CL-USER> (compile-file "./test-bound-p.lisp")
; Compiling C:/lispbox-0.7/quicklisp/local-projects/paiprolog/test-bound-p.lisp ...
; (DEFVAR UNBOUND ...)
; (DEFSTRUCT VAR ...)
; (DEFUN BOUND-P ...)
; (DEFUN RUN ...)
; Wrote c:/lispbox-0.7/quicklisp/local-projects/paiprolog/./test-bound-p.abcl (0.701 seconds)
#P"C:/lispbox-0.7/quicklisp/local-projects/paiprolog/test-bound-p.abcl"
NIL
NIL
CL-USER> (run)
; Evaluation aborted on #<UNDEFINED-FUNCTION {6BE0B7}>.
CL-USER> (load "./test-bound-p.abcl")
T
CL-USER> (run)
#<(SIMPLE-BASE-STRING 7) {1596BBE}>
#<(SIMPLE-BASE-STRING 7) {1596BBE}>
NIL
NIL
CL-USER> (lisp-implementation-version)
"1.3.3"
"Java_HotSpot(TM)_Client_VM-Oracle_Corporation-1.8.0_20-b26"
"x86-Windows_XP-5.1"
CL-USER>
https://github.com/quek/paiprolog/pull/10 Dose this fix the problem?
No it doesn't. The patch below works for me.
uchita-akiko-no-macbook-2:paiprolog uchidamasako$ git diff
diff --git a/prologc.lisp b/prologc.lisp
index d44b203..2e667b3 100644
--- a/prologc.lisp
+++ b/prologc.lisp
@@ -7,11 +7,16 @@
(in-package "PAIPROLOG")
-
+#-ABCL
(defconstant unbound (if (boundp 'unbound)
(symbol-value 'unbound)
"Unbound"))
+#+ABCL
+(defvar unbound (if (boundp 'unbound)
+ (symbol-value 'unbound)
+ "Unbound"))
+
(defvar *var-counter* 0)
(defstruct (var (:constructor ? ())
uchita-akiko-no-macbook-2:paiprolog uchidamasako$
Using latest version in Quicklisp:
I've tested this on SBCL and it works there. Not sure if there is compiler-specific code in the codebase; if not, I'll go take it over to the ABCL mailing list.