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