Subject: Re: how to define a local function
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 13 Apr 2007 20:16:36 -0500
Newsgroups: comp.lang.lisp
Message-ID: <YZadnabA6aHptr3bnZ2dnUVZ_s2vnZ2d@speakeasy.net>
Pascal Costanza  <pc@p-cos.net> wrote:
+---------------
| Rob Warnock wrote:
| > Pascal Costanza  <pc@p-cos.net> wrote:
| > +---------------
| > | If you want to see the bindings in both function and variable 
| > | namespaces, you can easily do the following as well:
| > +---------------
| > 
| > But then you would get inconsistences between the Scheme & CL
| > versions if there were ever an assignment to one of the variables.
| 
| I don't think there would be any inconsistencies. Note that I have 
| defined macros for the function namespace, so any assignment to the 
| variables would be respected.
+---------------

In Scheme, this is legal:

    > (letrec ((a (lambda (x) (+ x 3))))
	(let ((old-a-result (a 2)))
	  (set! a (lambda (x) (+ x 17)))
	  (list old-a-result (a 2))))

    (5 19)
    >

The same [well, ignoring SET! vs SETF] wouldn't work with
your dual value/function LETREC [you get (5 5)], since the
SETF would only change the value binding, but *would* work
with a values-only LETREC if one referenced the bound function
values *only* with FUNCALL (or my APPLY idiom).

Anyway, it's not a biggy... Lisp1 & LispN are too far apart
to merge with simple hacks like that anyway.

Summary/recap/call-for-end-of-thread: I was just trying to
point out that even though CL's LABELS *does* provide the same
self- & mutually-recursive bindings for fuctions that Scheme's
LETREC does for functions, for value bindings CL *doesn't*
have a direct native equivalent... but that an equivalent macro
could be defined [which you demonstrated, thanks].


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607