Arc Forumnew | comments | leaders | submitlogin
1 point by rocketnia 5177 days ago | link | parent

Why not make all Arc curry-able(?) by convention?

I think that's the way to go if you like currying. Otherwise it's sort of a technique for peeling oranges in a language full of apples.

Nevertheless, I've thought about currying a bit myself, just 'cause it comes up on this forum so much. The following code is the culmination of where I usually end up, in my mind: http://gist.github.com/644503.

In a nutshell, the technique is to have functions keep track of some arity information so that they can be used in lisp-style calls as well as being transformable into curried versions. Using 'defcall in Anarki or Rainbow, we can define a new Arc type that behaves like a function but carries the necessary information.

Once my code is loaded, you can use >.2 and <.1 just as you'd like. I overwrite them explicitly so that they're of type 'curryable instead of 'fn, and you can do the same thing to other functions as desired, just as long as the currying code doesn't depend on them (so that you don't get infinite loops). You can also curry functions you haven't overwritten, using cur.3.union.is to describe the arity on a call-by-call basis.

  arc> (map >.2 '(1 2 3 4 5))
  (t nil nil nil nil)
  arc> (map <.1 '(1 2 3 4 5))
  (nil t t t t)
  arc> (map cur.2.apply.apply `((,+ (1 2 3)) (,* (1 2 3))))
  (6 6)
  arc> (map [apply apply _] `((,+ (1 2 3)) (,* (1 2 3))))  ; clearer?
  (6 6)
I've never bothered to put this into code before just 'cause I don't have a lot of oranges to deal with from day to day, but maybe it'll be useful for you. ^_^


3 points by rocketnia 5177 days ago | link

Incidentally, I'm pretty sure (< x) has its current behavior so that (apply < lst) has a simple description: It always returns t if 'lst is increasing and nil if it isn't.

That being said, redefining '< this way isn't all that bad. The result of (apply < '(1)) ends up being a procedure, which still counts as a true value!

That being said, there may still be a problem if humans consistently have trouble simplifying (map >.2 '(1 2 3 4 5)). :-p

-----