unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Alex Shinn <alexshinn@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: Why not support (begin), (cond), (case-lambda), etc?
Date: Fri, 06 Jan 2012 03:03:53 -0500	[thread overview]
Message-ID: <87k455b6l2.fsf@netris.org> (raw)
In-Reply-To: <CAMMPzYOJMpUjWCyjDedD2x5FzseeEBXQZhO4uRqbQgUZUs4nxQ@mail.gmail.com> (Alex Shinn's message of "Fri, 6 Jan 2012 15:08:46 +0900")

Alex Shinn <alexshinn@gmail.com> writes:
> Seeing as how (cond) is currently non-standard, it's the
> other way around - you have to provide evidence that it's
> useful in macros.  Since by definition you're expanding
> a macro whose return value is undefined, I think this is
> likely a corner case (and possible evidence that the macro
> was poorly thought out to begin with if it may sometimes
> be defined and sometimes undefined).

Not all expressions are evaluated for their return values.  Some are
evaluated solely for their effects, and of course these are the only
expressions where (cond) or (begin) makes sense.

For example, consider a convenience macro to define a structure type.
It expands to a sequence of definitions, one of which is the
constructor.  In the structure specification, each field may provide an
optional `valid?' predicate.  One of the jobs of the constructor is to
make sure that its arguments are valid.

One reasonable way to do this is to include a `cond' in the expansion of
the constructor which contains one clause for each field that provides
the optional `valid?' predicate.  This `cond' would be evaluated solely
for its effect, namely to raise an error if any predicate fails.

However, the structure specification may not have included any field
predicates, in which case the macro would most naturally generate
(cond).

Alternatively, instead of putting all the argument checks into one
`cond', we could instead produce a sequence of `cond's with one clause
each, or perhaps a sequence of `if's.  In this case, the macro would
naturally generate (begin) if no field predicates were provided.

Of course, it is not hard to work around these seemingly pointless
prohibitions, just as it would not be hard to write

  (if (null? xs) 0 (apply + xs))

instead of

  (apply + xs)

but I don't understand why we should have to.  What's the compelling
argument on the other side that justifies these annoyances?

    Thanks,
      Mark



  reply	other threads:[~2012-01-06  8:03 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 [this message]
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
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=87k455b6l2.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=alexshinn@gmail.com \
    --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).