Functions suffer from the fact that they require lexically-scoped arguments to be supplied explicitly, and as we know today dynamic/global variables have many drawbacks. Context creation combines the two: Variables are not global and you don't have to supply them as arguments everywhere in your code.
Compile-time calculation can be used for everything from optimization to automatic code generation.
Examples:
- Anecdotes:
In some of my physics analysis code, I use functions which keep track of their dependencies and only run if necessary, i.e. if function-b calls function-a somewhere, then whenever function-a is set to re-run function-b automatically knows to re-run as well. This is useful when you have long chains of computation and update the data source at some point; you just specify the most basic function(s) which need re-running and call the master function, only the parts which need to be re-run are executed. This is a blend of compile-time calculation and optimization.
- Anaphoric macros
Like aif:
(defmacro aif (test then &optional else) `(let ((it ,test)) (if it ,then ,else)))
It violates referential transparency, but we gain in essence a new special term "it" which is bound to whatever the containing aif set it to. The fact that language has pronouns is a big hint that often times it's better to express ideas within a context than to insist that everything be understandable via substitution.
Example:
(aif (member x some-list) it (print "x is not in some-list"))
And you can do this for any conditional construct you can think of, e.g. awhen, acond, etc.
Another use for anaphoric macros: Ever wanted to write a recursive anonymous function but instead were forced to add a labels to your code? Try alambda:
(defmacro alambda (lambda-list &body body) `(labels ((self ,lambda-list ,@body)) #'self))
If you make heavy use of functions then you probably are prone to using recursion, so alambda may find quite a few good uses.
Let Over Lambda has even more examples (these are from On Lisp), but I won't bog down the page with them.
Gary Hollis