Subject: Re: special forms.
From: Erik Naggum <>
Date: Wed, 18 Jul 2001 18:53:53 GMT
Newsgroups: comp.lang.lisp
Message-ID: <>

* Geoff Summerhayes
> How about:
> (defun my-if (test then else)
>   (or (and test then)
>       (and (not test) else)))

  How about figuring out a way that does not involve the IF special

  The above boolean waste simply translates to this in at least one code

(let ((#:g66 (if (not test) (progn nil) (if t (progn then) nil))))
  (if #:g66 #:g66 (if t (progn (if (not (not test)) (progn nil) (if t (progn else) nil))) nil)))

  But it can be optimized into only _three_ ifs, instead of the original
  one.  This is impressing.  Somebody should use this to demonstrate the
  power of Lisp macros or something.  But since we already accept to have
  an if that the compiler knows about, the function if can simply be written

(defun if (condition consequent alternate)
  (if condition consequent alternate))

  However, if we pass lambda forms to if instead of expressions, this might
  actually work pretty nicely, even throwing in the ability to access the
  value of the condition for free:

(setf (getf 'nil 'boolean-index) 0)
(setf (getf 't   'boolean-index) 1)

(defun if (condition consequent alternate)
  (funcall (nth (getf (not condition) 'boolean-index) (list consequent alternate))

  When actually implemented, the boolean-index thing would naturally be
  handled more efficiently, and nth would probably use a hardware repeat
  instruction so we would not need hardware support for conditional
  branching at all.  That would be _so_ nice.  We can now do away with if.
  Or, _Scheme_ can do away with if now that it is proven to be possible to
  implement this not-at-all-primitive with some _real_ primitives.  That I
  basically reinvented the computed goto from Fortran badly should not make
  anyone feel particularly ashamed, should it?

  In other words: Enough already.

  There is nothing in this message that under normal circumstances should
  cause Barry Margolin to announce his moral superiority over others, but
  one never knows how he needs to behave to maintain his belief in it.