[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why not support (begin), (cond), (case-lambda), etc?
From: |
Mark H Weaver |
Subject: |
Re: Why not support (begin), (cond), (case-lambda), etc? |
Date: |
Fri, 06 Jan 2012 11:48:08 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) |
David Kastrup <address@hidden> writes:
> Mark H Weaver <address@hidden> writes:
>
>> I'd like to argue in favor of supporting (begin), (cond), (case-lambda)
>> and other such degenerate forms, for the same reason that we support
>> (*), (+), and (let () ...).
>
> Actually, I'd like to see (let ()) and (lambda ()) work too for similar
> reasons (basically equivalent to (if #f #f)).
I agree.
>> Imagine if we didn't support (*) and (+). Then you couldn't simply
>> write (apply + xs) to add a list of numbers; instead you'd have to write
>> (if (null? xs) 0 (apply + xs)).
>
> (apply + 0 xs) but it still is a distraction.
True, and indeed still an ugliness, even if one with fewer extra
characters. I myself work hard to make my programs as simple as elegant
as possible.
>> The same argument applies to (begin), (cond), and (case-lambda). They
>> simplify writing robust syntax transformers without having to handle
>> degenerate cases specially.
>
> Correct me if I am wrong (I actually have not really understood syntax
> transformers), but the usual patterns of xxx ... can't be empty (that
> is,
Actually, you are wrong here. "e ..." can be empty. If you want to
prohibit the empty list, you need to write something like "e0 e ..."
instead.
However, "e ..." _does_ require a proper list, i.e. without a dotted
tail at the end. For example "(define (proc arg ...) e0 e ...)" will
_not_ match (define (map f . xs) <blah>). To match cases like that, you
need to instead make your pattern "(define (proc . args) e0 e ...)".
>> Apart from this general argument, I can think of one particularly
>> compelling reason to support (begin). Suppose you have a macro that
>> generates a sequence of local definitions. How do you return an empty
>> sequence of definitions without terminating definition context?
>
> (begin (values))
No, that doesn't work. (values) is an expression, not a definition, and
thus (values) terminates definition context. (Within a local block,
local definitions cannot follow an expression).
scheme@(guile-user)> (let () (begin (values)) (define x 3) x)
While compiling expression:
ERROR: Syntax error:
unknown location: definition in expression context in subform x of 3
Mark
- Re: Why not support (begin), (cond), (case-lambda), etc?, (continued)
- Re: Why not support (begin), (cond), (case-lambda), etc?, Alex Shinn, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, David Kastrup, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, Alex Shinn, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, David Kastrup, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, Alex Shinn, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, David Kastrup, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, Andy Wingo, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?, David Kastrup, 2012/01/06
Re: Why not support (begin), (cond), (case-lambda), etc?, David Kastrup, 2012/01/06
Re: Why not support (begin), (cond), (case-lambda), etc?, David Kastrup, 2012/01/06
- Re: Why not support (begin), (cond), (case-lambda), etc?,
Mark H Weaver <=
Re: Why not support (begin), (cond), (case-lambda), etc?, Ian Price, 2012/01/06
- Prev by Date:
Re: Why not support (begin), (cond), (case-lambda), etc?
- Next by Date:
Re: Why not support (begin), (cond), (case-lambda), etc?
- Previous by thread:
Re: Why not support (begin), (cond), (case-lambda), etc?
- Next by thread:
Re: Why not support (begin), (cond), (case-lambda), etc?
- Index(es):