no continuations

Ashley Yakeley 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?
> 
> http://google.com/groups?selm=7eb8ac3e.0304131423.4f103d4f%40posting.google.co
> m
> 
> The difference between the Y and set! approaches to letrec *is*
> observable.

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)))))))
  (fact 8))
 
  (eq? (car *keep-track*) (cadr *keep-track*))

My implementation returns 

  40320
  #t

...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 mailing list