Subject: Re: Ask a question about internal function
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 22 May 2008 02:52:11 -0500
Newsgroups: comp.lang.lisp
Message-ID: <f9KdnRAYEae2u6jVnZ2dnUVZ_szinZ2d@speakeasy.net>
Blackguester  <blackguester@gmail.com> wrote:
+---------------
| Actually, I migrate some code from scheme with just replace the
| define with defun, and just wonder why this can't work in lisp.
+---------------

Because despite their strong surface similarities, Scheme and
Common Lisp really are *different* languages -- not just a few
keywords or function names different, but structurally different
and with different semantics [at least in places].

Also, the "internal DEFINE" in Scheme -- that is, a DEFINE inside
a <body> [as defined in the spec] -- is IMHO a very confusing
construct for newbies, since it's *really* not a "DEFINE" at all
but an implicit alias for a LETREC, see:

    http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.3

Now it happens to be the case that Common Lisp has no *exact*
equivalent for the full generality of LETREC [that is, binding
both recursive functions & local values intermingled within the
same binding form], though for bindings of functions the Common
Lisp LABELS form offers the same ability as LETREC to define
mutually-recursive functions, and the Common Lisp LET* form
offers the ability to perform variable bindings for which the
value-initializing expression can refer to earlier variable
bindings within the same LET*. So you can get the equivalent
semantics, though translating a pathologically-convoluted LETREC
might need several LABELS and/or LET* forms to get the same
resultant semantics.[1]


-Rob

[1] Hmmm... You *might* always be able to do it with only one
    SYMBOL-MACROLET form containing only one LABELS form, where
    the former defines some of the "variables" to be function
    calls of dummy functions in the latter returning quasi-contant
    values...  But I haven't verified that to be sure.

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