unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Taylan Ulrich Bayirli/Kammer <taylanbayirli@gmail.com>
To: Tobias Brandt <tob.brandt@gmail.com>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Why is an empty lambda body not allowed?
Date: Sat, 05 Jul 2014 01:01:39 +0300	[thread overview]
Message-ID: <871tu0eqbg.fsf@taylan.uni.cx> (raw)
In-Reply-To: <CAOOWqiqD9qUqFi1gvQU+EE4eEjWOijMV-F=0fZGReDucbN7bAw@mail.gmail.com> (Tobias Brandt's message of "Fri, 4 Jul 2014 21:14:43 +0200")

Tobias Brandt <tob.brandt@gmail.com> writes:

> I don't really care what (lambda ()) evaluates to as long as it's
> consistent with the rest of the language. But what rubs me the wrong
> way is that
>
> (define x (begin))
> (lambda () x)
>
> is not the same as
>
> (lambda () (begin))
>
> because one of the strength of functional programming is referential
> transparency. Therefore I would expect the definition of x (which has
> no side effects) to be substitutable for x itself. This is apparently
> not the case as one (begin) has a different meaning than the other
> because of its context.

I agree it's annoying.  However it only breaches referential
transparency on a superficial, textual level, or not at all depending on
your definition.  In your example, the right-hand side of the `define'
is (grammatically) an <expression> whereas the other form is in a <body>
position, so it's not so that you're exchanging two <expression>s.  It's
rather so that a valid <expression> (in Guile Scheme at least, see
below) happens to also be a valid <body> (which however leads to an
error later on).

By the way, it comes out the expression-begin is actually specified (in
R5 through 7RS) to take at least one operand, so in your example the
(define x (begin)) is unspecified in first place.

OTOH, a <body> is defined as "<definition>* <sequence>", where
<sequence> is "<command>* <expression>", meaning that in a <body> that
is just "(begin)", the (begin) is an <expression>.  In RnRS, (begin) is
actually an invalid <expression>, but since Guile allows it in general,
one would expect it to work here too.  (Guile's "excuse" here could be
that it uses a wholely different grammar that is compatible with the
RnRS one, instead of one constructed through incremental extensions to
it.)

I now wish Guile simply didn't allow (begin) as a valid expression. :-)

While this is just a nitpick, I'll file a bug report for it.

> As another data point, this seems to be fine:
>
> (use-modules (oop goops))
> (define-method (foo))
>
> So, GOOPS doesn't mind empty method bodies. However
>
> (define-method (foo) (begin))
>
> fails. Not very consistent either, I'm afraid.

I just checked and `define-method' (deferring to the auxilliary macro
`method') special-cases zero-form method bodies, simply giving them a
body of (if #f #f), so it introduces the asymmetry intentionally.  Dunno
why, but changing it could break backwards compatibility.  OTOH it's
nasty that the second failes when the first doesn't, so I'll file an
additional report for that.

> Cheers,
> Tobias

Taylan



      reply	other threads:[~2014-07-04 22:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-04 18:20 Why is an empty lambda body not allowed? Tobias Brandt
2014-07-04 18:44 ` Taylan Ulrich Bayirli/Kammer
2014-07-04 19:14   ` Tobias Brandt
2014-07-04 22:01     ` Taylan Ulrich Bayirli/Kammer [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=871tu0eqbg.fsf@taylan.uni.cx \
    --to=taylanbayirli@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=tob.brandt@gmail.com \
    /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).