guile-user
[Top][All Lists]
Advanced

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

Re: Closure?


From: Maciek Godek
Subject: Re: Closure?
Date: Fri, 11 Jul 2008 22:54:35 +0200

Kjetil S. Matheussen:

> The function "local-eval" is probably what you want.
>
> I use local-eval a lot, it's one of the really really
> nice features provided by Guile:
>
>
> (define-macro (with env . code)
>  `(local-eval (quote (begin ,@code)) ,env))
>
>
> (define ++
>  (let ((c 0))
>    (c-display "env" (the-environment))
>    (lambda()
>      (set! c (1+ c)) c)))

I don't actually get the line with c-display.
Does it require any additional module?
'Cause it ain' workin' for me.
(and besides what does it do?
the remaining part works fine)

> (++)
> => 1
> (with (procedure-environment ++) (set! c 20))
>
> (++)
> => 20

I'm really impressed :) Great respect!

I only wonder if there's a way to add a new
variable to an existing closure, or to delete one.
(not that I need it right now; but I imagine that
it can be implemented quite easily and efficiently
in C if the notion of closure is well-defined and
explicit)




reply via email to

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