chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] my errors with eval


From: Jim Ursetto
Subject: Re: [Chicken-users] my errors with eval
Date: Tue, 2 Jul 2013 15:41:15 -0500

You can't access internal defines in an eval, just as you can't access the 
lexical variable "a".

To get around this you could use set! instead to "define" the variables at 
toplevel.

(let ((a 1))
 (set! inc (lambda () (set! a (+ 1 a)) (print a)))
 (set! runTwice (lambda (op) (op) (op)))
 (eval '(runTwice inc)))
(inc)
;; prints: 2 3 4

Notice `inc` is accessible outside the `let` here.

Otherwise you have to use something like the currently nonfunctional 
`environments` egg.

On Jul 2, 2013, at 2:26 PM, "Daniel Ajoy" <address@hidden> wrote:

> Hi,
> 
> Both this
> 
> (let ((a 1) )
>  (define (inc)
>       (set! a (+ 1 a ) ) )
>  (define (runTwice op )
>       (op)
>       (op) )
>  (eval '(runTwice inc ) )
>  )
> 
> and this
> 
> (let* ((a 1) )
>  (define (inc)
>       (set! a (+ 1 a ) ) )
>  (define (runTwice op )
>       (op)
>       (op) )
>  (eval '(runTwice inc ) )
>  )
> 
> Give me the error:
> 
> Error: unbound variable: runTwice
> 
> I'm defining runTwice right before running the eval. What am I not 
> understanding?
> 
> Daniel
> 
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users




reply via email to

[Prev in Thread] Current Thread [Next in Thread]