How can I specify the bindings when evaluating an expression?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I specify the bindings when evaluating an expression?

stepharo
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?

Stef

Reply | Threaded
Open this post in threaded view
|

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

Marcus Denker-4

> 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


Reply | Threaded
Open this post in threaded view
|

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

Nicolai Hess
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


Reply | Threaded
Open this post in threaded view
|

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

stepharo
In reply to this post by Marcus Denker-4
Marcus

could you add this issue somewhere because this is something that I'm
expected from a compiler

Stef
Le 6/12/14 11:18, Marcus Denker a écrit :

>> 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
>
>
>


Reply | Threaded
Open this post in threaded view
|

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

Marcus Denker-4

> On 23 Dec 2014, at 09:45, stepharo <[hidden email]> wrote:
>
> Marcus
>
> could you add this issue somewhere because this is something that I'm expected from a compiler
>

Yes… I will check. Right now the API is too much focused on implementation artefacts vs. concepts.
(requestor vs. binding, for example).

In general, we need to do a *real* pass over the API of the compiler.
But we can only do that after we remove the old one…

        Marcus

> Stef
> Le 6/12/14 11:18, Marcus Denker a écrit :
>>> 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
>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

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

Sean P. DeNigris
Administrator
In reply to this post by Nicolai Hess
Nicolai Hess wrote
Dictionary newFrom:{ WorkspaceVariable key:#a value:3.
WorkspaceVariable key:#b value:4}
Thanks! That works great :)

n.b. in Pharo 3.0, just replace the WorkspaceVariables with regular associations:
  Smalltalk compiler evaluate:'a+b'
    notifying: (Dictionary newFrom: { #a -> 3. #b -> 4 })
    logged: nil
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

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

Nicolai Hess


2015-02-04 23:07 GMT+01:00 Sean P. DeNigris <[hidden email]>:
Nicolai Hess wrote
> Dictionary newFrom:{ WorkspaceVariable key:#a value:3.
> WorkspaceVariable key:#b value:4}

Thanks! That works great :)

n.b. in Pharo 3.0, just replace the WorkspaceVariables with regular
associations:
  Smalltalk compiler evaluate:'a+b'
    notifying: (Dictionary newFrom: { #a -> 3. #b -> 4 })
    logged: nil

That's interesting. We lost this feature in 40097
(13584 Forward code generation for Globals and Class Vars to meta object)


 



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/How-can-I-specify-the-bindings-when-evaluating-an-expression-tp4794352p4803777.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

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

Sean P. DeNigris
Administrator
Nicolai Hess wrote
We lost this feature in 40097
Which feature? Using bare associations instead of WorkspaceVariables?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

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

Nicolai Hess


2015-02-05 2:20 GMT+01:00 Sean P. DeNigris <[hidden email]>:
Nicolai Hess wrote
> We lost this feature in 40097

Which feature? Using bare associations instead of WorkspaceVariables?

Yes, maybe feature is the wrong word - ability?
What is missing now is, convert an association into a "VariableBinding"
similiar to WorkspaceVariable or GlobalVariable, that implements the code generation methods
emitStore: and emitValue:


 



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/How-can-I-specify-the-bindings-when-evaluating-an-expression-tp4794352p4803810.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

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

Marcus Denker-4

On 05 Feb 2015, at 10:09, Nicolai Hess <[hidden email]> wrote:



2015-02-05 2:20 GMT+01:00 Sean P. DeNigris <[hidden email]>:
Nicolai Hess wrote
> We lost this feature in 40097

Which feature? Using bare associations instead of WorkspaceVariables?

Yes, maybe feature is the wrong word - ability?
What is missing now is, convert an association into a "VariableBinding"
similiar to WorkspaceVariable or GlobalVariable, that implements the code generation methods
emitStore: and emitValue:

yes, we could move it up to Association… but we should keep VariableBinding as a subclass of
Literal so that people in the future e.g. can put a halt on a variable defined in the
workspace.

And yes, in general we need a nice API for the compiler to hand bindings to it… it is on my TODO
list.

Marcus
Reply | Threaded
Open this post in threaded view
|

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

Marcus Denker-4

yes, we could move it up to Association… but we should keep VariableBinding as a subclass of
Literal so that people in the future e.g. can put a halt on a variable defined in the
workspace.

And yes, in general we need a nice API for the compiler to hand bindings to it… it is on my TODO
list.


This Slice adds an API to the compiler to set a dictionary with bindings to be taken into account.
They are compiled as pushLinteralVariable: (thus refer to the association of the dictionary)

Smalltalk compiler
        bindings: { #a -> 3 } asDictionary;
        evaluate: '1+a'.

Internally this for now (ab)-uses the #requestor: API... later we will change this to be inverted: the requestors
should privide binding and get notified using Announcements.





Reply | Threaded
Open this post in threaded view
|

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

Marcus Denker-4

On 05 May 2015, at 13:39, Marcus Denker <[hidden email]> wrote:


yes, we could move it up to Association… but we should keep VariableBinding as a subclass of
Literal so that people in the future e.g. can put a halt on a variable defined in the
workspace.

And yes, in general we need a nice API for the compiler to hand bindings to it… it is on my TODO
list.


This Slice adds an API to the compiler to set a dictionary with bindings to be taken into account.
They are compiled as pushLinteralVariable: (thus refer to the association of the dictionary)

Smalltalk compiler
        bindings: { #a -> 3 } asDictionary;
        evaluate: '1+a’.

This is now in Pharo5 update #032

Marcus


Reply | Threaded
Open this post in threaded view
|

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

Thierry Goubier


2015-05-05 15:17 GMT+02:00 Marcus Denker <[hidden email]>:

On 05 May 2015, at 13:39, Marcus Denker <[hidden email]> wrote:


yes, we could move it up to Association… but we should keep VariableBinding as a subclass of
Literal so that people in the future e.g. can put a halt on a variable defined in the
workspace.

And yes, in general we need a nice API for the compiler to hand bindings to it… it is on my TODO
list.


This Slice adds an API to the compiler to set a dictionary with bindings to be taken into account.
They are compiled as pushLinteralVariable: (thus refer to the association of the dictionary)

Smalltalk compiler
        bindings: { #a -> 3 } asDictionary;
        evaluate: '1+a’.

This is now in Pharo5 update #032

Thanks Marcus, this should be very convenient.

Thierry
 

Marcus



Reply | Threaded
Open this post in threaded view
|

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

Sean P. DeNigris
Administrator
In reply to this post by Marcus Denker-4
Marcus Denker-4 wrote
> Smalltalk compiler
>         bindings: { #a -> 3 } asDictionary;
>         evaluate: '1+a’.

This is now in Pharo5 update #032
Cool :)
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

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

stepharo
In reply to this post by Marcus Denker-4
Nice :)


This Slice adds an API to the compiler to set a dictionary with bindings to be taken into account.
They are compiled as pushLinteralVariable: (thus refer to the association of the dictionary)

Smalltalk compiler
        bindings: { #a -> 3 } asDictionary;
        evaluate: '1+a'.

Internally this for now (ab)-uses the #requestor: API... later we will change this to be inverted: the requestors
should privide binding and get notified using Announcements.