Added code to demonstrate problem of using call/cc within a global definition

This commit is contained in:
Justin Ethier 2015-03-22 09:11:03 -04:00
parent 89526d79e8
commit 28d8c89a71
2 changed files with 69 additions and 49 deletions

View file

@ -11,17 +11,25 @@
;; TODO: define repl iteration, and wrap in an exception handler ;; TODO: define repl iteration, and wrap in an exception handler
; TODO: the below is broken because CPS conversion replaces it with:
;
; ((lambda (call/cc)
; (define repl:next-line
;
; So repl:next-line is never defined as a global!
; We need a better solution
(define (repl:next-line) (define (repl:next-line)
; (call/cc (write '1)
; (lambda (continue) (call/cc
(lambda (k)
(with-exception-handler (with-exception-handler
(lambda (obj) (lambda (obj)
(write (list 'an-error-occurred obj)) (write (list 'an-error-occurred obj))
); (continue #t)) (k #t))
(lambda () (lambda ()
(repl)))) ;) (repl)))))
; (repl:next-line)) (repl:next-line))
;#f)
(define (repl) (define (repl)
(display "cyclone> ") (display "cyclone> ")

View file

@ -23,49 +23,61 @@
;(eval '(a 1)) ;(eval '(a 1))
;(eval '(begin (define (a z) z) (a 1) (a 1))) ;(eval '(begin (define (a z) z) (a 1) (a 1)))
; TODO: demonstrates problem of using call/cc within a global.
(write ; all globals are created with a k parameter, EG:
(with-exception-handler ; ((lambda (call/cc)
(lambda (con) ; (define test
(cond ; (lambda (k$104)
((string? con) ;
(display con)) ; Need to rewrite the code to use this, and preserve the global def
(else (define (test)
(display "a warning has been issued")))
42)
(lambda ()
(+ (raise-continuable "should be a number") 23)
)))
;prints: should be a number
;=> 65
(write
(call/cc (call/cc
(lambda (k) (lambda (k)
(with-exception-handler (k #t))))
(lambda (x) (write (test))
(display "condition: ")
(write x)
;(newline)
(k 'exception))
(lambda ()
(+ 1 (raise 'an-error)))))))
(with-exception-handler ;(write
(lambda (x) ; (with-exception-handler
(display "something went wrong\n")) ; (lambda (con)
(lambda () ; (cond
(+ 1 (raise 'an-error)))) ; ((string? con)
; (display con))
(define test '(a b)) ; (else
(set-car! test '(1 2 3)) ; (display "a warning has been issued")))
(write test) ; 42)
(raise 'done) ; (lambda ()
(define (loop n) ; (+ (raise-continuable "should be a number") 23)
(cond ; )))
((= n 10000) ;;prints: should be a number
(write test) ;;=> 65
(loop 0)) ;
(else ;(write
(loop (+ n 1))))) ; (call/cc
(loop 0) ; (lambda (k)
; (with-exception-handler
; (lambda (x)
; (display "condition: ")
; (write x)
; ;(newline)
; (k 'exception))
; (lambda ()
; (+ 1 (raise 'an-error)))))))
;
;(with-exception-handler
; (lambda (x)
; (display "something went wrong\n"))
; (lambda ()
; (+ 1 (raise 'an-error))))
;
;(define test '(a b))
;(set-car! test '(1 2 3))
;(write test)
;(raise 'done)
;(define (loop n)
; (cond
; ((= n 10000)
; (write test)
; (loop 0))
; (else
; (loop (+ n 1)))))
;(loop 0)