Le 20/11/2012 04:33, Jacob Carlborg a écrit :
On 2012-11-20 08:48, thedeemon wrote:

This is just an old habit to see identifier with parens as a function
call and identifier without parens as a variable, so calling functions
without parens seem too unconventional to you. However there are many
languages which dropped this tradition and they are known for being
expressive and concise, that's why people love them. Recently we saw an
article from Walter about component programming which one could say was
really about function composition. It's really convenient to write code
in conveyor-style, this is what we see often in functional languages, as
well as some dynamic OO ones. For example, the task of reversing words
in a string may look like:

I completely agree.

"one two three".split.map{|s| s.reverse}.join(' ')
in Ruby

In this particular case you can use a shorter form of the map call:

"one two three".split.map(&:reverse).join(' ')

print . unwords . map reverse . words $ "one two three"
in Haskell

"one two three" |> split " " |> List.map reverse |> String.join " " |>
print_string
in OCaml
and something similar and even without dots in Scala.

Wouldn't the Scala syntax look fairly similar to Ruby:

"one two three".split.map(reverse).join(' ')


Note the map(reverse) and not map(&reverse)

Ease of chaining functions together is one of the things that make those
languages so pleasant to work with. I love to have the same in current D
and it would be a pity to lose it due to a clash with some old-fashioned
tradition.

I completely agree again.


Reply via email to