Hi all,
I want to do something like this:
var vx = 3;
var vy = 9;
("vx + vy").interpret
…but I’m not sure how to inject the values into the interpreting process. Any ideas?
Hi all,
I want to do something like this:
var vx = 3;
var vy = 9;
("vx + vy").interpret
…but I’m not sure how to inject the values into the interpreting process. Any ideas?
Local variables exist only within their “compilation context.” .interpret
is a new, separate compilation context. So what you’re thinking is not possible.
However I think this might work:
var vx = 3;
var vy = 9;
("{ |vx, vy| vx + vy }").interpret.value(vx, vy);
Or use environment variables, which exist in a collection rather than in a “context.”
// use-ing a new environment preserves locality
Environment.new.use {
~vx = 3;
~vy = 9;
("~vx + ~vy").interpret;
}
hjh
Interesting! That’s exactly the kind of thing I was looking for; I think it might work for what I’m trying to do.