Arc Forumnew | comments | leaders | submitlogin
7 points by lojic 5883 days ago | link | parent

What you're suggesting is closer to the way Ruby does it with the function being last:

  [1, 2, 3].map {|x| x * x }   # OR

  [1, 2, 3].map do |x|
    # larger function
  end
However, I think (map f list) is preferred since you're applying the function to the list. It's also the way Haskell does it, so it must be right :)


4 points by tel 5883 days ago | link

Haskell chooses this order because partial application and pointfree style are really common.

   let squareall = map (^2)
   squareall [1,2,3] ===> [1,4,9]
   squareall [3,4,5] ===> [9,16,25]
   let f = foldr1 (+) . squareall . filter even
   f [1,2,3,4,5] ===> 20
But since partial application is not a default behavior in Arc ([map square] and [map _ square] are not that different from one another) the order of the fn and list aren't as important.

Rule of thumb might be: put the fastest changing piece last, but this syntax thing might be a stronger heuristic.

-----