ashley at semantic.org
Fri Jan 9 22:07:37 EST 2004
In article <20040110040353.37C17AB8D at Adric.metnet.navy.mil>,
oleg at pobox.com wrote:
> > (define circular (letrec ((c (cons 'x c))) c))
> I'm afraid that is not a R5RS compliant code.
Indeed not, it merely demonstrates fixed-point behaviour. Nevertheless,
allowing this as an extension does not make my implementation
non-compliant. See section 1.3.2 on this point.
> > Do you have an example of use of Y for letrec where a program would
> > violate R5RS?
> The difference between the Y and set! approaches to letrec *is*
I don't believe you. My implementation uses Haskell's "mfix", which
looks like a Y to me. I certainly don't use anything like "set!". But my
implementation passes Dorai Sitaram's test:
(define *keep-track* '())
(letrec ((fact (lambda (n)
(set! *keep-track* (cons fact *keep-track*))
(if (= n 0) 1
(* n (fact (- n 1)))))))
(eq? (car *keep-track*) (cadr *keep-track*))
My implementation returns
...which is apparently correct behaviour for R5RS. Indeed I get exactly
the same result in mzscheme and guile. Again, I encourage you to try for
yourself at <http://hscheme.sourceforge.net/interpret.php> (though it's a bit slow).
Ashley Yakeley, Seattle WA
More information about the Haskell-Cafe