[Top][All Lists]

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

Re: Placement of defines

From: Kjetil S. Matheussen
Subject: Re: Placement of defines
Date: Thu, 18 Dec 2008 18:31:46 +0100 (CET)

Sebastian Tennant:

Hi all,

Having read this interesting thread:

I understand that internal definitions may not occur anywhere other than
at the beginning of the body of the enclosing expression, which explains
why this works:

((lambda (x) (define bar x) (display bar)) "foo\n")

while this doesn't:

((lambda (x) (set! x "baz\n") (define bar x) (display bar)) "foo\n")

Firstly, perhaps this could/should be mentioned in the manual?

(info "(guile) Internal Definitions") currently reads:

"A `define' form which appears inside the body of a `lambda', `let',
`let*', `letrec' or equivalent expression is called an "internal

May I suggest this reads:

"`Define' forms may only appear at the beginning of the body of a
`lambda', `let', `let*', `letrec' or equivalent expression, and when
they do they constitute what are known as "internal definitions"."

or words to that effect.

That's definitely an improvement!

Secondly, there is some talk in the above-mentioned thread of an
extension to R5RS Scheme that allows define forms to occur anywhere
within the body of the enclosing expression, making for much more
readable code.

The thread is approx 8.5 years old now, and I was just wondering why the
extension never made it into Guile, the readable code argument being a
pretty compelling one IMHO.

Yes, this limitation in Scheme is a horrible pest. There's no
decent reason why you shouldn't be allowed to use define other
places than right after a lambda, except the long discussion
involved how it should behave in various situations. But even
inconsistant behaviour between implementations would be better
than the current situation where you either have to rewrite
perfectly fine expressions or use various types of lets or
lambdas in more or less ridiculous ways:

- ((lambda (x) (set! x "baz\n") (define bar x) (display bar)) "foo\n")
+ ((lambda (x) (set! x "baz\n") (let () (define bar x) (display bar) "foo\n"))

reply via email to

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