On Feb 5, 2009, at 5:24 PM, David Wingate wrote:
I think I'm more confused than ever. The following fails: (define (foo a) (lambda () a )) (define bar (foo 42)) (serialize bar) because "a" is a free variable. Fair enough. If we expand the syntatic sugar for the definition of foo, the following also fails: (define foo (lambda (a) (lambda () a ) ) ) (define bar (foo 42)) (serialize bar) No problem -- it's equivalent to the first. But now if we inline the definition of foo, it succeeds: (define bar ((lambda (a) (lambda () a ) ) 42) ) (serialize bar) I suppose this is because ikarus somehow is able to optimize the final expression, "noticing" that the expression simplifies to (lambda () 42), and no free variables exist. And I furthermore suppose that such an optimization is not possible in the former cases.
This is all correct. Also, the previous example from Andreas: (let ((foo 42)) (lambda () foo)) is optimized to be (lambda () 42) which has no free variables even though the source lambda has one free variable. The procedure command-line-arguments is a "parameter" and the implementation of parameters has to be a closure over a mutable slot in which the parameter value is stored.
Is there a general technique for eliminating free variables in these sorts of expressions?
You cannot eliminate them completely; you can only disguise them in other forms (like keeping the free variables separate from the procedure and passing them to the procedure along with the remaining parameters). I general, I would recommend against that. Aziz,,,
