clasp-developers / clasp

clasp Common Lisp environment
https://clasp-developers.github.io/
2.54k stars 142 forks source link

Differing behavior in ASDF-loaded vs interactively compiled function accessing constant #1580

Open paulapatience opened 1 month ago

paulapatience commented 1 month ago

After loading the clasp-table-bug system provided below, calling (gethash-table "a") returns NIL instead of 0, but after compiling the function interactively, it behaves correctly.

cat >clasp-table-bug.asd <<EOF
(defsystem "clasp-table-bug"
  :depends-on ("alexandria" "shasht")
  :components ((:file "clasp-table-bug")))
EOF

cat >clasp-table-bug.lisp <<EOF
(uiop:define-package #:clasp-table-bug
  (:use #:common-lisp))
(in-package #:clasp-table-bug)

;; With DEFPARAMETER, it works.
(alexandria:define-constant +table+
  ;; With this, it works.
  #+(or)
  (alexandria:plist-hash-table (list "a" 0) :test 'equal)
  (shasht:read-json "{\"a\":0}")
  :test 'equalp)

(defun gethash-table (name)
  (gethash name +table+))

;; This returns NIL at first, until you recompile the function
#+(or)
(gethash-table "a")

;; This returns the right thing
#+(or)
(gethash "a" +table+)
EOF

The system depends on Alexandria and shasht.