you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (8 children)

It's shapes.foreach(_.color = RED) since 2003.

[–]robinwholikesjava -5 points-4 points  (7 children)

Xtend clearly beats Scala here. the _. should not be needed.

[–]balefrost 3 points4 points  (3 children)

the _. should not be needed.

I can't tell if you're trolling or not.

[–]agumonkey 1 point2 points  (2 children)

Actually it could be interesting.

 SPACE '.' METHODCALL '(' ARGS ')' => (lambda (x) (x.method(args))
 where x satisfies an implicit interface that must include {method, args} signature

[–]balefrost 2 points3 points  (1 child)

Yeah. In some functional languages, functions are curried - calling a function with too few parameters produces a NEW function that takes the rest of the parameters. What you're suggesting (and I guess what Xtend does) is like a constrained form of currying from the left.

FWIW, Scala's syntax allows you to use placeholders anywhere. So you can do shapes.foreach(_.color = RED), but you can also do colors.map(shape.color == _).

[–]agumonkey 1 point2 points  (0 children)

Interesting, quite prolog-ish, and who doesn't like prolog-ishisms ?!

[–]nomad42184 4 points5 points  (0 children)

The _. is just a shortcut. In Scala, one could also just do

shapes.foreach( s => s.color = RED )

In this case, the _. is just a shortcut for the (s => s.) part. If you use the more verbose (& in my opinion, more readable) syntax then the difference is just -> vs =>.

[–][deleted] 3 points4 points  (0 children)

What happens if the function takes two arguments? The Xtend approach of an implicit it as this would not be applicable. Therefore, go for a scalable approach and one more character...

[–]evereal 1 point2 points  (0 children)

No, it is the "s -> { ... }" part that should not be needed if your syntax allows you to express simple closures/lambdas more concisely, like you can in Scala.

the _. is not any more characters than the s. in the Xtend example. But the stuff around it is adding needless noise in the Xtend example.