[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MIT-Scheme-devel] For your amusement
From: |
Joe Marshall |
Subject: |
[MIT-Scheme-devel] For your amusement |
Date: |
Tue, 14 Jun 2011 08:11:06 -0700 |
For kicks I wanted to see what would happen if named-let
expanded to a fixed-point rather than to a letrec. I added some
code to "mit-macros.scm" that allows you to do that.
The variable named-let-strategy in the (runtime mit-macros)
package determines the expansion. The normal value is
the symbol 'LETREC, and this causes named-let to expand
into a letrec form like this:
(let loop ((x 0))
(if (>= x 10)
#f
(begin (display x) (newline) (loop (1+ x)))))
==>
((let ()
(define (loop x)
(if (>= x 10)
#f
(begin (display x) (newline) (loop (1+ x)))))
loop) 0)
(The pretty printer will recognize this as a named-let and
`undo' the expansion.)
If you set it to the symbol 'FIXED-POINT, you get this expansion
instead:
(let ((kernel
(lambda (iter x)
(let ((loop
(lambda (temp)
(declare (integrate temp))
(iter iter temp))))
(declare (integrate loop))
(if (>= x 10)
#f
(begin (display x) (newline) (loop (1+ x))))))))
(kernel kernel 0))
After SF does the integration, it will be this:
(let ((kernel
(lambda (iter x)
(and (&< x 10)
(begin (display x) (newline) (iter iter (1+ x)))))))
(kernel kernel 0))
So what's the difference? Pretty much nothing. I have yet to find
any code that compiles differently (modulo renaming of branch labels).
A basically null result is what is expected. However, the fixed-point
expansion does not have the implicit assignment that the letrec expansion
has. This makes it slightly easier to analyze, and SF is able to report
if the name is actually used in the body. I uncovered a few places
in the code where a named-let was written, but the name was never
invoked.
I had made this change in my own copy of Scheme, but it seemed
interesting enough that I thought I'd add a switch so others could
play with it if they desired. The default value of the switch is
'letrec (the original expansion). I didn't export the switch because
I can't imagine `regular' users would have a use for it.
--
~jrm
- [MIT-Scheme-devel] For your amusement,
Joe Marshall <=
- [MIT-Scheme-devel] For your amusement, Matt Birkholz, 2011/06/15
- Re: [MIT-Scheme-devel] For your amusement, Joe Marshall, 2011/06/15
- Re: [MIT-Scheme-devel] For your amusement, Taylor R Campbell, 2011/06/15
- Re: [MIT-Scheme-devel] For your amusement, Joe Marshall, 2011/06/17
- Re: [MIT-Scheme-devel] For your amusement, Taylor R Campbell, 2011/06/17
- Re: [MIT-Scheme-devel] For your amusement, Joe Marshall, 2011/06/17
- Re: [MIT-Scheme-devel] For your amusement, Taylor R Campbell, 2011/06/17
- Re: [MIT-Scheme-devel] For your amusement, Taylor R Campbell, 2011/06/17