[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-dev] closing a function
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?
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.
so after the compiler has done its work it would be possible to check
if there is any variable references into the context at compile time.
If there is none, the function is "closed" already and its sourceCode can be
stored.
So would it be possible to make a non closed function that has no
variable references into its context reproduce as compile string?
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
ok, so probably more like this?:
f = { var a = 1; { var b = 2; { { [a, b].postln; } }.value }.value }.value;
(
x = { arg func;
var d, l;
l = [];
d = func.def.context;
while { d.notNil } {
d = d.context;
if(d.notNil) { l = l ++ d.varNames };
};
l
};
)
f = { var a = 1; { var b = 2; { { [a, b].postln; } }.value }.value }.value;
x.value(f)
f = { var a = 1; #{ var b = 2; { { [a, b].postln; } }.value }.value }.value;
x.value(f)
f = #{ var a = 1; { var b = 2; { { [a, b].postln; } }.value }.value }.value;
x.value(f)
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
_______________________________________________
sc-dev mailing list
sc-dev@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-dev
--
.