[Openmcl-devel] Absolute beginner

mikel evins mevins at mac.com
Wed Apr 8 09:11:04 PDT 2009


On Apr 8, 2009, at 10:36 AM, Stephen Ng wrote:

> Hi!
>
> I am going through a tutorial on Lisp using Clozure CL and came across
> a warning message and wonder if someone can explain it to me -
>
> ? (setf bag 2)
> 2
> ? (dotimes (x 6) (setf bag (* bag bag)))
> ;Compiler warnings :
> ;   In an anonymous lambda form: Undeclared free variable BAG (3
> references)
> NIL
> ? bag
> 18446744073709551616


A variable whose definition isn't in the present scope is called a  
"free variable". For example, in

  (+ 2 j)

the j is a free variable. We can't tell from looking at that snippet  
alone whether j has a definition. In your example above, bag is a free  
variable. It so happens that in your code everything is fine, because  
you previously used SETF to establish a binding for bag in the  
enclosing scope, but the compiler can't tell that just from looking at  
the expression

   (dotimes (x 6) (setf bag (* bag bag)))

Since it can't tell just from looking at that expression whether you  
meant for bag to refer to something that was previously defined  
somewhere else, it warns you about the free variable. It goes ahead  
and compiles the code, and runs it just fine (because it so happened  
that there was an appropriate definition of bag in the enclosing  
scope), but in general the compiler can't know that, and it's pretty  
common that undeclared free variables are actually errors (typos, or  
accidental uses of variables that are out of scope, or other such  
mistakes), so when the compiler encounters you, it warns you before  
continuing, in case there's something you need to fix.

--me




More information about the Openmcl-devel mailing list