[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sun, 13 Jul 2008 08:59:18 +0200
>> 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)
> Just ignore that one. c-display is just a debugging
> function I forgot to remove. :-)
OK, actually that's exactly what I did :D
>>> => 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
> Adding is easy:
> (define (add-var-to-environment env name val)
> (local-eval `(let ((,name ,val)) (the-environment))
> (define env (add-var-to-environment (the-environment) 'a 50))
> (local-eval 'a env)
> => 50
Bravo! Gee, thanks a lot!
> I don't know if there's possible to delete a variable
> in a clean way.
That's nothing urgent. The thing is that I started to
perceive the global environment as a special closure
(I think it could be a nice generalization) and in that
model, the "define" and "undefine" forms could
operate within the nearest scope, which could make
the following constructs legal:
(with env (define x 20))
(with env (undefine x))
That would be freakin' cool.
I imagine that there could be a way to redefine
"define" inside a closure env (and perhaps
to invent an non-portable solution to undefine),
but I'd prefer to leave this idea to the ones who
implement guile's internals, so that there's only
one "define" operating on different scopes.
(Or maybe it only seems so simple...)
Thanks once again for showing me the power of
local-eval, for it's so close to what I've been looking
Re: Closure?, Kjetil S. Matheussen, 2008/07/14
- Re: Closure?, (continued)
- Re: Closure?, Kjetil S. Matheussen, 2008/07/11
- Re: Closure?, Neil Jerram, 2008/07/12
- Re: Closure?, Ludovic Courtès, 2008/07/15
- Re: Closure?, Andy Wingo, 2008/07/16
- Re: Closure?, Ludovic Courtès, 2008/07/16
- Re: Closure?, Maciek Godek, 2008/07/14
- Message not available