unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Arne Babenhauserheide <arne_bab@web.de>
To: guile-devel@gnu.org
Subject: definition in expression context, where definitions are not allowed
Date: Sun, 11 Oct 2015 09:49:30 +0200	[thread overview]
Message-ID: <2837212.ENRlmeWLag@fluss> (raw)

[-- Attachment #1: Type: text/plain, Size: 1290 bytes --]

Hi,

I’m repeatedly stumbling over the restrictions where to use define. Here’s a minimal example:

    (define (hello who)
      (display "Hello ")
      (define (world who)
        (display who))
      (world who)
      (display "!")
      (newline))

This throws a Syntax error: …definition in expression context, where
definitions are not allowed, in form (define (world who) (display
who))

And though I know that there are reasons for this, it just feels wrong
to be in the language which removes restrictions for writing great
languages and then seeing such a complication.

This works just fine - keeping all the information in the definition -
when I rewrite it to

    (define (hello who)
      (display "Hello ")
      (let ((world (lambda (who) (display who))))
        (world who)
        (display "!")
        (newline)))

So why isn’t that done automatically? Why does Guile not just do this
transformation with an information message that the define was changed
to a let? It already detects the situation, why can’t it make it work?

In other words: Is the optimization allowed by this worth the
additional complexity of the language?

Or am I missing something else which is enabled by this limitation?

Best wishes,
Arne

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 299 bytes --]

             reply	other threads:[~2015-10-11  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-11  7:49 Arne Babenhauserheide [this message]
2015-10-11 10:03 ` definition in expression context, where definitions are not allowed Taylan Ulrich Bayırlı/Kammer

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=2837212.ENRlmeWLag@fluss \
    --to=arne_bab@web.de \
    --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).