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
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
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 ***
> 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.
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