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

Discussion of Common Lisp
Post Reply
biturika
Posts: 4
Joined: Tue Mar 23, 2010 9:47 am

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

Post by biturika » Tue Mar 23, 2010 10:02 am

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.

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

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

Post by ramarren » Tue Mar 23, 2010 11:39 am

As the specification for LOAD says:
load binds *readtable* and *package* to the values they held before loading the file.

biturika
Posts: 4
Joined: Tue Mar 23, 2010 9:47 am

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

Post by biturika » Tue Mar 23, 2010 1:52 pm

Ok then, I see it's doing what it is supposed to do. Good to know.

Thanks

Post Reply