Re: re-using a comparison closure

2016-05-16 Thread Sergei Egorov
Make it static, i.e. append "static" before "def"

On Mon, May 16, 2016 at 6:57 PM Guy Matz  wrote:

> Thanks!  Not working, though.  Getting:
> No such property: compareVersions for class: Sorters
>
> with:
>
> class Sorters {
> def compareVersions = { afile, bfile ->
> return getVersion(afile).toInteger() <=> getVersion(bfile).toInteger()
> }
> }
>
> and called with:
>
> res.sort(Sorters.compareVersions)
>
>
> Any thoughts are appreciated!  Thanks!!
>
>
>
> On Mon, May 16, 2016 at 11:43 AM, Søren Berg Glasius (GR8Conf EU) <
> sbglas...@gr8conf.org> wrote:
>
>> Hi
>>
>> You can define it in a class as a static closure
>>
>>
>> class Sorters {
>>  static compareVersions =  { a,b ->
>>  return getVersion(a).toInteger() <=> getVersion(b).toInteger()
>>  }
>> }
>>
>> and use it like:
>>
>> list.sort(Sorters.compareVersions)
>>
>> Best regards,
>> Søren Berg Glasius
>> GR8Conf Europe organizing team
>>
>> GR8Conf ApS
>> Mobile: +45 40 44 91 88, Web: www.gr8conf.eu, Skype: sbglasius
>> Company Address: Buchwaldsgade 50, 5000 Odense C, Denmark
>> Personal Address: Hedevej 1, Gl. Rye, 8680 Ry, Denmark
>> --- GR8Conf - Dedicated to the Groovy Ecosystem
>>
>> From: Guy Matz  
>> Reply: users@groovy.apache.org 
>> 
>> Date: May 16, 2016 at 17:42:21
>> To: users@groovy.apache.org 
>> 
>> Subject:  Re: re-using a comparison closure
>>
>> Thanks!  Now, I have a number of methods that need access to that closure
>> . . .  Can I make the closure global?  Is there a better way?
>>
>> Thanks again,
>> Guy
>>
>> On Mon, May 16, 2016 at 11:30 AM, Søren Berg Glasius (GR8Conf EU) <
>> sbglas...@gr8conf.org> wrote:
>>
>>> Hi Guy
>>>
>>> Just assign the variable
>>>
>>> def comapreVersions = { a,b ->
>>> return getVersion(a).toInteger() <=> getVersion(b).toInteger()
>>> }
>>>
>>> and then use it in your sort:
>>>
>>>
>>> list.sort(compareVersions)
>>>
>>>
>>>
>>> Best regards,
>>> Søren Berg Glasius
>>> GR8Conf Europe organizing team
>>>
>>> GR8Conf ApS
>>> Mobile: +45 40 44 91 88, Web: www.gr8conf.eu, Skype: sbglasius
>>> Company Address: Buchwaldsgade 50, 5000 Odense C, Denmark
>>> Personal Address: Hedevej 1, Gl. Rye, 8680 Ry, Denmark
>>> --- GR8Conf - Dedicated to the Groovy Ecosystem
>>>
>>> From: Guy Matz  
>>> Reply: users@groovy.apache.org 
>>> 
>>> Date: May 16, 2016 at 17:28:34
>>> To: users@groovy.apache.org 
>>> 
>>> Subject:  re-using a comparison closure
>>>
>>> Hi!
>>> I have to sort a list of strings based on a number within the string . .
>>> .  I am able to sort using something like:
>>> list.sort( { a,b -> getVersion(a) <=> getVersion(b)})
>>>
>>> I need to use this in a bunch of places in my code and was hoping to
>>> replace it with a method, like:
>>> list.sort( compareVersions)
>>>
>>> with compareVersions:
>>> def compareVersions(a, b) {
>>>   return getVersion(a).toInteger() <=> getVersion(b).toInteger()
>>> }
>>>
>>> putting the method (compoareVersions) into the sort as a param doesn't
>>> work.  Anyone know what I'm missing?
>>>
>>> Thanks!!
>>> Guy
>>>
>>>
>>
>


Macro methods proposal

2016-09-23 Thread Sergei Egorov
Hey, everyone.

It's been awhile since last time I participated in Groovy.
I was mostly in read-only mode for the last two years.

With this move, I hope to change it.

I created a proposal for macro methods (no ETA, initially aimed to 3.0)
because I think they are great for the future of Groovy and compile time
metaprogramming.

You can find the proposal here:
https://github.com/bsideup/groovy-macro-methods-proposal

Not sure how Apache people will react on it since it's on GitHub, but it
was the simplest way for me to share and discuss it.

Please note that macro methods are not the same as MacroGroovy - another
thing from me already merged to groovy-core. But, MacroGroovy *can* and
*should* be implemented with macro methods.


Grammar and clearness are not my strong points, but we can improve the
proposal altogether.


For the few years Guillaume, Baruch, Cedric and others were trying to
spread the word  about macro methods, but the problem here that they are
something really new and I didn't succeed explained them back in the days.


So, I'm inviting everyone to discuss them, by raising GitHub issues, or
here, in mail list, to make them more clear for everyone, including end
users.


Cheers,
Sergei


Re: Macro methods proposal

2016-09-23 Thread Sergei Egorov
Hey Jason,

Left a comment on #3.

Yes, the method signature of Macro methods is not the same as the call
site. But, for the given call site, IDE can easily determine the signature,
and I'm pretty sure it has all the information already. Plus, this is a new
language feature anyway, so IDE will have to support it, at least I see no
other options for now.
See https://github.com/bsideup/groovy-macro-methods-proposal/issues/1 about
the syntax as well

Macro methods inherit all the rules of Groovy AST transformations - they
work only for Groovy code.

BR,
Sergei


On Fri, Sep 23, 2016 at 4:02 PM Winnebeck, Jason <
jason.winneb...@windstream.com> wrote:

> This is a really cool idea, especially I like the idea of the compile-time
> checked ORM example. I wonder whether or not the use in simple cases is
> productive given JIT inlining and branch prediction when branching on a
> constant, and decided to phrase that question in an issue
> https://github.com/bsideup/groovy-macro-methods-proposal/issues/3.
>
>
>
> I noticed that the method signature for the macro method does not match
> the signature used at the call site – does this confuse IDEs like IntelliJ,
> or does this actually work properly because ASTs must be in a separate JAR,
> so the @Macro AST has already run to generate a stub with the proper call
> signature that the IDE sees?
>
>
>
> Last question, is there any interaction with Java? That is, is it possible
> for an implementation to provide a “normal” version of the method like in
> your “warn” example so that Java can call it as a normal method while in
> Groovy the transform would be applied? In that way you could make a logging
> library that would work like a normal logging library in Java but in Groovy
> would apply the macro transformations.
>
>
>
> Jason
>
>
>
> *From:* Sergei Egorov [mailto:bsid...@gmail.com]
> *Sent:* Friday, September 23, 2016 5:58 AM
> *To:* d...@groovy.apache.org; users@groovy.apache.org
> *Subject:* Macro methods proposal
>
>
>
> Hey, everyone.
>
>
>
> It's been awhile since last time I participated in Groovy.
>
> I was mostly in read-only mode for the last two years.
>
>
>
> With this move, I hope to change it.
>
>
>
> I created a proposal for macro methods (no ETA, initially aimed to 3.0)
> because I think they are great for the future of Groovy and compile time
> metaprogramming.
>
>
>
> You can find the proposal here:
>
> https://github.com/bsideup/groovy-macro-methods-proposal
>
>
>
> Not sure how Apache people will react on it since it's on GitHub, but it
> was the simplest way for me to share and discuss it.
>
>
>
> Please note that macro methods are not the same as MacroGroovy - another
> thing from me already merged to groovy-core. But, MacroGroovy *can* and
> *should* be implemented with macro methods.
>
>
>
>
>
> Grammar and clearness are not my strong points, but we can improve the
> proposal altogether.
>
>
>
>
>
> For the few years Guillaume, Baruch, Cedric and others were trying to
> spread the word  about macro methods, but the problem here that they are
> something really new and I didn't succeed explained them back in the days.
>
>
>
>
>
> So, I'm inviting everyone to discuss them, by raising GitHub issues, or
> here, in mail list, to make them more clear for everyone, including end
> users.
>
>
>
>
>
> Cheers,
>
> Sergei
> This email message and any attachments are for the sole use of the
> intended recipient(s). Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply email and destroy all copies of the original
> message and any attachments.
>


Re: Welcome to our new committer : Sergei Egorov

2016-12-10 Thread Sergei Egorov
Hi, the Apache Groovy people!

I'm excited to join the team! Big thanks to PMC for this opportunity.

I wrote my first Groovy code 3.5 years ago :) Was tired of the POJO
boilerplate :D
Most of the time I was doing some crazy Groovy things just because I wanted
to learn how Groovy compiler works under the hood. It was fun and easy,
thanks to a great compile time meta-programming model (IMO one of the best
across JVM languages)
But eventually, such things has started to appear as libraries, available
for everyone. And here we are - some of them are merged to groovy-core and
more to come :)

As a committer I hope to continue and even increase my effort on the macro
system and few other parts of the language, but with all the power (and
responsibility :) ) of it.

Hopefully, Groovy people will pay more attention on the macro system as
well, i.e. by asking your questions here:
https://github.com/bsideup/groovy-macro-methods-proposal

I'm looking forward to being  an active committer!

Thanks,
Sergei Egorov

On Sat, Dec 10, 2016 at 11:08 AM Cédric Champeau <cchamp...@apache.org>
wrote:

> Hi folks,
>
> I'd like to introduce you to Sergei Egorov, our new Apache Groovy
> committer! Some of you may already know Sergei for his work on macros,
> which are going to make appearance in Apache Groovy 2.5. He is a very
> talented developer with the skills we need to help Groovy move forward.
>
> A warm welcome, and congratulations, to Sergei!
>
> Sergei, would you mind telling a few words about you?
>
> On behalf of the Apache Groovy team
> Cédric
>
>


Re: Macro methods proposal

2016-12-01 Thread Sergei Egorov
Cedric had an idea to include macro methods in 2.5 and re-implement
MacroGroovy as a macro method, so I'm reminding everyone about the proposal
:)

I'm almost done backporting groovy-macro-methods into the groovy-core, will
send PR this week so others can review (it's still WIP tho)

On Fri, Sep 23, 2016 at 4:54 PM Sergei Egorov <bsid...@gmail.com> wrote:

> Unfortunately, it will not work for 100% cases.
>
> I.e. macro method accepts ConstantExpression. You can't a method in Groovy
> with such constraints.
>
> Plus, such signature doesn't make sense for IDEs as well, because macro
> methods do all the magic when you compile *your* code, not macro method
> itself.
>
>
> Sergei
>
> On Fri, Sep 23, 2016 at 4:46 PM Winnebeck, Jason <
> jason.winneb...@windstream.com> wrote:
>
> Assuming the AST can’t already form the right signature in the JAR for IDE
> to see, I can think of one solution:
>
>
>
> public class MacroMethods {
>
>   @Macro public static  T safe(T param) {
>
> def ctx = Macros.macroContext
>
> def exp = Macros.getExpression(param)
>
> //original code from example…
>
>   }
>
> }
>
>
>
> In this case, the IDE sees a method with an appropriate signature, and
> knows the method returns the same type as the argument, but you still have
> access to the macro context via static methods which could be implemented
> using thread locals or similar. The signature could also be used to
> restrict the type of the expression allowed, although in most cases I’d
> expect Object or a “T” to be used.
>
>
>
> Jason
>
>
>
> *From:* Sergei Egorov [mailto:bsid...@gmail.com]
> *Sent:* Friday, September 23, 2016 9:27 AM
> *To:* users@groovy.apache.org; d...@groovy.apache.org
> *Subject:* Re: Macro methods proposal
>
>
>
> Hey Jason,
>
>
>
> Left a comment on #3.
>
>
>
> Yes, the method signature of Macro methods is not the same as the call
> site. But, for the given call site, IDE can easily determine the signature,
> and I'm pretty sure it has all the information already. Plus, this is a new
> language feature anyway, so IDE will have to support it, at least I see no
> other options for now.
>
> See https://github.com/bsideup/groovy-macro-methods-proposal/issues/1 about
> the syntax as well
>
>
>
> Macro methods inherit all the rules of Groovy AST transformations - they
> work only for Groovy code.
>
>
>
> BR,
>
> Sergei
>
>
>
>
>
> On Fri, Sep 23, 2016 at 4:02 PM Winnebeck, Jason <
> jason.winneb...@windstream.com> wrote:
>
> This is a really cool idea, especially I like the idea of the compile-time
> checked ORM example. I wonder whether or not the use in simple cases is
> productive given JIT inlining and branch prediction when branching on a
> constant, and decided to phrase that question in an issue
> https://github.com/bsideup/groovy-macro-methods-proposal/issues/3.
>
>
>
> I noticed that the method signature for the macro method does not match
> the signature used at the call site – does this confuse IDEs like IntelliJ,
> or does this actually work properly because ASTs must be in a separate JAR,
> so the @Macro AST has already run to generate a stub with the proper call
> signature that the IDE sees?
>
>
>
> Last question, is there any interaction with Java? That is, is it possible
> for an implementation to provide a “normal” version of the method like in
> your “warn” example so that Java can call it as a normal method while in
> Groovy the transform would be applied? In that way you could make a logging
> library that would work like a normal logging library in Java but in Groovy
> would apply the macro transformations.
>
>
>
> Jason
>
>
>
> *From:* Sergei Egorov [mailto:bsid...@gmail.com]
> *Sent:* Friday, September 23, 2016 5:58 AM
> *To:* d...@groovy.apache.org; users@groovy.apache.org
> *Subject:* Macro methods proposal
>
>
>
> Hey, everyone.
>
>
>
> It's been awhile since last time I participated in Groovy.
>
> I was mostly in read-only mode for the last two years.
>
>
>
> With this move, I hope to change it.
>
>
>
> I created a proposal for macro methods (no ETA, initially aimed to 3.0)
> because I think they are great for the future of Groovy and compile time
> metaprogramming.
>
>
>
> You can find the proposal here:
>
> https://github.com/bsideup/groovy-macro-methods-proposal
>
>
>
> Not sure how Apache people will react on it since it's on GitHub, but it
> was the simplest way for me to share and discuss it.
>
>
>
> Please note that macro methods are not the same as MacroGroovy - another
&g