Arc Forumnew | comments | leaders | submitlogin
4 points by cchooper 6098 days ago | link | parent

Do you mean something like this?

  (mac fix rest
    (withs (rest-parm (if (is '_ (last rest)) (uniq))
            parms rest-parm
            body nil
            rev-rest (if rest-parm (cdr (rev rest)) (rev rest)))
           (trav rev-rest 
                 (fn (x) (if (is '_ (car x))
                             (w/uniq u (push u parms) (push u body))
                             (push (car x) body)))
                 [self (cdr _)])
           `(fn ,parms ,(if rest-parm 
                            (join (list 'apply) body (list rest-parm))
                            body))))
If so I'm going to push it to the wiki.


1 point by tokipin 6098 days ago | link

actually i don't understand any of that ^_^;; i'm a lisp noob. in other languages there aren't macros so i implement it as a function which stores the function-to-be-curried and its initial arguments in a closure

however i tested your macro with some arithmetic and it all seems to work fine. the only thing i found is that something like this will cause an error:

  ((fix + _ 2) 3 4)
because there isn't an underscore at the end. i don't understand lisp enough to see if that was your intention. i think for the sake of variadic functions it should adapt regardless of where the underscore is (or whether or not it's present, eg: (fix +)), either by detecting if a function is variadic (which i'm guessing isn't reasonably possible at the moment) or by always returning a variadic function [edit: actually i think i can decipher the meaning of (if (is '_ (last rest))]

if the generated expression is always variadic, it would seem to mess with the fact that the underlying system cares how many arguments there are. is that a big deal? i don't think so. a language i use this function in is Lua, whose functions are all variadic (in that the interpreter doesn't complain if you supply too few (unsupplied are niled) or too many (excess are discarded) arguments) and it simply is never a problem. to me the fixed-argument thing seems similar in spirit to static typing in that it tries to solve a problem that really isn't significant

-----

2 points by cchooper 6097 days ago | link

Yes, I implemented it so it would only be variadic if there was an underscore at the end. It would actually be a simpler macro if they were always variadic, but that's such a radical change to the language that I'm a bit wary about it.

But maybe it's a good idea. I see your point about the 'spirit of static typing'. I'll have to check out Lua and see how it works out.

Edit: I mean it would be radical if fix were implicit, of course.

-----