First, I am very new to lisp, so it is possible that I'm just missing something very obvious. That said, I have Practical Common Lisp open next to me and the CL Hyper Spec open in the next tab, and have been unable to solve this issue:
I am trying to read a tree from a file, and assign values to slots in a class using this code:
(defun load-char (file)
(with-open-file (in file)
(with-standard-io-syntax
(let ((chr-in (read in))
(chr (make-instance 'pc)))
(mapcar #'(lambda (x) (setf (slot-value chr (car x)) (cdr x))) chr-in)
chr))))
When I originally hacked this together and ran it under the cl-user package everything worked perfectly -- I was quite proud of myself, actually. The problem started when I packaged this along with my class definition and a few helper functions in a new package. I loaded the package using asdf, then used (in-package :package-name)
to change my REPL's active package.
Now when I run (load-char "/path/to/file")
I get an error that says the COMMON-LISP-USER::ID
(ID is the first slot in my pc class) does not exist, so I wrote this to see what I was actually getting when I read the file in:
(defun load-char-test (file)
(with-open-file (in file)
(with-standard-io-syntax
(let ((chr-in (read in))
(chr (make-hash-table)))
(mapcar #'(lambda (x) (setf (gethash (car x) chr) (cdr x))) chr-in)
(maphash #'(lambda (k v) (format t "~a: ~a~%" k v)) chr)
chr))))
Then in the REPL I do (defparameter hsh (load-char-test "/path/to/file"))
and everything goes without errors, and my format call returns exactly what I expect (SLOT: VALUE). But when I do a (gethash 'id hsh)
it returns NIL NIL
. But, when I do (gethash 'common-lisp-user::id hsh)
it returns the expected value.
So, I'm reading in everything just fine, but everything in my list is being interned under the COMMON-LISP-USER package instead of the one I defined, and I cannot figure out why. Help is greatly appreciated.
P.S. Sorry if this post is needlessly long, I just wanted to show that I had actually tried to figure this out myself.