Robert Strandh <strandh@labri.u-bordeaux.fr> wrote:
+---------------
| The construction:
|
| (let ((x 0))
| (defun f ()
| ...))
|
| in CL defines a global function with x in its environment. The way to
| do that in Scheme (I claim) is:
|
| (define foo)
| (let ((x 0))
| (set! foo (lambda () ...)))
+---------------
Actually, the standard idiom for this in Scheme is simply:
(define foo
(let ((x 0))
(lambda () ...)))
You only need "set!"s if you're going to create multiple closures
over shared variables:
(define foo #f)
(define bar #f)
(define baz #f)
(let ((x 0))
(set! foo (lambda () ...))
(set! bar (lambda () ...))
(set! baz (lambda () ...)))
But that's admittedly ugly, which is why some Schemes provide a
multiple-value top-level define, e.g., MzScheme:
(define-values (foo bar baz)
(let ((x 0))
(values
(lambda () ...)
(lambda () ...)
(lambda () ...))))
In Common Lisp, of course, the original example extends trivially:
(let ((x 0))
(defun foo () ...)
(defun bar () ...)
(defun baz () ...))
-Rob
-----
Rob Warnock, 30-3-510 <rpw3@sgi.com>
SGI Network Engineering <http://www.meer.net/~rpw3/>
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA
[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]