guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Define in let


From: Taylan Ulrich B.
Subject: Re: Define in let
Date: Tue, 20 Aug 2013 19:02:29 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix)

Dmitry Bogatov <address@hidden> 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 <address@hidden>,
> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]