David Kastrup <d...@gnu.org> writes: > Mark H Weaver <m...@netris.org> 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