[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: when and unless
From: |
David Kastrup |
Subject: |
Re: when and unless |
Date: |
Tue, 06 Dec 2011 12:17:06 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.90 (gnu/linux) |
Alex Shinn <address@hidden> writes:
> On Tue, Dec 6, 2011 at 4:48 PM, Marijn <address@hidden> wrote:
>>
>> Couldn't help but wonder why they don't return the value of the last
>> body form, so I looked around a bit and both CLHS[1] and my racket
>> REPL seem to agree that they should:
>>
>> $ racket
>> Welcome to Racket v5.2.0.4.
>>> (when #t 'hello)
>> 'hello
>>> (unless #f 'hi)
>> 'hi
>>
>> Is there some other source that suggests that the return value should
>> be unspecified?
>
> Because the result is meaningless when the condition is false.
>
> CLHS returns nil in this case, but that fits with CL idioms and
> not Scheme idioms. when and unless are for side-effects - it's
> better to write (and #t 'hello) if you want the result.
>
> R7RS also leaves it unspecified.
I've actually wondered if it would not make sense to return
*unspecified* in the case of the plain else-less if even if the
condition is true, namely when you write (if #t #t).
There is probably code relying on this to be #t, but frankly, this
appears like a recipe for breakage.
--
David Kastrup
- Re: when and unless, Andy Wingo, 2011/12/05
- Re: when and unless, Marijn, 2011/12/06
- Re: when and unless, Alex Shinn, 2011/12/06
- Re: when and unless,
David Kastrup <=
- Re: when and unless, Andy Wingo, 2011/12/06
- Re: when and unless, David Kastrup, 2011/12/06
- Re: when and unless, Andy Wingo, 2011/12/06
- Re: when and unless, David Kastrup, 2011/12/06
- Re: when and unless, Chris K. Jester-Young, 2011/12/06
- Re: when and unless, David Kastrup, 2011/12/07
- Re: when and unless, Chris K. Jester-Young, 2011/12/07
- Re: when and unless, David Kastrup, 2011/12/08
- Re: when and unless, Chris K. Jester-Young, 2011/12/08
- Re: when and unless, David Kastrup, 2011/12/08