Arc Forumnew | comments | leaders | submitlogin
1 point by rincewind 5705 days ago | link | parent

clickable link: http://arclanguage.org/item?id=7788

I wrapped the currying and arity with a macro in my code:

  (mac defc (name args . body)
    `(do (def ,name ,args ,@body)
         ,(errsafe:let arity (len args)
                 `(zap [curry ,arity _] ,name))))
Having to specify which functions are curried is not a problem for me, because I mostly use it for combinators, but this simple macro does not integrate with defm or pat-m (yet).

  (defc flip (fun a b)
     (fun b a))

  (defc times (n f)
     [do (repeat n (zap f _)) _])

  ((flip times cdr) 4 '(a b c d e)) 
  => (e)
  ;(flip times cdr) is nthcdr
these examples should work with drcodes currying too, just use def instead of defc.


1 point by almkglor 5705 days ago | link

> but this simple macro does not integrate with defm or pat-m (yet).

It doesn't have to: the 'p-m modifier will adapt to it. All it needs is an args . body somewhere at the end of your macro's arg list - which you do have. p-m will then be able to adapt.

-----

1 point by rincewind 5704 days ago | link

All patterns would have to be of the same length, and ideally they should be ll(1) patterns, so they could dispatch on the first arg. Or should the pattern matching occur after the function got all of its arguments?

What I would really like to see is currying with partial function application and dispatch on every function argument, so that (my-curried-fun (annotate 'foo val)) is evaluated to a curried function for the type foo. Otherwise the (types|patterns) would have to be compared everytime this function is applied, which may be inefficient, e.g in

  (map (my-curried-fun (annotate 'foo val)) my-large-list)
This may be difficult to implement without a change in the interpreter or in p-m and curry/defc.

-----