[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] closing a function



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 Server


when 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?




 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?
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

--








.