Scheme: cond vs. if [was: Re: Question: Tokenizing CDATA attribute values]

Subject: Scheme: cond vs. if [was: Re: Question: Tokenizing CDATA attribute values]
From: lee@xxxxxx
Date: Mon, 16 Jun 97 22:29:08 EDT
David Megginson <dmeggins@xxxxxxxxxx> wrote:
> Paul Prescod writes:
>> I'm curious about your coding style. Why do you sometimes use "cond" for
>> "if"? And "#t" for "else"?
> 
> The #t is just a left-over from other LISPs.  I generally use cond
> when I have only one or more than two alternatives.

One of the most pernicious errors you can make in IEEE R4RS Scheme
is to have an "if" with no "else" part where the condition is not
always true:
    (define boy (if (wednesday) 'Simon))

This is legal in R4RS Scheme, but the result is unspecified on days
other than wednesday :-)  (the standard explicitly says that it has
an unspecified result).

One implementation might return #f and another #t and another something
else, and another might flag an error.  SoftQuad's Scheme interpreter
returns a special non-standard value, #<unspecified>; the only way you
can ever get this value is by doing something the standard doesn't specify.

    > (define (wednesday) #f)
    #<unspecified>
    > (define boy (if (wednesday) 'Simon))
    #<unspecified>
    > boy
    #<unspecified>

    > (define (wednesday) #t)
    #<unspecified>
    > (define boy (if (wednesday) 'Simon))
    #<unspecified>
    > boy
    simon


One common reason in R4RS scheme for having an if without an else is to
perform a side effect such as printing a debugging statement.

Since DSSSL Scheme is more or less side-effect free, I would expect that
an elseless if is always an error, and probably should be trapped.
I can't check whether jade complains about it from here.

Lee


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread