unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#17940: Nitpick: (lambda () (begin)) errors
@ 2014-07-04 22:39 Taylan Ulrich Bayirli/Kammer
  2020-03-13 13:08 ` bug#17940: (begin) Matt Wette
  0 siblings, 1 reply; 2+ messages in thread
From: Taylan Ulrich Bayirli/Kammer @ 2014-07-04 22:39 UTC (permalink / raw)
  To: 17940

Disclaimer: this is probably just a nitpick.

On guile-user someone brought up that (lambda () (begin)) errors,
arguably counter-intuitively:

http://lists.gnu.org/archive/html/guile-user/2014-07/msg00005.html

After much investigation over this trivial matter, I found that while
it's compliant with the RnRS (it's unspecified), it means Guile
extends the RnRS grammar in an "unexpected" way.  According to R5 and
7RS:

<lambda expression> -> (lambda <formals> <body>)
<body> -> <definition>* <sequence>
<sequence> -> <command>* <expression>
<expression> -> (other stuff) | <derived expression>
<derived expression> -> (other stuff) | (begin <sequence>)

meaning that the "(begin)" in that lambda body can be matched up to
<derived expression>, where it then almost matches the `begin' form
but fails only because in the RnRS grammar it must have at least one
expression (see <sequence> again; this is also reflected in section
4.2.3 where this `begin' form is explained; its template clearly shows
it must have at least one expression operand).

Guile on the other hand *generally* allows the expression-begin to
have zero operands, having it return *unspecified*.  So one would
expect it to work here as well, since one expects that this is a small
incremental extension to the RnRS grammar, but that's not the case.

If I'm not mistaken, `expand-body' in psyntax would be the place to
tackle this, and from a quick glance I'm guessing the benefit/effort
ratio for changing this is not very high. :-)

Taylan





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#17940: (begin)
  2014-07-04 22:39 bug#17940: Nitpick: (lambda () (begin)) errors Taylan Ulrich Bayirli/Kammer
@ 2020-03-13 13:08 ` Matt Wette
  0 siblings, 0 replies; 2+ messages in thread
From: Matt Wette @ 2020-03-13 13:08 UTC (permalink / raw)
  To: 17940

I have run into this also, in writing macros.
My workaround is to always add (if #f #f)
in my forms that allow no expressions in the body.
See second-to-last line below.

(define-syntax sx-match-1
   (syntax-rules ()
     ((_ v (pat exp ...) c1 ...)
      (let ((kf (lambda () (sx-match-1 v c1 ...))))
        (sxm-sexp v pat (begin (if #f #f) exp ...) (kf))))
     ((_ v) (error "sx-match: nothing matches"))))






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-13 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-04 22:39 bug#17940: Nitpick: (lambda () (begin)) errors Taylan Ulrich Bayirli/Kammer
2020-03-13 13:08 ` bug#17940: (begin) Matt Wette

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).