[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LET-IF



    Date: Tue, 26 Nov 85 08:42 EST
    From: Bernard S. Greenberg <BSG@SCRC-STONY-BROOK.ARPA>

	Date: Mon, 25 Nov 85 14:08 PST
	From: Richard Lamson <rsl@RUSSIAN.SPA.Symbolics.COM>

	    Date: Fri, 22 Nov 85 20:41:51 EST
	    From: "George J. Carrette" <GJC@MIT-MC.ARPA>

	    Funny you should mention that, I'm considering flushing quite a few
	    special forms in the LMI system and replacing them with macros, LET-IF
	    is one, and the following definition seems right:

	    (defmacro let-if (pred bindings &body body)
	      (let ((f (gentemp "f")))
	       `(flet ((,f () ,@body))
		   (if ,pred (let ,bindings (,f)) (,f)))))

	Unfortunately, this doesn't work if you want the bindings to be lexical
	instead of special bindings.  Consider:

	   (defun xor (a b)
	     (let-if a ((b (not b)))
	       b))

	Unless B is special, this won't work using your scheme.

    I can't imagine what LET-IF would mean with lexical variables
    no matter what the implementation.

    Date: Tue, 26 Nov 85 08:42 EST
    From: Bernard S. Greenberg <BSG@SCRC-STONY-BROOK.ARPA>

	Date: Mon, 25 Nov 85 14:08 PST
	From: Richard Lamson <rsl@RUSSIAN.SPA.Symbolics.COM>

	    Date: Fri, 22 Nov 85 20:41:51 EST
	    From: "George J. Carrette" <GJC@MIT-MC.ARPA>

	    Funny you should mention that, I'm considering flushing quite a few
	    special forms in the LMI system and replacing them with macros, LET-IF
	    is one, and the following definition seems right:

	    (defmacro let-if (pred bindings &body body)
	      (let ((f (gentemp "f")))
	       `(flet ((,f () ,@body))
		   (if ,pred (let ,bindings (,f)) (,f)))))

	Unfortunately, this doesn't work if you want the bindings to be lexical
	instead of special bindings.  Consider:

	   (defun xor (a b)
	     (let-if a ((b (not b)))
	       b))

	Unless B is special, this won't work using your scheme.

    I can't imagine what LET-IF would mean with lexical variables
    no matter what the implementation.

I can imagine: (let-if a ((b (not b))) (f b)) means

	(if a (let ((b (not b))) (f b)) (f b)).

But in most such cases I should imagine

	(let ((b (if a (not b) b))) (f b))

would do just as well (and result in better code), because a redundant
bindings of b to iself doesn't hurt in the lexical case (whereas it is
not allowed in the special case, as it would result in visibly different
semantics).