mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
Added code to demonstrate problem of using call/cc within a global definition
This commit is contained in:
parent
89526d79e8
commit
28d8c89a71
2 changed files with 69 additions and 49 deletions
20
icyc.scm
20
icyc.scm
|
@ -11,17 +11,25 @@
|
|||
|
||||
;; 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)
|
||||
; (call/cc
|
||||
; (lambda (continue)
|
||||
(write '1)
|
||||
(call/cc
|
||||
(lambda (k)
|
||||
(with-exception-handler
|
||||
(lambda (obj)
|
||||
(write (list 'an-error-occurred obj))
|
||||
); (continue #t))
|
||||
(k #t))
|
||||
(lambda ()
|
||||
(repl)))) ;)
|
||||
; (repl:next-line))
|
||||
;#f)
|
||||
(repl)))))
|
||||
(repl:next-line))
|
||||
|
||||
(define (repl)
|
||||
(display "cyclone> ")
|
||||
|
|
98
test.scm
98
test.scm
|
@ -23,49 +23,61 @@
|
|||
;(eval '(a 1))
|
||||
;(eval '(begin (define (a z) z) (a 1) (a 1)))
|
||||
|
||||
|
||||
(write
|
||||
(with-exception-handler
|
||||
(lambda (con)
|
||||
(cond
|
||||
((string? con)
|
||||
(display con))
|
||||
(else
|
||||
(display "a warning has been issued")))
|
||||
42)
|
||||
(lambda ()
|
||||
(+ (raise-continuable "should be a number") 23)
|
||||
)))
|
||||
;prints: should be a number
|
||||
;=> 65
|
||||
|
||||
(write
|
||||
; TODO: demonstrates problem of using call/cc within a global.
|
||||
; all globals are created with a k parameter, EG:
|
||||
; ((lambda (call/cc)
|
||||
; (define test
|
||||
; (lambda (k$104)
|
||||
;
|
||||
; Need to rewrite the code to use this, and preserve the global def
|
||||
(define (test)
|
||||
(call/cc
|
||||
(lambda (k)
|
||||
(with-exception-handler
|
||||
(lambda (x)
|
||||
(display "condition: ")
|
||||
(write x)
|
||||
;(newline)
|
||||
(k 'exception))
|
||||
(lambda ()
|
||||
(+ 1 (raise 'an-error)))))))
|
||||
(k #t))))
|
||||
(write (test))
|
||||
|
||||
(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)
|
||||
;(write
|
||||
; (with-exception-handler
|
||||
; (lambda (con)
|
||||
; (cond
|
||||
; ((string? con)
|
||||
; (display con))
|
||||
; (else
|
||||
; (display "a warning has been issued")))
|
||||
; 42)
|
||||
; (lambda ()
|
||||
; (+ (raise-continuable "should be a number") 23)
|
||||
; )))
|
||||
;;prints: should be a number
|
||||
;;=> 65
|
||||
;
|
||||
;(write
|
||||
; (call/cc
|
||||
; (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)
|
||||
|
|
Loading…
Add table
Reference in a new issue