Advertisement
Guest User

Continuations and constructor-hoisting

a guest
May 4th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.07 KB | None | 0 0
  1. #lang racket
  2.  
  3. (define xs #f)
  4. (set! xs '()) ;ensure Racket will permit rebinding of xs at the REPL
  5. (define cont #f)
  6.  
  7. (define (meh x)
  8.   (let ((y (vector x 10)))
  9.     ;(display y)
  10.     (if (test x)
  11.         y
  12.         x)))
  13.  
  14. (define (test x)
  15.   (call-with-current-continuation
  16.    (lambda (c)
  17.      (set! cont c)))
  18.   (even? x))
  19.  
  20. (set! xs (cons (meh 8) xs))
  21.  
  22. (cont 'ignored)
  23.  
  24. (eq? (car xs) (cadr xs))
  25. ;=> #f, which I believe is wrong.
  26.  
  27. ;If you uncomment the (display y), then this returns #t.
  28. ;[Also, Chicken returns #t regardless.]
  29. ;The uncommenting appears to *force* the compiler to create the
  30. ;vector y before (test x), and so any continuation saved from
  31. ;there will retain the identical y.
  32.  
  33. ;On the other hand, if Racket accepts this as wrong, this makes
  34. ;it impossible for it to hoist constructors into if-branches
  35. ;unless it can prove that the test doesn't leak any continuations
  36. ;or it does other tricky things.
  37. ;There are some places in the standard that say "it is an error to
  38. ;have multiple returns from this special form", but I don't
  39. ;think "if" is one of them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement