unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Kjetil S. Matheussen" <k.s.matheussen@notam02.no>
To: guile-user@gnu.org
Subject: Re: Closure?
Date: Fri, 11 Jul 2008 19:42:40 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0807111939020.5259@ttleush> (raw)
In-Reply-To: <cmu-lmtpd-26382-1215792454-10@mail-imap1.uio.no>



Ludovic Court?s:
> "Maciek Godek" <pstrychuj@gmail.com> writes:
>
>> I've been wondering if there's any way to recall
>> (or get inside) an environment of a closure (= to
>> directly access variables bound to a closure)
>
> Yes, with `the-environment':
>
>  guile> ((lambda (a b) (the-environment)) 2 3)
>  (((a b) 2 3) #<eval-closure b7c6dcf8>)
>
> But don't do that, since the representation of environments could
> eventually change.
>

Please don't change it. :-)
It's one of those things which makes Guile special.



Maciek Godek:
>
> Don't worry, I won't :)
> Now I only know how to obtain environment of a closure,
> but I still don't know how to get inside and modify it (I'm
> lacking this `with' I wrote about).
>

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)))

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

(++)
=> 20






       reply	other threads:[~2008-07-11 17:42 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 ` Kjetil S. Matheussen [this message]
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         ` Closure? Maciek Godek
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=Pine.LNX.4.64.0807111939020.5259@ttleush \
    --to=k.s.matheussen@notam02.no \
    --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).