You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Jorge Franco <gr...@gmail.com> on 2016/11/25 23:29:16 UTC
Proposal - Pattern matching elixir way
Hello!
I'm playing with elixir language lately, and I like the pattern matching
and guards in functions. I'm sure more proposal about pattern matching have
been done. And yes, in groovy switch is very powerful. But I think can be
interesting add something similar in groovy, so then groovy is more
functional friendly and readable.
Please take a look at this implementation idea, using AST's:
https://gist.github.com/chiquitinxx/296ec6cd0cf4d5afe01e6693f14a877b
What do you think? not very interesting, maybe other implementation ideas,
too much complex, switch wins, ...
Thank you for your time.
Some links to elixir:
http://elixir-lang.org/getting-started/pattern-matching.html
http://culttt.com/2016/05/23/multi-clause-functions-pattern-matching-guards-elixir/
Re: Proposal - Pattern matching elixir way
Posted by Jorge Franco <gr...@gmail.com>.
Thank you for the feedback :)
I agree annotations can be a bit 'magic' stuff. And I see Sergei's macros
looks great. So, I think I'll try Andres suggestion, create a external
library with ast's (without changing groovy syntax), I think can be similar
to GContracts. Then maybe in the future, can be moved to a nice groovy
syntax.
Cheers
2016-11-29 0:15 GMT+01:00 Roman Shaposhnik <ro...@shaposhnik.org>:
> On Fri, Nov 25, 2016 at 3:50 PM, Johannes Link <jo...@gmail.com>
> wrote:
> > Using an annotation seems like a hackish way. I'd rather go with an
> extended
> > version of switch or even better a native matching parameter syntax.
> Just my
> > 2 cents.
>
> Same here: I feel like relying on annotations too much tends to create a
> very
> black-box'ish type of experience for developers: slap the right annotation
> on
> something and magic happens. When it works it is great, but when it doesn't
> once tends to spend a lot more time trying to figure out what went wrong in
> annotation heavy frameworks.
>
> Thanks,
> Roman.
>
Re: Proposal - Pattern matching elixir way
Posted by Roman Shaposhnik <ro...@shaposhnik.org>.
On Fri, Nov 25, 2016 at 3:50 PM, Johannes Link <jo...@gmail.com> wrote:
> Using an annotation seems like a hackish way. I'd rather go with an extended
> version of switch or even better a native matching parameter syntax. Just my
> 2 cents.
Same here: I feel like relying on annotations too much tends to create a very
black-box'ish type of experience for developers: slap the right annotation on
something and magic happens. When it works it is great, but when it doesn't
once tends to spend a lot more time trying to figure out what went wrong in
annotation heavy frameworks.
Thanks,
Roman.
Re: Proposal - Pattern matching elixir way
Posted by Johannes Link <jo...@gmail.com>.
Using an annotation seems like a hackish way. I'd rather go with an extended version of switch or even better a native matching parameter syntax. Just my 2 cents.
Johannes
> Am 26.11.2016 um 00:29 schrieb Jorge Franco <gr...@gmail.com>:
>
> Hello!
>
> I'm playing with elixir language lately, and I like the pattern matching and guards in functions. I'm sure more proposal about pattern matching have been done. And yes, in groovy switch is very powerful. But I think can be interesting add something similar in groovy, so then groovy is more functional friendly and readable.
>
> Please take a look at this implementation idea, using AST's:
> https://gist.github.com/chiquitinxx/296ec6cd0cf4d5afe01e6693f14a877b
>
> What do you think? not very interesting, maybe other implementation ideas, too much complex, switch wins, ...
>
> Thank you for your time.
>
> Some links to elixir:
> http://elixir-lang.org/getting-started/pattern-matching.html
> http://culttt.com/2016/05/23/multi-clause-functions-pattern-matching-guards-elixir/
Re: Proposal - Pattern matching elixir way
Posted by Sergei Egorov <bs...@gmail.com>.
Hey Jorge,
You can also take a look at:
https://github.com/bsideup/groovy-pattern-match/blob/e2c2b0472b7d078a8b299085705584cfea827405/src/test/groovy/ru/trylogic/groovy/pattern/PatternMatchingMacroMethodsTest.groovy
This is pattern matching implemented as a macro method, without touching
the syntax of Groovy.
Macro methods FTW! :)
On Sat, 26 Nov 2016 at 11:12, Andres Almiray <aa...@gmail.com> wrote:
> This kind of idea is why I love AST xforms: you can play around with a
> feature without forcing a syntax change into Groovy core.
>
> This is exactly what happened with @TailRecursive. The feature proved to
> be good enough for 80% of the cases, for the remaining it was either
> verbose or required a true syntax change. It's likely this enhanced switch
> will encounter the same fate.
>
> My suggestion: continue developing the feature as a standalone module,
> push binaries to bintray/maven central. That way you can get quicker
> feedback from a broader audience. When the time is right, we can revisit
> adding the feature into core.
>
> Please don't get me wrong, the feature has merit but I think it requires a
> bit more work to further understand the ramifications of adding it to core.
> After all, we don't want Groovy to become a kitchen-sink language, drag
> down by complexity to later try to save face and claim it's a simple
> language and that you need to read 10 papers to understand why is that, do
> we? ;-)
>
> Cheers
> Andres
>
> Sent from my primitive Tricorder
>
> > On Nov 26, 2016, at 8:26 AM, Daniel Sun <re...@hotmail.com> wrote:
> >
> > Hi Jorge,
> >
> > First of all, thanks for your proposal.
> >
> > I wonder why do you want the feature? What senarios make the code
> such
> > as "@When('!file || !new File(path).exists()')" overwhelm existing
> features
> > of groovy(e.g. switch statement)?
> >
> > Cheers,
> > Daniel.Sun
> >
> >
> >
> > --
> > View this message in context:
> http://groovy.329449.n5.nabble.com/Proposal-Pattern-matching-elixir-way-tp5737005p5737008.html
> > Sent from the Groovy Dev mailing list archive at Nabble.com.
>
Re: Proposal - Pattern matching elixir way
Posted by Andres Almiray <aa...@gmail.com>.
This kind of idea is why I love AST xforms: you can play around with a feature without forcing a syntax change into Groovy core.
This is exactly what happened with @TailRecursive. The feature proved to be good enough for 80% of the cases, for the remaining it was either verbose or required a true syntax change. It's likely this enhanced switch will encounter the same fate.
My suggestion: continue developing the feature as a standalone module, push binaries to bintray/maven central. That way you can get quicker feedback from a broader audience. When the time is right, we can revisit adding the feature into core.
Please don't get me wrong, the feature has merit but I think it requires a bit more work to further understand the ramifications of adding it to core. After all, we don't want Groovy to become a kitchen-sink language, drag down by complexity to later try to save face and claim it's a simple language and that you need to read 10 papers to understand why is that, do we? ;-)
Cheers
Andres
Sent from my primitive Tricorder
> On Nov 26, 2016, at 8:26 AM, Daniel Sun <re...@hotmail.com> wrote:
>
> Hi Jorge,
>
> First of all, thanks for your proposal.
>
> I wonder why do you want the feature? What senarios make the code such
> as "@When('!file || !new File(path).exists()')" overwhelm existing features
> of groovy(e.g. switch statement)?
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/Proposal-Pattern-matching-elixir-way-tp5737005p5737008.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.
Re: Proposal - Pattern matching elixir way
Posted by Daniel Sun <re...@hotmail.com>.
Hi Jorge,
First of all, thanks for your proposal.
I wonder why do you want the feature? What senarios make the code such
as "@When('!file || !new File(path).exists()')" overwhelm existing features
of groovy(e.g. switch statement)?
Cheers,
Daniel.Sun
--
View this message in context: http://groovy.329449.n5.nabble.com/Proposal-Pattern-matching-elixir-way-tp5737005p5737008.html
Sent from the Groovy Dev mailing list archive at Nabble.com.