MetaLinks with arbitrary number of arguments

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

MetaLinks with arbitrary number of arguments

Peter Uhnak
Hi,

is it possible to create a metalink on arbitrary amount of arguments?

Right now the metaObject and selector must have the same number of arguments, e.g.

MetaLink new
        metaObject: [ :object :selector :args | ... ];
        selector: #value:value:value;
        arguments: #(object selector arguments)


What I would like to have instead is something like...

MetaLink new
        metaObject: [ :allArgs | ... ];
        selector: #value:;
        arguments: #(object selector arguments)


And then `allArgs` would either be an array with all the arguments, or maybe a Dictionary.

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: MetaLinks with arbitrary number of arguments

Marcus Denker-4

> On 15 Mar 2017, at 10:35, Peter Uhnak <[hidden email]> wrote:
>
> Hi,
>
> is it possible to create a metalink on arbitrary amount of arguments?
>
> Right now the metaObject and selector must have the same number of arguments, e.g.
>
> MetaLink new
> metaObject: [ :object :selector :args | ... ];
> selector: #value:value:value;
> arguments: #(object selector arguments)
>
>
> What I would like to have instead is something like...
>
> MetaLink new
> metaObject: [ :allArgs | ... ];
> selector: #value:;
> arguments: #(object selector arguments)
>
>
> And then `allArgs` would either be an array with all the arguments, or maybe a Dictionary.
>

Right now not… but it would be a nice addition.

It could either use some magic (if the number of args requested are larger then the number of args
of the selector it gives the rest as a dictionary).

or, maybe better (less magic), this could be an option to be configured per link:


MetaLink new
        metaObject: [ :allArgs | ... ];
        selector: #value:;
        arguments: #(object selector arguments)
        options: #(argsAsDictionary)

(which would allow #argsAsArray, too).

        Marcus
Reply | Threaded
Open this post in threaded view
|

Re: MetaLinks with arbitrary number of arguments

Peter Uhnak
On Wed, Mar 15, 2017 at 10:49:51AM +0100, denker wrote:

>
> > On 15 Mar 2017, at 10:35, Peter Uhnak <[hidden email]> wrote:
> >
> > Hi,
> >
> > is it possible to create a metalink on arbitrary amount of arguments?
> >
> > Right now the metaObject and selector must have the same number of arguments, e.g.
> >
> > MetaLink new
> > metaObject: [ :object :selector :args | ... ];
> > selector: #value:value:value;
> > arguments: #(object selector arguments)
> >
> >
> > What I would like to have instead is something like...
> >
> > MetaLink new
> > metaObject: [ :allArgs | ... ];
> > selector: #value:;
> > arguments: #(object selector arguments)
> >
> >
> > And then `allArgs` would either be an array with all the arguments, or maybe a Dictionary.
> >
>
> Right now not… but it would be a nice addition.
>
> It could either use some magic (if the number of args requested are larger then the number of args
> of the selector it gives the rest as a dictionary).
>
> or, maybe better (less magic), this could be an option to be configured per link:
>
>
> MetaLink new
> metaObject: [ :allArgs | ... ];
> selector: #value:;
> arguments: #(object selector arguments)
> options: #(argsAsDictionary)
>
> (which would allow #argsAsArray, too).
>
> Marcus


+1 for option, magic only brings suffering. :)

Peter

Reply | Threaded
Open this post in threaded view
|

Re: MetaLinks with arbitrary number of arguments

Marcus Denker-4

> On 15 Mar 2017, at 11:09, Peter Uhnak <[hidden email]> wrote:
>
> On Wed, Mar 15, 2017 at 10:49:51AM +0100, denker wrote:
>>
>>> On 15 Mar 2017, at 10:35, Peter Uhnak <[hidden email]> wrote:
>>>
>>> Hi,
>>>
>>> is it possible to create a metalink on arbitrary amount of arguments?
>>>
>>> Right now the metaObject and selector must have the same number of arguments, e.g.
>>>
>>> MetaLink new
>>> metaObject: [ :object :selector :args | ... ];
>>> selector: #value:value:value;
>>> arguments: #(object selector arguments)
>>>
>>>
>>> What I would like to have instead is something like...
>>>
>>> MetaLink new
>>> metaObject: [ :allArgs | ... ];
>>> selector: #value:;
>>> arguments: #(object selector arguments)
>>>
>>>
>>> And then `allArgs` would either be an array with all the arguments, or maybe a Dictionary.
>>>
>>
>> Right now not… but it would be a nice addition.
>>
>> It could either use some magic (if the number of args requested are larger then the number of args
>> of the selector it gives the rest as a dictionary).
>>
>> or, maybe better (less magic), this could be an option to be configured per link:
>>
>>
>> MetaLink new
>> metaObject: [ :allArgs | ... ];
>> selector: #value:;
>> arguments: #(object selector arguments)
>> options: #(argsAsDictionary)
>>
>> (which would allow #argsAsArray, too).
>>
>> Marcus
>
>
> +1 for option, magic only brings suffering. :)
>

This should be easy.. I will look into it hopefully this week.

        Marcus


Reply | Threaded
Open this post in threaded view
|

Re: MetaLinks with arbitrary number of arguments

Marcus Denker-4
Hi,

Here is a slice that implements the  #argsAsArray option:
 
        https://pharo.fogbugz.com/f/cases/19857/add-option-argsAsArray

from a speed perspective, the question is if a dictionary makes sense… as it would
need to be created at runtime.

        Marcus

> On 15 Mar 2017, at 11:25, denker <[hidden email]> wrote:
>
>
>> On 15 Mar 2017, at 11:09, Peter Uhnak <[hidden email]> wrote:
>>
>> On Wed, Mar 15, 2017 at 10:49:51AM +0100, denker wrote:
>>>
>>>> On 15 Mar 2017, at 10:35, Peter Uhnak <[hidden email]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> is it possible to create a metalink on arbitrary amount of arguments?
>>>>
>>>> Right now the metaObject and selector must have the same number of arguments, e.g.
>>>>
>>>> MetaLink new
>>>> metaObject: [ :object :selector :args | ... ];
>>>> selector: #value:value:value;
>>>> arguments: #(object selector arguments)
>>>>
>>>>
>>>> What I would like to have instead is something like...
>>>>
>>>> MetaLink new
>>>> metaObject: [ :allArgs | ... ];
>>>> selector: #value:;
>>>> arguments: #(object selector arguments)
>>>>
>>>>
>>>> And then `allArgs` would either be an array with all the arguments, or maybe a Dictionary.
>>>>
>>>
>>> Right now not… but it would be a nice addition.
>>>
>>> It could either use some magic (if the number of args requested are larger then the number of args
>>> of the selector it gives the rest as a dictionary).
>>>
>>> or, maybe better (less magic), this could be an option to be configured per link:
>>>
>>>
>>> MetaLink new
>>> metaObject: [ :allArgs | ... ];
>>> selector: #value:;
>>> arguments: #(object selector arguments)
>>> options: #(argsAsDictionary)
>>>
>>> (which would allow #argsAsArray, too).
>>>
>>> Marcus
>>
>>
>> +1 for option, magic only brings suffering. :)
>>
>
> This should be easy.. I will look into it hopefully this week.
>
> Marcus
>


Reply | Threaded
Open this post in threaded view
|

Re: MetaLinks with arbitrary number of arguments

Marcus Denker-4

> On 20 Mar 2017, at 16:34, denker <[hidden email]> wrote:
>
> Hi,
>
> Here is a slice that implements the  #argsAsArray option:
>
> https://pharo.fogbugz.com/f/cases/19857/add-option-argsAsArray
>
> from a speed perspective, the question is if a dictionary makes sense… as it would
> need to be created at runtime.
>

This test show how to use it:

testReifySendArgsAsArray
        | sendNode instance|
        sendNode := (ReflectivityExamples>>#exampleMethod) ast body statements first value.
        link := MetaLink new
                metaObject: self;
                selector: #tagExec:;
                arguments: #(selector context);
                options: #(argsAsArray).
        sendNode link: link.
        self assert: sendNode hasMetalink.
        self assert: (ReflectivityExamples>>#exampleMethod) class = ReflectiveMethod.
        self assert: (tag isNil).
        instance := ReflectivityExamples new .
        self assert: (instance exampleMethod = 5).
        self assert: (tag isArray).
        self assert: (tag first == #+).
        self assert: (tag second class == Context).