From: Drew McDermott
Subject: Final cond clause test other than 't'
Date: 
Message-ID: <1144779462.238214.122430@g10g2000cwb.googlegroups.com>
This is probably a silly question, but ....

Suppose I use ':else' or ':otherwise' instead of 't' as the default
clause in a 'cond'.  Is there any reasonable compiler that will produce
worse (or even different) code than it would for 't'?  The "reasonable"
compilers are those produced by vendors or maintained by serious groups
(e.g., Allegro, Lispworks, CMUCL, CLISP, ...).

Thanks.
               -- Drew McDermott

From: bradb
Subject: Re: Final cond clause test other than 't'
Date: 
Message-ID: <1144781080.730132.161430@e56g2000cwe.googlegroups.com>
The way I read the CLHS
(http://www.lispworks.com/documentation/HyperSpec/Body/m_cond.htm), the
first true form will be evaluated.  CLHS says true is anything not NIL.
 So I would guess that CLHS says this is OK.

Brad
From: Barry Margolin
Subject: Re: Final cond clause test other than 't'
Date: 
Message-ID: <barmar-AA4259.15510811042006@comcast.dca.giganews.com>
In article <························@e56g2000cwe.googlegroups.com>,
 "bradb" <··············@gmail.com> wrote:

> The way I read the CLHS
> (http://www.lispworks.com/documentation/HyperSpec/Body/m_cond.htm), the
> first true form will be evaluated.  CLHS says true is anything not NIL.
>  So I would guess that CLHS says this is OK.
> 
> Brad

He's not asking whether it's OK -- obviously it is.  I believe the gist 
of his question was whether compilers would generate worse code, because 
they recognize the T clause specially.

I believe any decent compiler will recognize any constant and generate 
efficient code for the "else" clause.  This is just a particular case of 
constant folding, which most optimizing compilers do.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: bradb
Subject: Re: Final cond clause test other than 't'
Date: 
Message-ID: <1144786402.718008.12300@j33g2000cwa.googlegroups.com>
> He's not asking whether it's OK -- obviously it is.  I believe the gist
> of his question was whether compilers would generate worse code, because
> they recognize the T clause specially.

True, I didn't read it closely enough.
From: William D Clinger
Subject: Re: Final cond clause test other than 't'
Date: 
Message-ID: <1144850215.714806.245780@i39g2000cwa.googlegroups.com>
Drew McDermott wrote:
> Suppose I use ':else' or ':otherwise' instead of 't' as the default
> clause in a 'cond'.  Is there any reasonable compiler that will produce
> worse (or even different) code than it would for 't'?

If so, it's a performance bug.  There is no more reason
for you to worry about this than about hundreds of other
potential performance bugs.

Unless, of course, you have reason to suspect this
particular performance bug in a system you're using.
In that case, I'd say it's possible but unlikely, and
should be easy to check by disassembling the code
for a couple of test cases.

Will