guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

when and unless


From: Andy Wingo
Subject: when and unless
Date: Thu, 30 Jun 2011 12:44:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

I think we should add `when' and `unless' to the default environment.

They go like this:

  (define-syntax when
    (syntax-rules ()
      ((_ test then then* ...)
       (if test (begin then then* ... (if #f #f))))))

  (define-syntax unless
    (syntax-rules ()
      ((_ test else else* ...)
       (if (not test) (begin else else* ... (if #f #f))))))

These are pretty uncontroversial and common, and they make it easier to
read code, so let's do it.

The only argument I have heard against them is that "when" connotes some
connection with time, whereas "if" does not.  I agree with this
criticism, but "when" is sufficiently common that it shouldn't confuse
anyone, and in any case we have modules if someone feels strongly enough
to not want these bindings.

The trailing (if #f #f) is to indicate that the consequent expressions
are evaluated for effect, not for value, and the the return value(s) of
`when' and `unless' are not specified.  In the future we may cause
instances of (if #f #f) used for a value to emit a warning or an error.

Regards,

Andy
-- 
http://wingolog.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]