Discussion:
[Chicken-users] Internal Definitions / begin
Martin Schneeweis
2018-07-16 13:51:09 UTC
Permalink
Hi,

is it expected behaviour that (a) does not work but (b) does?

a) define after begin

(define rec-1 (lambda (depth)
(if (fx< 0 depth)
(begin
(define x
(string-append "depth: " (number->string depth)))
(rec-1 (fx- depth 1))
(print x)))))

b) define after let

(define rec-1 (lambda (depth)
(if (fx< 0 depth)
(let ()
(define x
(string-append "depth: " (number->string depth)))
(rec-1 (fx- depth 1))
(print x)))))


chicken tools - reacting to (a):

Chicken 4:
csi: Note: the following toplevel variables are referenced but unbound:
x (in rec-1)

csc (default parameter): no comment

Chicken 5:

csc (default parameter): error

lg
Martin
Peter Bex
2018-07-16 14:11:31 UTC
Permalink
Post by Martin Schneeweis
Hi,
is it expected behaviour that (a) does not work but (b) does?
yeah, this is a bit unexpected, but "let" will start a new
definition body whereas "begin" does not. Try it in another
Scheme, you'll see the same thing.

CHICKEN extends the standard already a little bit by being more
lenient in where internal defines may be placed, but it's not
a free-for-all.

In CHICKEN 4 we don't detect illegal internal defines, and they
will actually "fall through" and be treated as global defines,
which is a total mindfuck. In CHICKEN 5 we've improved the situation
by raising an error when an illegally-placed define is detected.

Cheers,
Peter
Martin Schneeweis
2018-07-16 14:38:14 UTC
Permalink
Hi Peter,
In CHICKEN 4 we don't detect illegal internal defines, and they will
actually "fall through" and be treated as global defines, which is a
total mindfuck. In CHICKEN 5 we've improved the situation by raising
an error when an illegally-placed define is detected.
thanks for the clarification - I guess I will add a small comment to
https://wiki.call-cc.org/man/4/Extensions%20to%20the%20standard#internal-definitions
then (for people like me who did not read
https://wiki.call-cc.org/man/4/The%20R5RS%20standard with enough
attention)

lg
Martin

Loading...