Summary
#!optional arguments are not "evaluated in an environment in which all previous parameters have been bound."
Metadata
- Id: e80880b215668b6dad8e8336b00a2c5a5d76bab6
- Trac id: 421
- Type: defect
- Reporter: alanpost
- Owner:
- Cc:
- Status: closed
- Component: expander
- Estimated difficulty:
- Resolution: fixed
- Priority: major
- Milestone: 4.9.0
- Version: 4.6.x
- Changetime: 2012-09-24 21:47:48 UTC
- Created: 2010-10-30 23:32:11 UTC
- Keywords:
Attachments
- e80880b215668b6dad8e8336b00a2c5a5d76bab6/attachments/test-optional.scm
Description
Chicken Scheme uses DSSSL style lambda lists, as an extension to standard scheme:
http://wiki.call-cc.org/man/4/Extensions%20to%20the%20standard
Optional parameters are permitted to have an initializer, and the documentation states:
"The corresponding <initializer> is evaluated in an environment in which all previous parameters have been bound."
I would expect the following to work (note that a1 is being bound to the value of a0):
(define (foo #!optional a0 (a1 a0))
(list a0 a1))
(foo) => (#f #f) (foo 0) => (0 0)
However, I instead get the following error:
Note: the following toplevel variables are referenced but unbound:
a0 (in def-a123)
I've attached a test case for #!optional parameters testing additional cases.
I'm running chicken scheme from git, commit cd19d7e077f0a6b53c3c804c972ec3738683e9ab.
My platform is OpenBSD 4.8-snapshot.
Changes and comments
[2010-10-30 23:32:39 UTC] alanpost attached test-optional.scm (description=test case designed to be placed in chicken-core/tests/)
[2010-10-30 23:35:04 UTC] sjamaan wrote:
Likely fixed by changing let-optionals to let-optionals* in expand.scm:374
[2010-10-31 00:22:33 UTC] felix changed status from new to closed
[2010-10-31 00:22:33 UTC] felix set resolution to fixed
[2010-10-31 00:22:33 UTC] felix wrote:
Using `let-optionals*` is not only correct, it also generates faster and smaller code. Thanks a lot, Alan! I added the testcase (and fixed a few problems with it).
[2011-06-01 09:00:41 UTC] felix changed milestone from 4.7.0 to 4.8.0
[2011-06-01 09:00:41 UTC] felix wrote:
Milestone 4.7.0 deleted
[2012-09-24 21:47:48 UTC] felix changed milestone from 4.8.0 to 4.9.0
[2012-09-24 21:47:48 UTC] felix wrote:
Milestone 4.8.0 deleted