unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Maciek Godek" <pstrychuj@gmail.com>
To: guile-user@gnu.org
Subject: Re: Closure?
Date: Sun, 13 Jul 2008 08:59:18 +0200	[thread overview]
Message-ID: <e2ceda030807122359y437af188n35748419b355832f@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0807121332010.5348@ttleush>

>> 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
>> explicit)
>>
>
> Adding is easy:
>
> (define (add-var-to-environment env name val)
>  (local-eval `(let ((,name ,val)) (the-environment))
>              env))
>
> (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
for.




  reply	other threads:[~2008-07-13  6:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cmu-lmtpd-26382-1215792454-10@mail-imap1.uio.no>
2008-07-11 17:42 ` Closure? Kjetil S. Matheussen
2008-07-11 17:47   ` Closure? Kjetil S. Matheussen
2008-07-11 20:54     ` Closure? Maciek Godek
2008-07-12 11:47       ` Closure? Kjetil S. Matheussen
2008-07-13  6:59         ` Maciek Godek [this message]
2008-07-12 22:43     ` Closure? Neil Jerram
2008-07-15  7:59       ` Closure? Ludovic Courtès
2008-07-15  9:11         ` Closure? Andy Wingo
2008-07-16 16:42           ` Closure? Ludovic Courtès
     [not found] <cmu-lmtpd-15105-1216051603-3@mail-imap1.uio.no>
2008-07-14 16:30 ` Closure? Kjetil S. Matheussen
2008-07-14 21:14   ` Closure? Maciek Godek
     [not found]   ` <e2ceda030807141414i5acef7d1h37d12d14e01cc1d@mail.gmail.com>
2008-07-14 21:41     ` Closure? Kjetil S. Matheussen
2008-07-14 22:46       ` Closure? Maciek Godek
2008-07-11 14:48 Closure? Maciek Godek
2008-07-11 15:01 ` Closure? Ludovic Courtès
2008-07-11 15:32   ` Closure? Maciek Godek
2008-07-12 22:57 ` Closure? Neil Jerram
2008-07-13  6:57   ` Closure? Maciek Godek
2008-07-13 22:56     ` Closure? Neil Jerram
2008-07-14  1:15       ` Closure? Maciek Godek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2ceda030807122359y437af188n35748419b355832f@mail.gmail.com \
    --to=pstrychuj@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).