Re: [RFE] Methods as expressions

2018-03-22 Thread David Dawson
> >> I think you could experiment with this using a closure, since return >> statements have this expression property already: >> >> >> >> final foo = ({ -> >> >> if(...) { ... } >> >> else if(...) { ... } >> >> else i

Re: [RFE] Methods as expressions

2018-03-21 Thread MG
return statements have this expression property already: final foo = ({ ->   if(...) { ... }   else if(...) { ... }   else if(...) { ... }   else { ... } }()) *From:*mg [mailto:mg...@arscreat.com] *Sent:* Wednesday, March 21, 2018 4:03 PM *To:* dev@groovy.apache.org <mailto:dev@groovy.apach

Re: [RFE] Methods as expressions

2018-03-21 Thread David Dawson
)) > > > > > > *From:* mg [mailto:mg...@arscreat.com <mg...@arscreat.com>] > *Sent:* Wednesday, March 21, 2018 4:03 PM > *To:* dev@groovy.apache.org > *Subject:* Re: [RFE] Methods as expressions > > > > Having control flow statements as expressions in

Re: [RFE] Methods as expressions

2018-03-21 Thread MG
ct:* Re: [RFE] Methods as expressions Having control flow statements as expressions in Groovy would feel pretty natural to me. I had always assumed there were reasons why this was not supported, so I did not bring it up... I currently use the simulated eval language extension I proposed for that,

RE: [RFE] Methods as expressions

2018-03-21 Thread eric.milles
:03 PM To: dev@groovy.apache.org Subject: Re: [RFE] Methods as expressions Having control flow statements as expressions in Groovy would feel pretty natural to me. I had always assumed there were reasons why this was not supported, so I did not bring it up... I currently use the simulated e

Re: [RFE] Methods as expressions

2018-03-21 Thread mg
od in Rust ? Cheers,mg Ursprüngliche Nachricht Von: David Dawson <david.daw...@simplicityitself.com> Datum: 21.03.18 10:07 (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: [RFE] Methods as expressions in Rust, control flow statements are expressions. Partly this was

Re: [RFE] Methods as expressions

2018-03-21 Thread David Dawson
in Rust, control flow statements are expressions. Partly this was done to enable the lifetimes to be more concisely controlled, but its a nice structure. If done in groovy, this would work (toy example, picking the right payment provider based on a property) def provider = if(request.name ==

Re: [RFE] Methods as expressions

2018-03-21 Thread Jochen Theodorou
Am 21.03.2018 um 09:27 schrieb Cédric Champeau: [...] In any case, I was doubtful as you are here before actually using it in Kotlin. After a few weeks, it became clear to me this syntax was both more concise and more self-explanatory. For me {} was always very clear, for {} starts a new

Re: [RFE] Methods as expressions

2018-03-21 Thread Guillaume Laforge
Another case is a method / function that returns a closure, would we allow the syntax: def m(String x, int y) = { x * y } ? On Wed, Mar 21, 2018 at 3:46 AM, Daniel Sun wrote: > Hi Cédric, > > If method throws exception, what does your proposed syntax look like? >

Re: [RFE] Methods as expressions

2018-03-21 Thread Cédric Champeau
It's funny to see arguments about compatibility with Java here. Groovy's compatibility with Java is the promise that you can _almost_ copy and paste Java code and it compiles in Groovy. Not the other way around ;) In any case, I was doubtful as you are here before actually using it in Kotlin.

Re: [RFE] Methods as expressions

2018-03-21 Thread David Dawson
LOL. thanks, I probably deserved that being thrown back at me :-) I think that Jochen said it best "It seemed to be part of a bigger picture, but the bigger picture is missing." My CS background is on the weaker side, so I can't quite say what I want... Apart from Groovy, the two languages that

Re: [RFE] Methods as expressions

2018-03-20 Thread Daniel Sun
Hi Cédric, If method throws exception, what does your proposed syntax look like? For example, ``` def m(String x, Integer y) throws IOException { readSomeFile(..) } ``` is equivalent to the following code? ``` def m(String x, Integer y) throws IOException = readSomeFile(..) ```

Re: [RFE] Methods as expressions

2018-03-20 Thread MG
On 20.03.2018 17:16, David Dawson wrote: To give an alternate take on the topic. The best thing in Groovy when it first started gaining adoption was this ["hello"], "world"].collect {   it * 2 }.each { println it } Utterly incompatible with Java, happily destroying its idioms. Collection

Re: [RFE] Methods as expressions

2018-03-20 Thread MG
On 20.03.2018 16:19, eric.mil...@thomsonreuters.com wrote: Java syntax for a default method value is: public@interfaceDelegate{ boolean*interfaces*() defaulttrue; Is there really a need to introduce another form when the saving is actially 0 characters (colon and equals vs open and close

Re: [RFE] Methods as expressions

2018-03-20 Thread David Dawson
ize named > parameters? > > > > *From:* mg [mailto:mg...@arscreat.com] > *Sent:* Tuesday, March 20, 2018 7:11 AM > *To:* dev@groovy.apache.org > *Subject:* Re: [RFE] Methods as expressions > > > > I agree with the proper functions in principle, but in this case it w

RE: [RFE] Methods as expressions

2018-03-20 Thread eric.milles
: Tuesday, March 20, 2018 7:11 AM To: dev@groovy.apache.org Subject: Re: [RFE] Methods as expressions I agree with the proper functions in principle, but in this case it would be "special syntax for a special, limited case" which to me is the (non desirable) C# way of doing things... I

Re: [RFE] Methods as expressions

2018-03-20 Thread Daniel.Sun
Hi Cédric, +1. I would like to hear what other groovy users say. P.S. Your proposal should be not difficult to implement in Parrot parser. Cheers, Daniel.Sun -- Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: [RFE] Methods as expressions

2018-03-20 Thread mg
of making Groovy Kotlin compatible now Ursprüngliche Nachricht Von: David Dawson <david.daw...@simplicityitself.com> Datum: 20.03.18 13:00 (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: [RFE] Methods as expressions I personally agree with Cedric, having the intent of &q

Re: [RFE] Methods as expressions

2018-03-20 Thread David Dawson
: Cédric Champeau <cedric.champ...@gmail.com> > Datum: 20.03.18 12:23 (GMT+01:00) > An: dev@groovy.apache.org > Betreff: Re: [RFE] Methods as expressions > > Again that's a declaration of intent (if you put apart the fact that you > can have style rules that force you to put t

Re: [RFE] Methods as expressions

2018-03-20 Thread mg
atum: 20.03.18 11:41 (GMT+01:00) An: dev@groovy.apache.org Betreff: [RFE] Methods as expressions Hi, One of the Kotlin features I really like is the short-hand notation for simple expression methods: class Foo {     fun truth(): Integer = 42 } For example, in Groovy, you write: @Controller

Re: [RFE] Methods as expressions

2018-03-20 Thread mg
2:23 (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: [RFE] Methods as expressions Again that's a declaration of intent (if you put apart the fact that you can have style rules that force you to put the brackets on new lines). When I write: double surface(double x, double y) = x * y It's

Re: [RFE] Methods as expressions

2018-03-20 Thread Paolo Di Tommaso
Ursprüngliche Nachricht > Von: Cédric Champeau <cedric.champ...@gmail.com> > Datum: 20.03.18 11:41 (GMT+01:00) > An: dev@groovy.apache.org > Betreff: [RFE] Methods as expressions > > Hi, > > One of the Kotlin features I really like is the sho

Re: [RFE] Methods as expressions

2018-03-20 Thread Cédric Champeau
- Ursprüngliche Nachricht > Von: Cédric Champeau <cedric.champ...@gmail.com> > Datum: 20.03.18 11:41 (GMT+01:00) > An: dev@groovy.apache.org > Betreff: [RFE] Methods as expressions > > Hi, > > One of the Kotlin features I really like is the short-hand notation

Re: [RFE] Methods as expressions

2018-03-20 Thread mg
: [RFE] Methods as expressions Hi, One of the Kotlin features I really like is the short-hand notation for simple expression methods: class Foo {     fun truth(): Integer = 42 } For example, in Groovy, you write: @Controller("/") class HelloController { @Get("/hello/{name

Re: [RFE] Methods as expressions

2018-03-20 Thread mg
lt;cedric.champ...@gmail.com> Datum: 20.03.18 11:41 (GMT+01:00) An: dev@groovy.apache.org Betreff: [RFE] Methods as expressions Hi, One of the Kotlin features I really like is the short-hand notation for simple expression methods: class Foo {     fun truth(): Integer = 42 } For example, in

Re: [RFE] Methods as expressions

2018-03-20 Thread Cédric Champeau
I agree, that's the syntax I use for now. But I like the expression syntax `=` because of the explicitness of the expression (it's a function which value is ...). It's less about saving characters than it is about expressing the intent. 2018-03-20 12:08 GMT+01:00 Andres Almiray

Re: [RFE] Methods as expressions

2018-03-20 Thread Andres Almiray
FYI you can also write it like @Controller("/") class HelloController { @Get("/hello/{name}") String hello(String name) { "Hello $name" } } So you're only saving 2 characters (space and closing brace) by following Kotlin/Scala syntax. Cheers, Andres

Re: [RFE] Methods as expressions

2018-03-20 Thread David Dawson
Yes, I would love this kind of thing On 20 March 2018 at 10:41, Cédric Champeau wrote: > Hi, > > One of the Kotlin features I really like is the short-hand notation for > simple expression methods: > > class Foo { > fun truth(): Integer = 42 > } > > For example,

[RFE] Methods as expressions

2018-03-20 Thread Cédric Champeau
Hi, One of the Kotlin features I really like is the short-hand notation for simple expression methods: class Foo { fun truth(): Integer = 42 } For example, in Groovy, you write: @Controller("/") class HelloController { @Get("/hello/{name}") String hello(String name) {