Login  Register

Re: How can I specify the bindings when evaluating an expression?

Posted by Nicolai Hess on Dec 06, 2014; 9:27pm
URL: https://forum.world.st/How-can-I-specify-the-bindings-when-evaluating-an-expression-tp4794352p4794477.html

2014-12-06 11:18 GMT+01:00 Marcus Denker <[hidden email]>:

> On 05 Dec 2014, at 15:18, stepharo <[hidden email]> wrote:
>
> I would like to be able to express
>
> Compiler new
>    bindings: { a -> 3. b -> 4};
>    evaluate: 'a + b';
>    result
> and get 7
>
> How can I do that?
>

Not directly, as evaluate is just a doit… but it can be added
as the machinery is there for evaluating in context in the debugger.

I will have a look but not this weekend.

        Marcus



The easiest solution I have found:

Smalltalk compiler evaluate:'a+b'
    notifying: (Dictionary newFrom:{ WorkspaceVariable key:#a value:3. WorkspaceVariable key:#b value:4})
    logged:nil

The dictionary is used as the receiver for the call to #bindingOf: and WorkspaceVariable acts like a LiteralVariable
that implements emitValue/emitStore



nicolai