Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define xs #f)
- (set! xs '()) ;ensure Racket will permit rebinding of xs at the REPL
- (define cont #f)
- (define (meh x)
- (let ((y (vector x 10)))
- ;(display y)
- (if (test x)
- y
- x)))
- (define (test x)
- (call-with-current-continuation
- (lambda (c)
- (set! cont c)))
- (even? x))
- (set! xs (cons (meh 8) xs))
- (cont 'ignored)
- (eq? (car xs) (cadr xs))
- ;=> #f, which I believe is wrong.
- ;If you uncomment the (display y), then this returns #t.
- ;[Also, Chicken returns #t regardless.]
- ;The uncommenting appears to *force* the compiler to create the
- ;vector y before (test x), and so any continuation saved from
- ;there will retain the identical y.
- ;On the other hand, if Racket accepts this as wrong, this makes
- ;it impossible for it to hoist constructors into if-branches
- ;unless it can prove that the test doesn't leak any continuations
- ;or it does other tricky things.
- ;There are some places in the standard that say "it is an error to
- ;have multiple returns from this special form", but I don't
- ;think "if" is one of them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement