Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!spool.mu.edu!news.cs.indiana.edu!jashley@cs.indiana.edu
From: "J. Michael Ashley" <jashley@cs.indiana.edu>
Subject: Re: Use of 'else'
Message-ID: <1995Mar19.084557.17948@news.cs.indiana.edu>
Organization: Computer Science, Indiana University
References: <3kda86$1r1@canyon.sr.hp.com> <3kea6m$r9l@news.xmission.com>
Date: Sun, 19 Mar 1995 08:45:53 -0500
Lines: 38

In article <3kea6m$r9l@news.xmission.com>,
Michael Callahan <callahan@xmission.xmission.com> wrote:
>Bob Waltenspiel (bobw@sr.hp.com) wrote:
>: I have a question about using 'else'.  I've used it to signify the
>: default clause of a cond expression, but my instructor doesn't like
>: it.  He suggests I should be using #t exclusively.  I'm trying to
>: understand his reasoning and ask the net for help.
>
>Because it's just a hack, and tends to hide what is really going on
>by covering it up with an extra symbol.  If the identifier else is
>not used anywere else in the code where it may conflict, it is a
>simple matter to do (define else #t) to get the same result.

I disagree that you should use #t to signal the end of a cond, because
you can in fact use #t in any clause.  You have the same problem with
the (define else #t) hack.  'else' is a useful keyword to signal the
last clause of a cond, and its use should be constrained by the cond
macro.  For example this definition of cond,

    (define-syntax cond
      (syntax-rules (else)
        ((cond (else e0 e1 ...))
         (begin e0 e1 ...))
        ((cond (test e0 e1 ...) clause1 clause2 ...)	
         (if test
	     (begin e0 e1 ...)
	     (cond clause1 clause2 ...)))))

ensures that an else clause can only appear as the last clause.

I agree that the (define else #t) ruse hides what is really going on,
but using 'else' as a keyword in the macro definition doesn't hide
anything.

A complete definition of cond can be found in the macro appendix of
the R4 report.

Mike
