guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is an empty lambda body not allowed?


From: Taylan Ulrich Bayirli/Kammer
Subject: Re: Why is an empty lambda body not allowed?
Date: Fri, 04 Jul 2014 21:44:23 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Tobias Brandt <address@hidden> writes:

> Hi,
>
> it seems to be illegal to write
> (lambda ())
>
> I would have expected this to evaluate to a procedure returning
> unspecified.

I don't see that as being more intuitive, or useful.  Even returning
*unspecified* or returning zero values is an action, a procedure with
nothing as its body intuitively does nothing, which doesn't really make
sense (it must at least return something) .. oh well, philosophical
babbling.  In practice it will be just an additional incompatibility
with other implementations, for no gain.

Tangentially related thread from a couple months back:

http://lists.gnu.org/archive/html/guile-devel/2014-02/msg00039.html

> On the other hand, the following are all valid
> (begin)
> (define x (begin))
> (lambda () x)
>
> but
> (lambda () (begin))
>
> is not.
>
> Why is that?

There are (conceptually) two different syntaxes bound to `begin', which
are selected based on the context in which the form appears.

The one `begin' can have a sequence os definitions and expressions as
its subforms, and is evaluated exactly as if the (begin <...>) form were
just <...>.  (The subforms are "spliced" into the surrounding scope.)
This is a hack for macros that want to output several definitions.  This
`begin' form can appear at the start of a lambda body, and similar
places.

The other `begin' can only have expressions (no definitions) as its
subforms, and is itself an expression, thus can appear anywhere an
expression may appear, like in the middle of a lambda body, or as a
procedure-call operand.

In your example, it seems ambiguous which `begin' should be used (it has
no definition subforms, so it could just be the expression-begin), and
apparently Guile interprets it as the former, which is fine.  R5RS could
actually even be interpreted to mean that the splicing-begin *should* be
used in that context (see end of section 5.2.2 "Internal definitions"),
though the same doesn't hold for R7RS-small as far as I see (section
4.2.3 "Sequencing").

I agree that one would at first expect ((lambda () (begin))) to be
equivalent to (begin), but I wouldn't e.g. complicate the compiler for
it.

> Cheers,
> Tobias

Taylan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]