views:

85

answers:

2

What kind of advantages are there to changing 'cond' to be a special form instead of syntactic sugar?

A: 

cond is a special form because the parameters must not be evaluated until they have to.
Very important. And if I'm not mistaken, Scheme didn't have an if form originally.
Actually the if form could be syntactic sugar with the use of macros.

Nick D
+5  A: 

In one of the landmark papers on Scheme (Lambda the Ultimate Declarative, §1.2), Steele writes:

However, there is no denying that IF-THEN-ELSE seems to be the simplest conditional control operator easily capable of expressing all others.

Then he writes in §4.1:

Although I propose to construct only the lower-level portion of the compiler, plus the necessary macros to provide standard LISP features such as COND and PROG, one could easily imagine constructing an ALGOL compiler, for example, by providing a parser plus the necessary macros as a front end.

The point that Steele tries to make in this and other papers, including his MS thesis on the Rabbit compiler, is that if is simpler than cond, and in general it makes more sense to macro-expand library syntax as cond and case into simpler essential syntax like if. That way you keep the input language your compiler needs to understand simple, which has the advantage that it is easier to reason about, implement and optimize. It all fits in the minimalist design of Scheme I guess.

Superficially, one could be tempted into thinking that cond can be compiled more optimally (think switch table). As with all issues regarding "optimization" without actual data or proof, this could turn out to be a premature conclusion and in fact I would not bet my money on this being true.

Therefore, to answer your question, I see no real or lasting advantages to making cond essential syntax instead of a macro in Scheme. Or, if there would be advantages, there would at least be some disadvantages like a more complex evaluator.

eljenso