Subject: Re: the necessity of Lisp's Objects?
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 11 Feb 2008 02:56:22 -0600
Newsgroups: comp.lang.lisp,comp.lang.scheme,comp.lang.functional
Message-ID: <F4mdnWlBPvorkC3anZ2dnUVZ_ryqnZ2d@speakeasy.net>
George Neuner  <gneuner2/@/comcast.net> wrote:
+---------------
| "David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au> wrote:
| >Jon Harrop <usenet@jdh30.plus.com> wrote: 
| >> Actually, I can't think of any other languages that support recursive
| >> anonymous functions anyway: none of Lisp, Scheme, SML, OCaml, F# and
| >> Haskell do AFAIK.
| >
| >You can do anonymous recusion in Lisp and Scheme via letrec.  Any
| >language where you can implement the Y-combinator you can get
| >anonymous recursion.
| 
| Lisp doesn't have letrec - you use labels instead.  And technically
| the functions are not anonymous because the forms require you to bind
| or name them.  A function has to be named or symbol bound to be
| recursive - else no way to refer to itself.
+---------------

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
    > 

Or, unfolded to show that the function really *is* "anonymous":

    > (labels ((self (x) (if (< x 2) 1 (* x (self (1- x)))))) #'self)

    #<Interpreted Function (LABELS SELF) {48987EE1}>
    > (fboundp 'self)

    NIL
    > (funcall ** 5)

    120
    > (funcall *** 10)

    3628800
    >

Perhaps David Formosa was referring to this sort of thing...?


-Rob

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