It's a good reason to be cautious about overuse of by-name parameters.  I
see why they're useful (DSLs) but I'd prefer a visual distinction from an
ordinary block.  I suppose an IDE could highlight them differently.

On Fri, Jul 27, 2012 at 11:03 PM, Josh Berry <[email protected]> wrote:

> On Fri, Jul 27, 2012 at 4:10 PM, Ricky Clarkson
> <[email protected]> wrote:
> > I can't comment on the 'I'm likely wrong here' part as I couldn't follow
> you
> > there.
> >
> > Your rule of thumb is a good one for current Scala and Java.
>
> My rule of thumb led me astray, as it seemed to indicate there is a
> closure there.  Of course, things are curious with this snippet
> because this:
>
> None map {println("Hello"); println}
>
> Will print hello once.  This seems counter to what I would have
> expected, which would be for that block to only be evaluated if there
> was something to map.  I think I see where I was wrong.  Not entirely
> sure, though.
>
> Your reasoning about a => being required if only at the function site
> doesn't really make sense to me.  The part that surprises me is that
> this change will again cause the block to be "evaluated" and the last
> statement used in its place:
>
> def run10Times(x: () => Any => Unit) = 1 to 10 map (x)
>
> run10Times{
>   println("hello")
>   println
> }
>
> This make sense in light of my new understanding, but it ultimately
> underscores that there is zero way to tell by looking at a function
> call if a block you place in it is a closure or not.  (Which, really,
> is ultimately the point, right?  That the language does the job of
> creating the environments necessary for the code to function as
> specified.)
>
> Ah well, apologies for the long tangent.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to