From ... Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!134.222.94.5!npeer.kpnqwest.net!nreader1.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: special forms. References: Mail-Copies-To: never From: Erik Naggum Message-ID: <3204471231889910@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 51 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 18 Jul 2001 18:53:53 GMT X-Complaints-To: newsmaster@Norway.EU.net X-Trace: nreader1.kpnqwest.net 995482433 193.71.66.1 (Wed, 18 Jul 2001 20:53:53 MET DST) NNTP-Posting-Date: Wed, 18 Jul 2001 20:53:53 MET DST Xref: archiver1.google.com comp.lang.lisp:13325 * 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 operator? The above boolean waste simply translates to this in at least one code walker: (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)) condition)) 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. #:Erik -- 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.