[racket] (if ...) form without an else

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Wed Apr 11 23:51:08 EDT 2012

On Wed, Apr 11, 2012 at 2:42 PM, lothar atheling <lothar_ at warpmail.net> wrote:
> usually an (if ...) form without an else part does not cause an error.
> but sometimes it does, as the following shows:
> if: bad syntax (must have an "else" expression) in: (if isinitialised
> (expose))
> why the different behavior?

The main Racket language changed to force 'if' to make the consequent
and alternative both mandatory, motivated by a desire to reduce the
chance of bugs.  Here's a link to some of the discussion back in 2009:


If you do really need one-armed ifs, consider using "when" and
"unless" instead.  Using 'when' and 'less' makes it clear to readers
that it's intentional that a conditional branch doesn't fire off when
the test fails.

By the way, it is possible for you to personally weaken the
restriction on 'if', since Racket's syntax permits overriding the
language's default.  But see if using 'when' and 'unless' is
sufficient for your programs first.

Posted on the users mailing list.