unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Ian Hulin <ian@hulin.org.uk>
Cc: 10099-done@debbugs.gnu.org, "Ludovic Courtès" <ludo@gnu.org>,
	"Han-Wen Nienhuys" <hanwenn@gmail.com>
Subject: bug#10099: Null (begin) blocks - V2.0.3 reports error was OK in V2.0.2
Date: Wed, 21 Dec 2011 20:17:47 -0500	[thread overview]
Message-ID: <8762h9s8uc.fsf@pobox.com> (raw)
In-Reply-To: <871usznhvv.fsf@pobox.com> (Andy Wingo's message of "Wed, 23 Nov 2011 13:27:32 +0100")

Hi,

On Wed 23 Nov 2011 07:27, Andy Wingo <wingo@pobox.com> writes:

> On Tue 22 Nov 2011 00:02, Andy Wingo <wingo@pobox.com> writes:
>>On Mon 21 Nov 2011 18:25, Ian Hulin <ian@hulin.org.uk> writes:
>>> (define-public (void? x) (eq? x (begin)))
>>> This works in V1.8, and apparently used to work in 2.0.2 (no errors),
>>
>> Interesting.  If it changed incompatibly in 2.0.x, that is a Guile bug.
>> Sorry about that!  We'll fix it.
>
> I cannot reproduce this issue with 2.0.2.  I suspect that this code has
> been this way since early 1.9 releases, and is a consquence of switching
> to the new syntax expander.
>
> That said, this change was not mentioned in NEWS, and the documentation
> has not been updated, so perhaps we should do something.  I would prefer
> just to leave it as it is, unless you think that adding a compatibility
> hack could help you somehow.  What do you think, Ian?

I have appended the updated documentation to this reply to clarify that
(begin) in expression context is invalid syntax.  I have also added a
backwards-compatibility shim to issue a deprecation warning and
translate it to *unspecified*, in Guile 2.0.  That should fix this bug.

Regards,

Andy


6.13.1 Sequencing and Splicing
------------------------------

As an expression, the `begin' syntax is used to evaluate a sequence of
sub-expressions in order.  Consider the conditional expression below:

     (if (> x 0)
         (begin (display "greater") (newline)))

   If the test is true, we want to display "greater" to the current
output port, then display a newline.  We use `begin' to form a compound
expression out of this sequence of sub-expressions.

 -- syntax: begin expr1 expr2 ...
     The expression(s) are evaluated in left-to-right order and the
     value of the last expression is returned as the value of the
     `begin'-expression.  This expression type is used when the
     expressions before the last one are evaluated for their side
     effects.

   The `begin' syntax has another role in definition context (*note
Internal Definitions::).  A `begin' form in a definition context
"splices" its subforms into its place.  For example, consider the
following procedure:

     (define (make-seal)
       (define-sealant seal open)
       (values seal open))

   Let us assume the existence of a `define-sealant' macro that expands
out to some definitions wrapped in a `begin', like so:

     (define (make-seal)
       (begin
         (define seal-tag
           (list 'seal))
         (define (seal x)
           (cons seal-tag x))
         (define (sealed? x)
           (and (pair? x) (eq? (car x) seal-tag)))
         (define (open x)
           (if (sealed? x)
               (cdr x)
               (error "Expected a sealed value:" x))))
       (values seal open))

   Here, because the `begin' is in definition context, its subforms are
"spliced" into the place of the `begin'.  This allows the definitions
created by the macro to be visible to the following expression, the
`values' form.

   It is a fine point, but splicing and sequencing are different.  It
can make sense to splice zero forms, because it can make sense to have
zero internal definitions before the expressions in a procedure or
lexical binding form.  However it does not make sense to have a
sequence of zero expressions, because in that case it would not be
clear what the value of the sequence would be, because in a sequence of
zero expressions, there can be no last value.  Sequencing zero
expressions is an error.

   It would be more elegant in some ways to eliminate splicing from the
Scheme language, and without macros (*note Macros::), that would be a
good idea.  But it is useful to be able to write macros that expand out
to multiple definitions, as in `define-sealant' above, so Scheme abuses
the `begin' form for these two tasks.


-- 
http://wingolog.org/





      parent reply	other threads:[~2011-12-22  1:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4ECA89A5.5090202@hulin.org.uk>
2011-11-21 23:02 ` Null (begin) blocks - V2.0.3 reports error was OK in V2.0.2 Andy Wingo
2011-11-25 10:37   ` bug#10099: " David Kastrup
2011-11-25 11:13     ` Andy Wingo
2011-11-23 12:27 ` Andy Wingo
2011-11-24 23:49   ` Ian Hulin
2011-11-25  9:31     ` Andy Wingo
2011-12-22  1:17   ` Andy Wingo [this message]

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=8762h9s8uc.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=10099-done@debbugs.gnu.org \
    --cc=hanwenn@gmail.com \
    --cc=ian@hulin.org.uk \
    --cc=ludo@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).