26 Jun 20:15
Re: [groovy-dev] optional returns
From: Jochen Theodorou <blackdrag@...>
Subject: Re: [groovy-dev] optional returns
Newsgroups: gmane.comp.lang.groovy.devel
Date: 2008-06-26 18:15:14 GMT
Subject: Re: [groovy-dev] optional returns
Newsgroups: gmane.comp.lang.groovy.devel
Date: 2008-06-26 18:15:14 GMT
Martin C. Martin schrieb:
> In Ruby, there's not distinction between statements and expressions.
> There's a convention that sometimes if, for, etc. are called statements,
> but the compiler/interpreter make no such distinction.
>
> So looping constructs are expressions, but they always return nil, since
> there's really no good return value for them. It's the same reason that
> Groovy's "each" doesn't return anything.
I think we changed each to return the object we iterate on, so in
list.each{println it} we will return the list...
> switch statements (which Ruby calls "case" statements) return a value.
> Here's the first example of their use in Matz's book on Ruby:
>
> # Determine US generation name based on birth year
> # Case expression tests ranges with ===
> generation = case birthyear
> when 1946..1963: "Baby Boomer"
> when 1964..1976: "Generation X"
> when 1978..2000: "Generation Y"
> else nil
> end
yes, I think we really should keep in mind, that Groovy has statements
and expressions, while others have probably only expressions. That is a
huge difference. And starting to let statements return something, means
in the end to let all statements become expressions.
bye blackdrag
--
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
RSS Feed