Subject: Re: the necessity of Lisp's Objects?
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 12 Feb 2008 05:34:01 -0600
Newsgroups: comp.lang.lisp,comp.lang.scheme,comp.lang.functional
Message-ID: <ho2dnQY1mbW0GSzanZ2dnUVZ_uKpnZ2d@speakeasy.net>
George Neuner  <gneuner2/@/comcast.net> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) wrote:
| >Well, true, but you can keep the internal name from escaping by
| >returning the function value, making it effectively "anonymous":
| >
| >    > (funcall
| >       (labels ((self (x) (if (< x 2) 1 (* x (self (1- x)))))) #'self)
| >       5)
| >
| >    120
| >    > 
| 
| Yes, I suppose that is anonymous in the way John intended.
| 
| It's a little more verbose in Scheme:
| 
|  ((lambda (x)
|    (let self ((x x)) 
|      (if (< x 2) 1 (* x (self (- x 1))))))
|   5)
|  120
| 
| but I think the Scheme makes it a little clearer that there is a named
| self referential function in an anonymous wrapper.  
+---------------

That's using the "named LET", though you also can do it in Scheme
almost exactly the same way I did in CL, by using LETREC instead
of LABELS and leaving off the FUNCALL:

    > ((letrec ((self (lambda (x) (if (< x 2) 1 (* x (self (1- x)))))))
	 self)
       5)
    120
    > 


-Rob

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