This has come up for me quite often -- it can be very frustrating:
this script clobbers the names (names escape the function's local scope):
Names Default to Here( 1 );
some expr = Expr(
a = 4;
b = 5;
g = 6;
);
f = Function( {input expr},
{Default Local},
Print( "running expr" );
input expr
);
f( Name Expr( some expr ) );
show( a, b, g )
Here is a solution, but the problem with this solution is that it is technically two function calls (counts as 2 stack items, thus will reach the 225 stack limit faster)
Names Default to Here( 1 );
some expr = Expr(
a = 4;
b = 5;
g = 6;
Show( Eval List( {a, b, g} ) );
);
f = Function( {input expr},
{Default Local},
Print( "running expr" );
Eval( Eval Expr(
Local( {Default Local},
Expr( Name Expr( input expr ) )
)
) );
1
);
f( Name Expr( some expr ) );
show( a, b, g )
It would be nice if the "Default Local" directive wasn't a parse time directive but a run time flag, but perhaps what is happening is that name-resolution is being performed at parse time, thus making run-time name lookup rules moot.
Jordan