Subject: Re: Ask a question about internal function
From: (Rob Warnock)
Date: Thu, 22 May 2008 21:33:53 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Mark Wooding  <> wrote:
| Rob Warnock <> wrote:
| > [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.
| I think you can always convert a Scheme LETREC into Common Lisp
| of the form
|   (let (...)
|     (labels (...)
|       (setf ...)
|       ...))
| There's a complication in working out a good ordering of the
| assignments in the SETF form.  But R5RS imposes a restriction ...

Ah, yes, of course, thanks!! And actually, becasue of that restriction,
and also because you can't [AFAIK] redefine LABELS functions with
a SETF, I don't think you need the SETF at all. Just put all the
variable bindings in the LET (*with* their initializers) and the
function bindings in the LABELS, and you're done.

Hmmm... This may mean that the full generality of the semantics
of Scheme LETREC *cannot* be expressed in CL!! For example, the
following is legal Scheme [albeit pathologically atypical!]:

    > (letrec ((a 45)
	       (b (lambda (x) (+ x 12)))
	       (c '()))
	(set! c a)
	(set! a b)
	(set! b (lambda (x) (* x 3)))
	(b (a c)))

The closest I can get to that in CL is this brokenness:

    > (let ((a 45)
	    (c nil))
	(labels ((b (x) (+ x 12)))
	  (setf c a)
	  (setf a #'b)
	  (setf (fdefinition #'b) (lambda (x) (* x 3))) ; *ILLEGAL!!*
	  (b (funcall a c))))

    Invalid function name: #<Interpreted Function (LABELS B) {48948AC1}>
    [Condition of type SIMPLE-TYPE-ERROR]

      0: [ABORT] Return to Top-Level.

    Debug  (type H for help)

Oh, well...  ;-}


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607