Hi Christopher,

> (de make-adder (N) (list '(X) (list '+ 'X N)))
> 
> That works, but I was wondering if there was some more readable way to
> do it.

Well, the standard candidate for that purpose is 'curry' (though we learned that
this function name is a bit unlucky ;)

   (de make-adder (N)
      (curry (N)
         (X) (+ X N) ) )

In this call, 'N' is kept in a closure, allowing it to be changed while the
generated function runs:

   (make-adder 7)
   -> ((X) (job '((N . 7)) (+ X N)))

This is here not necessary, thus 'curry' allows you to tell it when
values are constant by using pattern variables, here '@N':

   (de make-adder (@N)
      (curry (@N)
         (X) (+ X @N)) )

   (make-adder 7)
   -> ((X) (+ X 7))


Another option (in addition to your direct 'list'ing, is 'fill'

   (de make-adder (N)
      (fill '((X) (+ X N)) 'N) )

   (make-adder 7)
   -> ((X) (+ X 7))

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to