Today I read up to the section "Dynamic, a.k.a. Special, Variables" of Chapter 6 of Practical Common Lisp. Here are some thing I learned:
-
Lexical and dynamic variables are supported. These two roughly map to the concepts of local and global variables (respectively) in other languages.
-
CL is dynamically and strongly typed.
-
The scope of a variable in Lisp is within the form in which it's binded. That form is aptly called the binding form.
-
let*
allows you to use the value of one variable declared in the let statement as part of the value of the other variables that come after it. Someone pointed this out the other day as well. This solves the problem I was having a few days ago with the tip calculator program. Maybe I'll fix it as part of my Lisp work tomorrow. -
Lexical scoping is a bit different in Lisp compared to, say, Java. You can persist the value of a variable past its scope with a closure. Or, rather, the binding of that variable to some object. Because it's the binding that's persisted, you can alter the value of the variable. You can also have multiple closures over a single variable binding or a single closure over multiple variable bindings.
The idea of a closure seems pretty interesting. I don't think I've encountered anything like it before. If I'm not mistaken, a closure allows you to kind of have a "limited" global variable in the sense that it may have started out as a local variable, but now you can access it through the closure even after you're way beyond the death of the scope of that variable. It's grandfathering in a local variable from another scope, but not completely.