Skip to content

Instantly share code, notes, and snippets.

@edw
Last active November 21, 2018 18:38
Show Gist options
  • Select an option

  • Save edw/0c3764cd7af7f926bef291ead34a2d8d to your computer and use it in GitHub Desktop.

Select an option

Save edw/0c3764cd7af7f926bef291ead34a2d8d to your computer and use it in GitHub Desktop.
Call-CC Bug in Chibi Scheme?
;; This code displays "(0 1)" in Guile, MIT Scheme, and Scheme48. In
;; Chibi, when evaluated from a REPL, it behaves the same, but subsequent
;; evaluations of `(c0)` signal the following error:
;; > (c0)
;; ERROR in child thread: #<Context 140149901512544>
;; ERROR in travel-to-point! on line 657 of file /usr/local/share/chibi/init-7.scm: non procedure application: #f
;; ERROR in travel-to-point! on line 657 of file /usr/local/share/chibi/init-7.scm: non procedure application: #f
(define (counter n)
(letrec ((generator
(lambda (yield)
(let counter ((n n))
(call-with-current-continuation
(lambda (continue)
(set! generator (lambda (k)
(set! yield k)
(continue n)))
(yield n)))
(counter (+ n 1))))))
(lambda () (call-with-current-continuation generator))))
(define c0 (counter 0))
(display (let* ((zero (c0))
(one (c0)))
(list zero one)))
(newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment