BookmarkSubscribeRSS Feed
vince_faller

Super User

Joined:

Mar 17, 2015

Get all variables and values from an expression.

I'm trying to get all of the variables inside of any expression (so I can't explicitly scope inside of it) like so: 

 

Names default to here(1);
some_f = function({x}, 
	{c}, 
	c=1;
	return(x);
);
some_expr = Expr(
	a=1;
	//b = some_f(1);
);

//trying to get all the variables inside some_expr
Eval(Substitute(
	Expr(
		local here(
			DV_EXPR;
			associative array(namespace("here") << Get Contents);
		)
	), 
	Expr(DV_EXPR), nameexpr(some_expr)
));

Now that works great until uncomment that function call inside the expression.  

Then I run into a problem like this one. 

 

b = 2;
y = Local Here(
	a = 1;
	c = a + b;
	c;
);

Can anyone think of a better way to do this?  Or of a way to make sure that my local here can see names outside of itself WITHOUT putting them in the local here namespace? I've also tried just local(). But because of the way {DEFAULT LOCAL} works, no love.  Tried UsingNamespace() as well but I'm pretty sure it's not working.