I think 'curry' is what you're looking for. Your 'adder' example could be
written as:

   : (de adder (@N) (curry (@N) (X) (+ X @N)))
   -> adder
   : (adder 3)
   -> ((X) (+ X 3))
   : (doc 'curry)  # for more info  :)

Hope that helps,
Erik



On Feb 7, 2017 10:04 PM, "pd" <eukel...@gmail.com> wrote:

> Hello,
>
> I wonder if there is any way to bind a free symbol in a lambda in order to
> pass the lambda to a defined function (for example)
>
> What I want to do is something like this:
>
> (de myf (f l) (f l))
>
> (let l 99 (myf '((x) (+ (car x) l)) (1 2)))
>
> I want it to return 100 but it fails with an error (1 2) number expected
>
> this is because free symbol l in lambda ((x) (+ (car x) l)) is not bind by
> let as pretended because of quoting of lambda
>
> In other words, I think the problem is quoting avoids let binding as in:
>
> (setq f (let n 10 '((x) (+ x n)))) -> ((x) (+ x n))
>
> but I want it to return -> ((x) (+ x 10))
>
> or using the typicall example:
>
> (de adder (n) '((x) (+ x n)))  ->  ((n) '((x) (+ x n)))
>
> so (adder 1) should return ((x) (+ x 1)) but it returns ((x) (+ x n))
>
> Is there any way to manage this?  Something similar to "expand" in newlisp
> will do the job:
>
> newlisp:
>    (define (badadder n) (lambda (x) (+ x n)))
>    (badadder 3) -> (lambda (x) (+ x n))
>    (define (adder n) (expand (lambda (x) (+ x n)) 'n))
>    (adder 3) -> (lambda (x) (+ x 3))
>
> The fist example in newlisp will be:
>
> (define (myf f l) (f l))
>
> (let ((l 99)) (myf (lambda (x) (+ (first x) l)) '(1 2)))
>
> which fails for same reason picolisp fails but in newlisp the solution is:
>
> (define (myf f l) (f l))
>
> (let ((l 99)) (myf (expand (lambda (x) (+ (first x) l)) 'l) '(1 2)))  ->
> 100
>
>
> thanks
>
>
>

Reply via email to