From: Mark H Weaver <mhw@netris.org>
To: David Kastrup <dak@gnu.org>
Cc: guile-devel@gnu.org
Subject: Re: Why not support (begin), (cond), (case-lambda), etc?
Date: Fri, 06 Jan 2012 11:48:08 -0500 [thread overview]
Message-ID: <87fwfsbwvr.fsf@netris.org> (raw)
In-Reply-To: <8762gpyxh8.fsf@fencepost.gnu.org> (David Kastrup's message of "Fri, 06 Jan 2012 10:46:43 +0100")
David Kastrup <dak@gnu.org> writes:
> Mark H Weaver <mhw@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
next prev parent reply other threads:[~2012-01-06 16:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-06 0:49 Why not support (begin), (cond), (case-lambda), etc? Mark H Weaver
2012-01-06 3:37 ` Alex Shinn
2012-01-06 5:03 ` Mark H Weaver
2012-01-06 6:08 ` Alex Shinn
2012-01-06 8:03 ` Mark H Weaver
2012-01-06 12:08 ` Alex Shinn
2012-01-06 12:26 ` David Kastrup
2012-01-06 12:38 ` Alex Shinn
2012-01-06 12:50 ` David Kastrup
2012-01-06 12:52 ` Alex Shinn
2012-01-06 13:02 ` David Kastrup
2012-01-06 16:13 ` Andy Wingo
2012-01-06 16:19 ` David Kastrup
2012-01-06 17:23 ` Andy Wingo
2012-01-06 17:11 ` Mark H Weaver
2012-05-01 14:10 ` Who moderates the scheme-reports list? Mark H Weaver
2012-05-05 5:09 ` Alex Shinn
2012-05-06 3:36 ` Mark H Weaver
2012-05-06 3:47 ` Alex Shinn
2012-05-06 10:12 ` David Kastrup
2012-05-07 16:26 ` Ludovic Courtès
2012-05-07 17:36 ` Mark H Weaver
2012-05-07 22:06 ` Alex Shinn
2012-05-08 14:42 ` Ludovic Courtès
2012-01-06 9:48 ` Why not support (begin), (cond), (case-lambda), etc? David Kastrup
2012-01-06 9:46 ` David Kastrup
2012-01-06 16:48 ` Mark H Weaver [this message]
2012-01-06 17:02 ` David Kastrup
2012-01-06 16:53 ` Ian Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fwfsbwvr.fsf@netris.org \
--to=mhw@netris.org \
--cc=dak@gnu.org \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).