[plt-scheme] required else for if ?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Sep 6 18:19:59 EDT 2009

If you want to program in r5rs, then you can and you'll get the if you
desire (ditto for r6rs). Both are supported by PLT. In the standard
PLT languages, however, the convention is to use "when".

hth,
Robby

On Sun, Sep 6, 2009 at 2:07 PM, Doug Evans<dje at sebabeach.org> wrote:
> Hi.
>
> How come the default behaviour of `if' in mzscheme is to
> require the else clause,
> and not have an optional else clause?
>
> $ mzscheme --version
> Welcome to MzScheme v4.1.2 [3m], Copyright (c) 2004-2008 PLT Scheme Inc.
> $ mzscheme -e '(if #f 1)'
> #f::0: if: bad syntax (must have an "else" expression) in: (if #f 1)
> $
>
> I thought Standard Scheme (rnrs) had the else clause as being optional,
> with the result of an elided else clause being "unspecified",
> or "void" I guess in plt-scheme-speak.
> This seems like a gratuitous divergence.
>
> I realize there's `when', which is in (rnrs control (6)),
> but I'm porting a bit of code, and converting everything
> to use `when' seems like unnecessary pain.
>
> P.S. I found this in r5rs/main.ss
>
> (define-syntax r5rs:if
>  (syntax-rules ()
>    [(_ test then)
>     (if test then (void))]
>    [(_ test then else)
>     (if test then else)]))
>
> and tweaked it to become
>
> (define-syntax if
>  (syntax-rules ()
>    [(_ test then)
>     (when test then)]
>    [(_ test x-then x-else)
>     (cond (test x-then) (else x-else))]))
>
> which seems to work.
> [Recorded here for future folks googling for a solution.
> It mightn't be perfect, but it's got me past this issue.
> Any recommended improvements are welcome of course.]
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.