On Dec 18, 2004, at 2:32 AM, Julian Rohrhuber wrote:
On Dec 17, 2004, at 9:23 AM, Julian Rohrhuber wrote:would it be possible to close functions automatically when they can be closed?there are problems in doing so. functions must have some enclosing context. closed functions have as their enclosing context the interpreter object, not the lexically enclosing frame. closed functions can access the interpreter variables a-z.#{ s.postln }.value a Serverwhen the Function is created by the primitive, its current context is stored, be it the interpreter object or the enclosing function. at this point, shoulnd't be the information available whether the function could have been closed?
The instantiated frame of the enclosing lexical context is stored at runtime. But the compiler has already compiled all of the variable references into the code based on the lexical context that was in effect at compile time. It cannot be changed.
is this check correct?:No. you would have to check that the function referenced no variables in all enclosing contexts.what kind of function would have more than one enclosing contexts?
this one for example. your test fails on this:f = { var a = 1; { var b = 2; { { [a, b].postln; } }.value }.value }.value
x = { arg func; func.def.context.sourceCode.postln; func.def.context.varNames.isNil }; x.value(f) nil true
I've had the impression that the context encloses everything that is relevant already.( x = { arg func; func.def.context.sourceCode.postln; func.def.context.varNames.isNil }; ) // false ( var a = 4; f = { a + 5 }; x.value(f) ) // true ( f = { var a = 4; a + 5 }; x.value(f) ) // true ( f = { a + 5 }; x.value(f) ) // false ( { var b=9; var a = 4; f = { a + 5 + b }; }.value; x.value(f) ) -- . _______________________________________________ sc-dev mailing list sc-dev@xxxxxxxxxxxxxxx http://www.create.ucsb.edu/mailman/listinfo/sc-dev_______________________________________________ sc-dev mailing list sc-dev@xxxxxxxxxxxxxxx http://www.create.ucsb.edu/mailman/listinfo/sc-dev-- . _______________________________________________ sc-dev mailing list sc-dev@xxxxxxxxxxxxxxx http://www.create.ucsb.edu/mailman/listinfo/sc-dev