When is 'require' required?
Posted: Sat Dec 25, 2010 10:11 pm
Hello all! I've been away from this board for some time. Last time, I was in the middle of learning lisp by reading PCL. I had gotten about 2/3 of the way through, before I realized that I didn't really like the style of the book. So I switched to Paul Graham's ACL, and worked through all the exercises in each chapter. For Lisp beginners, I think I would recommend ACL over PCL: ACL is written very well and could be used as a textbook for an introductory class, while PCL seems somewhat scattershot and unfocused with too much emphasis on explaining a large set of APIs.
Right now, I'm in the middle of reading On Lisp, which is a good book, but quite a bit dryer than ACL. The lack of exercises and practice problems really affects the exposition of the material. I'm also practicing writing some Cocoa programs in Lisp using Clozure's Cocoa bridge. Here, I've encountered a simple problem, which I can't seem to work around.
To get the Cocoa bridge working, when I start up Clozure, I first have to type
in my Clozure Listener at the toplevel prompt.
I then load and compile the source file helloworld.lisp which loads a Cocoa NIB file called hello.nib that I created using Interface Builder
and execute in the Listener
Suppose, though, I want to avoid having to type (require :nib) in the Listener, and somehow have that command get incorporated into the helloworld.lisp source file, so that I can simply load and compile helloworld.lisp in a single step, before executing (hello-world:main) in the Listener; how do I go about doing this?
If I leave out the (require :nib) altogether, then I get the error message:
Evidently, the NIB package contains the definitions for the iu:load-nibfile function and the like. I've tried including (require :nib) within the helloworld.lisp source file, before and also after the (defpackage :hello-world) specification, but I still get the same type of error message.
How should I organize my source files in lisp? Do I need defsystem or asdf-install to load in package prerequisites, or can this be done without these tools?
Right now, I'm in the middle of reading On Lisp, which is a good book, but quite a bit dryer than ACL. The lack of exercises and practice problems really affects the exposition of the material. I'm also practicing writing some Cocoa programs in Lisp using Clozure's Cocoa bridge. Here, I've encountered a simple problem, which I can't seem to work around.
To get the Cocoa bridge working, when I start up Clozure, I first have to type
Code: Select all
(require :nib)
I then load and compile the source file helloworld.lisp which loads a Cocoa NIB file called hello.nib that I created using Interface Builder
Code: Select all
(defpackage :hello-world
(:export main))
(in-package :hello-world)
(require :nib) ; Where does this go?
(defun main ()
(iu:load-nibfile (truename "ip:HelloWorld;hello.nib")))
Code: Select all
(hello-world:main)
If I leave out the (require :nib) altogether, then I get the error message:
Code: Select all
Read error between positions 83 and 124 in helloworld.lisp.
> Error: Reader error on #<BASIC-FILE-CHARACTER-INPUT-STREAM ("helloworld.lisp"/8 ISO-8859-1) #x302001546C3C>, near position 124, within " ()
> (iu:load-nibfi":
> Reference to unknown package "IU".
> While executing: CCL::SIGNAL-READER-ERROR, in process Listener(6).
> Type cmd-. to abort, cmd-\ for a list of available restarts.
> Type :? for other options.
1 >
How should I organize my source files in lisp? Do I need defsystem or asdf-install to load in package prerequisites, or can this be done without these tools?