guile-devel
[Top][All Lists]
Advanced

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

definition in expression context, where definitions are not allowed


From: Arne Babenhauserheide
Subject: definition in expression context, where definitions are not allowed
Date: Sun, 11 Oct 2015 09:49:30 +0200
User-agent: KMail/4.14.8 (Linux/3.14.14-gentoo; KDE/4.14.8; x86_64; ; )

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: signature.asc
Description: This is a digitally signed message part.


reply via email to

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