[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] I seem to not understand something about scope in Sc
From: |
John Cowan |
Subject: |
Re: [Chicken-users] I seem to not understand something about scope in Scheme/Chicken... |
Date: |
Tue, 25 Dec 2007 22:21:11 -0500 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Robin Lee Powell scripsit:
>
> Can someone explain to me what's going on in
> http://paste.lisp.org/display/53038 ? I can't think of any reason
> why a define in a recursive call would corrupt the calling
> function's value for a variable, but having it happen IFF the define
> is in a (cond...) seems Really Really Wierd.
R5RS section 5.2.2:
Definitions may occur at the beginning of a <body> (that is, the
body of a lambda, let, let*, letrec, let-syntax, or letrec-syntax
expression or that of a definition of an appropriate form).
Cond is not on the list, so technically your use of "define" is a syntax
error. Chicken does not really differentiate between define and set! in
such contexts, so it is being treated as a set! of the *global* variable.
The simplest fix is to change the cond's body to be (let ((...) ...).
--
Is not a patron, my Lord [Chesterfield], John Cowan
one who looks with unconcern on a man http://www.ccil.org/~cowan
struggling for life in the water, and when address@hidden
he has reached ground encumbers him with help?
--Samuel Johnson