Page 1 of 1

REPL prompt (package) doesn't change after loading file

Posted: Tue Mar 23, 2010 10:02 am
by biturika
Hi,

This is my first post and probably a dumb question. First I probably should give you some background.

I've managed to install Clozure Common Lisp on Ubuntu, and get Slime working with Emacs. I've been using the book Practical Common Lisp to try to learn Common Lisp. I'm only in chapter three and things have been going fine. I peaked ahead to the chapter on packages though.

I've used defpackage and in-package successfully at the REPL, but when I add the same to a file and then load the file, I assumed this would have the same affect as just typing the commands into the REPL, i.e., changing the prompt. After loading the file though, the prompt is the same. Nonetheless I can still access functions I defined in the file. So I'm just confused about why the package / prompt didn't change when manipulated from the file rather than the REPL directly.

Below is the code, stored in a filename.lisp file, which I am loading using (load (compile-file "filename.lisp"))

Code: Select all

(in-package :cl-user)

	(defpackage :praktikul
	  (:use :cl))

	(in-package :praktikul)

	(defun make-cd (title artist rating ripped)
	  (list :title title :artist artist :rating rating :ripped ripped))

	(defvar *db* nil)

	(defun add-record (cd)
	  (push cd *db*))

	(defun prompt-read (prompt)
	  (format *query-io* "~a: " prompt)
	  (force-output *query-io*)
	  (read-line *query-io*))

	(defun prompt-for-cd ()
	   (make-cd
	    (prompt-read "Title")
	    (prompt-read "Artist")
	    (or
	     (parse-integer
	      (prompt-read "Rating")
	      :junk-allowed t)
	     0)
	    (y-or-n-p "Ripped [y/n]: ")))

	(defun add-cds ()
	  (loop (add-record (prompt-for-cd))
	     (if (not (y-or-n-p "Another? [y/n]: ")) (return))))

	(defun dump-db ()
	  (dolist (cd *db*)
	    (format t "~{~a:~10t~a~%~}~%" cd)))

	(defun save-db (filename)
	  (with-open-file (out filename
		           :direction :output
		           :if-exists :supersede)
	    (with-standard-io-syntax
	      (print *db* out))))
Thank you for any feedback.

Re: REPL prompt (package) doesn't change after loading file

Posted: Tue Mar 23, 2010 11:39 am
by ramarren
As the specification for LOAD says:
load binds *readtable* and *package* to the values they held before loading the file.

Re: REPL prompt (package) doesn't change after loading file

Posted: Tue Mar 23, 2010 1:52 pm
by biturika
Ok then, I see it's doing what it is supposed to do. Good to know.

Thanks