[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



is this check correct?:

No. you would have to check that the function referenced no variables in all enclosing contexts.


(
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