On Wed, Feb 08, 2017 at 01:57:22PM +0100, pd wrote: > *I feel* curry to be a unfortunate name for that function because I expect > curry to be a function that once applied to another function with n > parameters it returns a chain of applying functions with exactly one > argument, that is having: > > : (de sum (x y) (+ x y)) > > I expect a function named curry to behave this way: > > (curry 'sum) -> ((x) '((y) (+ x y))) # it is really pseudocode not > actually picolisp code since returning a lambda quoted this way won't do > the job > > or in classical lisp notation: > > (curry 'sum) -> (lambda (x) (lambda (y) (+ x y))) > > in a way you now can apply the curryfied sum partially: ((curry 'sum) 2) > -> ((y) (+ 2 y)) or totally: ((curry 'sum) 3 4) -> 7 > > But picolisp curry function doesn't do that, it simply returns a lambda
You can easily use PicoLisp's 'curry' to built the classical curry (de classiCurry (Fun) (let Par (list (caar Fun)) (list Par (cons 'curry Par (cdar Fun) (cdr Fun)) ) ) ) For your example (I use 'add' instead of 'sum' because the latter is built-in): : (de add (X Y) (+ X Y)) -> add : (classiCurry add) -> ((X) (curry (X) (Y) (+ X Y))) : ((classiCurry add) 2) -> ((Y) (job '((X . 2)) (+ X Y)) If you know that your function does not modify the values of its parameters, you can use pattern variables to get more efficient code with constants and no need for a 'job' closure: : (de add (@X Y) (+ @X Y)) -> add : (classiCurry add) -> ((@X) (curry (@X) (Y) (+ @X Y))) : ((classiCurry add) 2) -> ((Y) (+ 2 Y)) In both cases you get: : (((classiCurry add) 2) 3) -> 5 ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe