Re: [groovy-user] mixing dynamic and static code in groovy
Alex Tkachman schrieb:
> On Mon, Nov 30, 2009 at 11:54 PM, Jochen Theodorou <blackdrag@...> wrote:
>> Alex Tkachman schrieb:
>>> Hi!
>>>
>>> After I published 1st results in to direction of statically typed
>>> Groovy I was asked many times by different people about ability to mix
>>> dynamic and static code together. Here is short article on first
>>> results in this direction -
>>> http://groovy.dzone.com/articles/mixing-dynamic-and-static-code-0
>> Alex, you wrote: number ([value: it, prime:false]
>> Is there a special reason you don't write:
>>
>> number (value: it, prime:false)?
>>
>> Becuase, this version is what we usually use. Yours is not wrong, I was just
>> wondering.
>>
>
> Good catch. Not implemented yet and I try not publish code, which doesn't work.
Should I take this as you writing a whole new parser then?
[...]
>> And even if I know it is a Collection, that does not
>> remove the possibility that the value has a class with its own definition of
>> "each" which then should be called instead. And I am not talking about a
>> dynamic "each" method here.
>
> resolve of method to call goes very similar to standard groovy
> algorithm - own methods, DGM, static categories in use but dynamicly
> added methods obviously ignored
ok, then if there is:
Collection x = foo()
and foo() is a dynanic method call, and later we have
x.each {println it}
how are you able to tell what "each" exactly is to be used without
making a dynamic method call for it? In Java this is out of question,
because either it is defined on Collection in a static manner (which is
not), or it is a compile time error. So I wonder how you want to make
this into a static method call.
Also the order own methods, DGM is not fully correct. If we have a
method T#x() in DGM (DGM#x(T)) as well as in T, then the DGM method is
used instead of the one defined on T. If we have a method x() in T1, but
the class we actually have to handle is T2 extends T1, and DGM provides
a T2#x(), then the DGM method is taking instead of the own method again.
If we actually handle a T3 extends T2 and there is a T3#x(), then
T3#x() will be used instead of the DGM method. And these rules apply
even if the static type of the variable used for the value laterhas only
the static type T0, with T0 extends T1.
I really wonder how you want to handle T0 x = foo(); x.x(), if x is
actually a T2. Don't get me wrong, I can imagine ways, they are just not
very good.
bye blackdrag
--
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email