Arc Forumnew | comments | leaders | submitlogin
Curried functions with undefined numbers of arguments
3 points by tel 6119 days ago | 4 comments
I've only just begun to play with Arc, so this might either be nonsense because of feature conflict or because there is a better method, but I want to see this:

   arc> ([+] 1 2 3 4 5) 
   15
   arc> ([in 'a] 'a 'b 'c 'd 'e)
   t
   arc> ([- _ 4] 5 3)
   -2
I.e. the last one translates to (- 5 4 3).

The only other language I've used which implement function shorthand like that was Haskell, which obviously doesn't have this opportunity because of its type system, but I think it's a logical default behavior.

With Arc's assumption of the Smart Programmer this default behavior is more useful than the error message.



1 point by Zak 6118 days ago | link

As chrisdone pointed out, your first two examples actually add complexity. The last one doesn't make sense. You've written a function that takes and argument and subtracts four from it. One would expect this function to return an integer, not a function.

Don't get me wrong - I'm all for partial application. See my suggestion on it here: http://arclanguage.org/item?id=645

-----

1 point by chrisdone 6119 days ago | link

In your above example I'm not exactly sure how it is different from just saying:

arc> (+ 1 2 3 4 5) 15 arc> (in 'a 'a 'b 'c 'd 'e) t arc> (- 5 4 3) -2

I.e. what power is gained from it?

Do you have any more examples?

-----

1 point by tel 6118 days ago | link

These examples were poor, sorry. I'd only just started the tutorial and I didn't want to guess function names too much.

A slightly better, though still trivial, example:

   (map [+ 5] 
        (list (range -3 0)
              (range 1 3)
              (range 3 5)))
becomes

   (map (fn (nums) (apply + (cons 5 nums)))
        (list (range -3 0)
              (range 1 3)
              (range 3 5)))
Though, normally, you might write something akin to:

   (map (fn (nums) (+ 5 (apply + nums)))
        ...)
It's a lot like Zak's suggestion, just noting that sometimes n is infinite. Full partial application is really powerful -- especially with the general trend in Arc to have the final argument be the most dynamic one -- and I regret that I don't really have time at the moment to make an interesting example.

-----

2 points by Zak 6118 days ago | link

You're now taking a list of lists and trying to add a number to each list. That should fail - partial evaluation or no. There's no sane way for the first expression to translate in to the second.

-----