From: taylanbayirli@gmail.com (Taylan Ulrich B.)
To: Dmitry Bogatov <KAction@gnu.org>
Cc: guile-user@gnu.org
Subject: Re: Define in let
Date: Tue, 20 Aug 2013 19:02:29 +0200 [thread overview]
Message-ID: <87a9kc9ty2.fsf@taylan.uni.cx> (raw)
In-Reply-To: <87k3jgb9kr.fsf@gnu.org> (Dmitry Bogatov's message of "Tue, 20 Aug 2013 20:39:32 +0400")
Dmitry Bogatov <KAction@gnu.org> writes:
> It seems following is invalid:
>
> (let ((a 2))
> (define (foo x) (+ a x)))
>
> I prefer to reduce scope of variable as much as possible, so
> I find this restriction unconvinent. Is is part of standard or technical
> limitation? Is it any workaround?
>
> Please, keep in CC, I am not subscribed.
>
> --
> Best regards, Dmitry Bogatov <KAction@gnu.org>,
> Free Software supporter and netiquette guardian.
> git clone git://kaction.name/rc-files.git --depth 1
> GPG: 54B7F00D
> Html mail and proprietary format attachments are forwarded to /dev/null.
No Scheme standard so far has supported such a thing, and neither Guile.
It would be neat, I had the idea too (it would allow re-use of the
semantics of `begin' and thus be coherent/orthogonal in a way), but I
think it's a non-trivial change, probably both to the implementation of
Guile and the semantics for `let' that have been well-understood ever
since very old Lisps: that `let' is a thin wrapper around a call to an
in-place `lambda'.
(let ((a x)
(b y))
...)
is just
((lambda (a b)
...)
x y)
in pretty much any Lisp.
Note that you can do
(define foo
(let ((a 2))
(lambda (x) (+ a x))))
and if you want to define multiple things that use that `a' binding, you
could use `define-values', but Guile doesn't have that yet (there's a
hacky in-Scheme definition in R7RS-small if you want something quick):
(define-values (foo bar)
(let ((a 2))
(values
(lambda (x) (+ a x))
(lambda (y) (* a y)))))
Taylan
next prev parent reply other threads:[~2013-08-20 17:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 16:39 Define in let Dmitry Bogatov
2013-08-20 16:57 ` Thompson, David
2013-08-20 17:02 ` Taylan Ulrich B. [this message]
2013-08-20 17:18 ` John B. Brodie
2013-08-20 17:19 ` Ian Price
2013-08-20 17:52 ` Mike Gran
2013-08-20 21:01 ` David Pirotte
2013-08-21 6:52 ` Panicz Maciej Godek
2013-08-21 6:55 ` Panicz Maciej Godek
2013-08-21 9:28 ` Ralf Mattes
2013-08-21 10:17 ` Panicz Maciej Godek
2013-08-21 10:32 ` Ralf Mattes
2013-08-21 11:01 ` Panicz Maciej Godek
2013-08-21 15:42 ` Dmitry Bogatov
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=87a9kc9ty2.fsf@taylan.uni.cx \
--to=taylanbayirli@gmail.com \
--cc=KAction@gnu.org \
--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).