From: jason
Subject: Toplevel equire - how does it work (SBCL)
Date: 
Message-ID: <1159289463.620137.61450@b28g2000cwb.googlegroups.com>
Hi,

I've got a question about the behaviour of require; I understand that
to use it with ASDF, it is common to  add hooks that let asdf find the
necessary package for the lisp.

What I don't understand is why require-ing asdf systems only seems to
work for me on the toplevel:

file a.lisp
-------------------
(require 'my-package)
....
-------------------

[this is what happens when I try to compile this file with SLIME
running SBCL]
-+  Errors (1)
 `-- READER-ERROR at 653 (line 29, column 17) on #<SB-SYS:FD-STREAM for
"file ~/a.lisp" {B0C3CC1}>:
     package "my-package" not found

If I do a (require 'my-package) on the toplevel, I get
; loading system definition from ....
NIL

and I'm able to use the package from there on.

What am I missing about require? I understand that it's a very
implementation-dependant facility, so I'll be satisfied with some
insight into how SBCL handles this, but any deeper insight would be
nice too.

Jason
From: Christophe Rhodes
Subject: Re: Toplevel equire - how does it work (SBCL)
Date: 
Message-ID: <sqlko64kr4.fsf@cam.ac.uk>
"jason" <···········@gmail.com> writes:

> What am I missing about require? 

REQUIRE is a function, so compiling a file with a call to REQUIRE at
its top-level has no particular effect, and specifically does not call
REQUIRE at compile-file time.  So if you have symbols later in the
file which are part of the required library, you will not compile them
properly.

The hacky solution is to wrap 
  (eval-when (:compile-toplevel :load-toplevel :execute) ...)
around your call to require, so that it will be called at compile-file
time as well as the usual load-fasl and load-source times; I would
recommend instead defining an asdf system for your code, and using
asdf's dependency mechanism to load your library for you.

Christophe