David Rush <kumo@bellsouth.net> wrote:
+---------------
| froydnj@rose-hulman.edu (Nathan Froyd) writes:
| > >1. (define (func_1 arg) (stuff with arg) )
| > >2.: (define func_1 (lambda (arg) (stuff with arg)))
| >
| > They're equivalent ways of expressing the same thing...
|
| Well, there are compilers that do better error-checking with form 1...
+---------------
But there are also compilers that are "smart" about form 2 as well. E.g.,
MzScheme "infers" names for procedure values (closures) depending on the
context in which the procedure was created. <URL:http://www.cs.rice.edu/
CS/PLT/packages/doc/mzscheme/node85.htm> has the gory details, but MzScheme
tries fairly hard to "get it right":
> (define foo
(lambda (x) (list x 1)))
> foo
#<procedure:foo>
> (define bar
(let ((gorp (lambda (y) (+ y 3))))
gorp))
> bar
#<procedure:gorp>
> (define baz 'not-yet)
> (set! baz (lambda (x) (/ x 2)))
> baz
#<procedure:baz>
>
Though of course there are limits to what one can reasonably infer,
and in such cases the procedure ends up being truly anonymous:
> (let ((baz-setter! (lambda (x) (set! baz x))))
(baz-setter! (lambda (z) (* z 1.5))))
> (baz 2)
3.0
> baz
#<procedure>
>
-Rob
-----
Rob Warnock, 31-2-510 rpw3@sgi.com
SGI Network Engineering http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA