psyntax and compiler extension required
Matthias Radestock <[email protected]>
| Newsgroups | gmane.comp.java.sisc.devel |
|---|---|
| Organization | LShift Ltd |
| Message-ID | <[email protected]> |
In my attempts to define the macros for srfi-9 I encountered the
following problem:
define-values cannot be defined (in R5RS, or even using syntax-case) in
a way that would make it work in internal definitions such as
(let ()
(define a 1)
(define-values (b c) (values 2 3))
(define d 4)
(+ a b c d))
The same problem, expressed differently, is
(letrec-values
((a 1)
((b c) (values 2 3))
(d 4))
(+ a b c d))
(**)
This is a known problem. There are some Schemes, notably MzScheme, that
solve the problem by providing native support for define-values /
letrec-values(*). Doing this in SISC shouldn't be too hard. My
suggestion is to:
* Change the syntax of letrec to cover the letrec-values case.
* Change the macro expander to handle the extended letrec syntax.
* Change the macro expander to use the extended letrec syntax for
expanding internal define-values.
* Change the compiler / LetrecExp to handle the extended letrec syntax.
* [optional] Change the macro expander to recognize top-level
define-values as native syntax.
* [optional] Change the compiler to produce DefineValuesExpr for
top-level define-values.
* Change the optimizer to handle any new native syntax we introduce.
A variation on the above is to leave letrec alone and instead introduce
a native letrec-values. The macro expander would then have to either
always use letrec-values for internal definitions or, if it tries to be
smarter, use letrec if there are no internal define-values and use
letrec-values otherwise.
Matthias
(*) As far as I can tell from the docs MzScheme handles this not quite
right - it's not possible to intermix define and define-values in a
mutually recursive way.
(**) The usual syntax for letrec-values does not specifically cater for
the non-values case. I am using the extended syntax because it allows us
to make the non-values case as efficient as letrec.
-------------------------------------------------------
This SF.net email is sponsored by: If flattening out C++ or Java
code to make your application fit in a relational database is painful,
don't do it! Check out ObjectStore. Now part of Progress Software.
http://www.objectstore.net/sourceforge