From: "Maciek Godek" <pstrychuj@gmail.com>
To: "Neil Jerram" <neiljerram@googlemail.com>
Cc: guile-user@gnu.org
Subject: Re: Closure?
Date: Sun, 13 Jul 2008 08:57:20 +0200 [thread overview]
Message-ID: <e2ceda030807122357p33ed8cbr78728754dba73872@mail.gmail.com> (raw)
In-Reply-To: <49dd78620807121557n5c7a1f3bs5a2c2788faca21a7@mail.gmail.com>
> Hi Maciek,
>
> Just picking up another point from your original email. You may have
> already worked this out, but just in case...
OK, it's always good to say to much than not to say enough
(at least if it comes to hacking ;])
>> Additionaly, it would be nice to see the possibility
>> of explicit definitions of environments, like:
>>
>> (define env (make-closure (a . 1)(b . 2))
>> (with env (define c 3))
>
> This is equivalent to:
> (define env (let ((a 1) (b 2)) (the-environment)))
> (local-eval '(define c 3) env)
>
> except that the last line fails with a "Bad define placement" error.
> That's because there are special rules for defines inside lexical
> scopes.
As the practise shows, although guile documentation says something
different. In section 3.1.4.7 (A Shared Persistent Variable)
"An important detail here is that the `get-balance' and `deposit'
variables must be set up by `define'ing them at top level and then
`set!'ing their values inside the `let' body. Using `define' within
the `let' body would not work: this would create variable bindings
within the local `let' environment that would not be accessible at top
level."
So one might conclude that it _is_ possible to use define inside
a 'let' form.
>> so that we could define the aforementioned
>> counter as:
>> (define counter-env (make-closure (c . 0)))
>> (define ++ (with counter-env (lambda()(set! c (1+ c))c)))
>
> This one really works:
>
> (define counter-env (let ((c 0)) (the-environment)))
> (define (++) (local-eval '(begin (set! c (+ c 1)) c) counter-env))
>
> So, in summary, make-closure wouldn't provide anything more than what
> we already have.
Yes, since there's local-eval and the-environment, everything I've
ever dreamed of is possible :)
But as I've concluded from the discourse, neither of these is
defined in R5RS (and it makes me wonder)
next prev parent reply other threads:[~2008-07-13 6:57 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Maciek Godek [this message]
2008-07-13 22:56 ` Closure? Neil Jerram
2008-07-14 1:15 ` Closure? Maciek Godek
[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 ` 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
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=e2ceda030807122357p33ed8cbr78728754dba73872@mail.gmail.com \
--to=pstrychuj@gmail.com \
--cc=guile-user@gnu.org \
--cc=neiljerram@googlemail.com \
/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).