accessing local/instance variables with metalinks

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

accessing local/instance variables with metalinks

Peter Uhnak
Hi,

what is the best way to access variables from within a metalink?

for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.

I can use #instVarNamed:

```
MetaLink new
        metaObject: [ :object |
                (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
        ];
        selector: #value:;
        arguments: #(object);
        control: #instead.
```

but the above isn't exactly nice, plus it wouldn't work with temporary variables.

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Marcus Denker-4
Hello,

Not yet. It should be easy to add if we find a good API for it…

I will work on it this week (I have blocked some time for RF related hacking).

e.g I think we have to extend the syntax for reifications to use classes.

something like:

arguments: {RFTempReification named: #trachelCanvas};

The current symbols then would be the same as using

RFReification named: #object

But subclasses can be used directly and parametrized.

        Marcus

> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>
> Hi,
>
> what is the best way to access variables from within a metalink?
>
> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>
> I can use #instVarNamed:
>
> ```
> MetaLink new
> metaObject: [ :object |
> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
> ];
> selector: #value:;
> arguments: #(object);
> control: #instead.
> ```
>
> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>
> Thanks,
> Peter
>


Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Uko2
By the way, we need to add a rubric highlighting to the classes somehow :).

Uko



> On 12 Dec 2016, at 13:36, Marcus Denker <[hidden email]> wrote:
>
> Hello,
>
> Not yet. It should be easy to add if we find a good API for it…
>
> I will work on it this week (I have blocked some time for RF related hacking).
>
> e.g I think we have to extend the syntax for reifications to use classes.
>
> something like:
>
> arguments: {RFTempReification named: #trachelCanvas};
>
> The current symbols then would be the same as using
>
> RFReification named: #object
>
> But subclasses can be used directly and parametrized.
>
> Marcus
>
>> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>>
>> Hi,
>>
>> what is the best way to access variables from within a metalink?
>>
>> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>>
>> I can use #instVarNamed:
>>
>> ```
>> MetaLink new
>> metaObject: [ :object |
>> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
>> ];
>> selector: #value:;
>> arguments: #(object);
>> control: #instead.
>> ```
>>
>> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>>
>> Thanks,
>> Peter
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Marcus Denker-4
There is a MetalinkIconStyler already.

But I think that it is better to have stylers for the users of metalinks, e.g. there is a special
styler for breakpoints.

I see the general styler more as a debug tool (it is off by default).
       
        Marcus

> On 14 Dec 2016, at 05:10, Yuriy Tymchuk <[hidden email]> wrote:
>
> By the way, we need to add a rubric highlighting to the classes somehow :).
>
> Uko
>
>
>
>> On 12 Dec 2016, at 13:36, Marcus Denker <[hidden email]> wrote:
>>
>> Hello,
>>
>> Not yet. It should be easy to add if we find a good API for it…
>>
>> I will work on it this week (I have blocked some time for RF related hacking).
>>
>> e.g I think we have to extend the syntax for reifications to use classes.
>>
>> something like:
>>
>> arguments: {RFTempReification named: #trachelCanvas};
>>
>> The current symbols then would be the same as using
>>
>> RFReification named: #object
>>
>> But subclasses can be used directly and parametrized.
>>
>> Marcus
>>
>>> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>>>
>>> Hi,
>>>
>>> what is the best way to access variables from within a metalink?
>>>
>>> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>>>
>>> I can use #instVarNamed:
>>>
>>> ```
>>> MetaLink new
>>> metaObject: [ :object |
>>> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
>>> ];
>>> selector: #value:;
>>> arguments: #(object);
>>> control: #instead.
>>> ```
>>>
>>> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>>>
>>> Thanks,
>>> Peter
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Uko2
Ah, looks like I didn’t read the topic correctly… I’d like to have styling for the class template, because it is a bit complicated to highlight variables.

Uko

> On 14 Dec 2016, at 12:44, Marcus Denker <[hidden email]> wrote:
>
> There is a MetalinkIconStyler already.
>
> But I think that it is better to have stylers for the users of metalinks, e.g. there is a special
> styler for breakpoints.
>
> I see the general styler more as a debug tool (it is off by default).
>
> Marcus
>> On 14 Dec 2016, at 05:10, Yuriy Tymchuk <[hidden email]> wrote:
>>
>> By the way, we need to add a rubric highlighting to the classes somehow :).
>>
>> Uko
>>
>>
>>
>>> On 12 Dec 2016, at 13:36, Marcus Denker <[hidden email]> wrote:
>>>
>>> Hello,
>>>
>>> Not yet. It should be easy to add if we find a good API for it…
>>>
>>> I will work on it this week (I have blocked some time for RF related hacking).
>>>
>>> e.g I think we have to extend the syntax for reifications to use classes.
>>>
>>> something like:
>>>
>>> arguments: {RFTempReification named: #trachelCanvas};
>>>
>>> The current symbols then would be the same as using
>>>
>>> RFReification named: #object
>>>
>>> But subclasses can be used directly and parametrized.
>>>
>>> Marcus
>>>
>>>> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> what is the best way to access variables from within a metalink?
>>>>
>>>> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>>>>
>>>> I can use #instVarNamed:
>>>>
>>>> ```
>>>> MetaLink new
>>>> metaObject: [ :object |
>>>> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
>>>> ];
>>>> selector: #value:;
>>>> arguments: #(object);
>>>> control: #instead.
>>>> ```
>>>>
>>>> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>>>>
>>>> Thanks,
>>>> Peter
>>>>
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Marcus Denker-4
Ah, yes. And context menus…

> On 14 Dec 2016, at 10:46, Yuriy Tymchuk <[hidden email]> wrote:
>
> Ah, looks like I didn’t read the topic correctly… I’d like to have styling for the class template, because it is a bit complicated to highlight variables.
>
> Uko
>
>> On 14 Dec 2016, at 12:44, Marcus Denker <[hidden email]> wrote:
>>
>> There is a MetalinkIconStyler already.
>>
>> But I think that it is better to have stylers for the users of metalinks, e.g. there is a special
>> styler for breakpoints.
>>
>> I see the general styler more as a debug tool (it is off by default).
>>
>> Marcus
>>> On 14 Dec 2016, at 05:10, Yuriy Tymchuk <[hidden email]> wrote:
>>>
>>> By the way, we need to add a rubric highlighting to the classes somehow :).
>>>
>>> Uko
>>>
>>>
>>>
>>>> On 12 Dec 2016, at 13:36, Marcus Denker <[hidden email]> wrote:
>>>>
>>>> Hello,
>>>>
>>>> Not yet. It should be easy to add if we find a good API for it…
>>>>
>>>> I will work on it this week (I have blocked some time for RF related hacking).
>>>>
>>>> e.g I think we have to extend the syntax for reifications to use classes.
>>>>
>>>> something like:
>>>>
>>>> arguments: {RFTempReification named: #trachelCanvas};
>>>>
>>>> The current symbols then would be the same as using
>>>>
>>>> RFReification named: #object
>>>>
>>>> But subclasses can be used directly and parametrized.
>>>>
>>>> Marcus
>>>>
>>>>> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> what is the best way to access variables from within a metalink?
>>>>>
>>>>> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>>>>>
>>>>> I can use #instVarNamed:
>>>>>
>>>>> ```
>>>>> MetaLink new
>>>>> metaObject: [ :object |
>>>>> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
>>>>> ];
>>>>> selector: #value:;
>>>>> arguments: #(object);
>>>>> control: #instead.
>>>>> ```
>>>>>
>>>>> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>>>>>
>>>>> Thanks,
>>>>> Peter
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Marcus Denker-4
In reply to this post by Marcus Denker-4
Hi,

I think I found a simple solution: the ability to reference any variable.
https://pharo.fogbugz.com/f/cases/19467/Metalinks-support-accessing-variables-for-arguments

This test shows how to use it for a temp:

testAccessTemp
        | varNode instance |
        varNode := (ReflectivityExamples>>#exampleAssignment) ast body statements second.
        link := MetaLink new
                metaObject: self;
                selector: #tagExec:;
                arguments: {RBVariableNode named: #temp}.
        varNode link: link.
        self assert: varNode hasMetalink.
        self assert: (tag isNil).
        instance := ReflectivityExamples new .
        self assert: (instance exampleAssignment = 3).
        self assert: (tag = 3).

I have not yet tested it for any other example, but it should work for your case, too, which would look
like this:

MetaLink new
        metaObject: [ :surface :trachelCanvas |
                surface clear: trachelCanvas color.
        ];
        selector: #value:value:;
        arguments:  {RBVariableNode named: #surface . RBVariableNode named: #trachelCanvas }.
        control: #instead.



> On 12 Dec 2016, at 09:36, Marcus Denker <[hidden email]> wrote:
>
> Hello,
>
> Not yet. It should be easy to add if we find a good API for it…
>
> I will work on it this week (I have blocked some time for RF related hacking).
>
> e.g I think we have to extend the syntax for reifications to use classes.
>
> something like:
>
> arguments: {RFTempReification named: #trachelCanvas};
>
> The current symbols then would be the same as using
>
> RFReification named: #object
>
> But subclasses can be used directly and parametrized.
>
> Marcus
>
>> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>>
>> Hi,
>>
>> what is the best way to access variables from within a metalink?
>>
>> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>>
>> I can use #instVarNamed:
>>
>> ```
>> MetaLink new
>> metaObject: [ :object |
>> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
>> ];
>> selector: #value:;
>> arguments: #(object);
>> control: #instead.
>> ```
>>
>> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>>
>> Thanks,
>> Peter
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: accessing local/instance variables with metalinks

Marcus Denker-4
In reply to this post by Marcus Denker-4
Hi,

I think I found a simple solution: the ability to reference any variable.
https://pharo.fogbugz.com/f/cases/19467/Metalinks-support-accessing-variables-for-arguments

This test shows how to use it for a temp:

testAccessTemp
        | varNode instance |
        varNode := (ReflectivityExamples>>#exampleAssignment) ast body statements second.
        link := MetaLink new
                metaObject: self;
                selector: #tagExec:;
                arguments: {RBVariableNode named: #temp}.
        varNode link: link.
        self assert: varNode hasMetalink.
        self assert: (tag isNil).
        instance := ReflectivityExamples new .
        self assert: (instance exampleAssignment = 3).
        self assert: (tag = 3).

I have not yet tested it for any other example, but it should work for your case, too, which would look
like this:

MetaLink new
        metaObject: [ :surface :trachelCanvas |
                surface clear: trachelCanvas color.
        ];
        selector: #value:value:;
        arguments:  {RBVariableNode named: #surface . RBVariableNode named: #trachelCanvas }.
        control: #instead.



> On 12 Dec 2016, at 09:36, Marcus Denker <[hidden email]> wrote:
>
> Hello,
>
> Not yet. It should be easy to add if we find a good API for it…
>
> I will work on it this week (I have blocked some time for RF related hacking).
>
> e.g I think we have to extend the syntax for reifications to use classes.
>
> something like:
>
> arguments: {RFTempReification named: #trachelCanvas};
>
> The current symbols then would be the same as using
>
> RFReification named: #object
>
> But subclasses can be used directly and parametrized.
>
> Marcus
>
>> On 5 Dec 2016, at 20:42, Peter Uhnak <[hidden email]> wrote:
>>
>> Hi,
>>
>> what is the best way to access variables from within a metalink?
>>
>> for example I have a message send `surface clear` and I want to change it to `surface clear: trachelCanvas color`.
>>
>> I can use #instVarNamed:
>>
>> ```
>> MetaLink new
>> metaObject: [ :object |
>> (object instVarNamed: #surface) clear: (object instVarNamed: #trachelCanvas) color.
>> ];
>> selector: #value:;
>> arguments: #(object);
>> control: #instead.
>> ```
>>
>> but the above isn't exactly nice, plus it wouldn't work with temporary variables.
>>
>> Thanks,
>> Peter
>>
>