是什么让这个lwp程序的动作在直接加载到命令行和使用加载过程之间有什么不同?

时间:2016-12-06 10:47:03

标签: scheme continuations guile callcc

我使用guile 2.0.13作为我的方案解释器,我编写了文件3.3.3.scm,如下所示:

(define lwp-list '())

(define quit-k #f)

(define lwp
  (lambda (thunk)
    (set! lwp-list (append lwp-list (list thunk)))))

(define start
  (lambda ()
    (if (not quit-k)
        (set! quit-k (call/cc (lambda (k) k))))
    (if (not (null? lwp-list))
        (let ([p (car lwp-list)])
          (set! lwp-list (cdr lwp-list))
          (p)))))

(define pause
  (lambda ()
    (call/cc
     (lambda (k)
       (lwp (lambda () (k #f)))
       (start)))))

(define quit
  (lambda ()
    (set! lwp-list '())
    (quit-k #f)))

(lwp (lambda () (let f () (pause) (display "h") (f))))
(lwp (lambda () (let f () (pause) (display "e") (f))))
(lwp (lambda () (let f () (pause) (display "y") (f))))
(lwp (lambda () (let f () (pause) (display "!") (f))))
(lwp (lambda () (let f () (pause) (newline) (f))))
(lwp (lambda () (let f () (pause) (quit))))
(start)

如果我在交互界面中使用3.3.3.scm(load "3.3.3.scm")似乎运行正常。但是当我直接运行guile 3.3.3.scm时,将在quit第一次调用后调用过程guile

hey!
Backtrace:
In ice-9/boot-9.scm:
 160: 3 [catch #t #<catch-closure 17db460> ...]
In unknown file:
   ?: 2 [apply-smob/1 #<catch-closure 17db460>]
In ice-9/boot-9.scm:
  66: 1 [call-with-prompt prompt0 ...]
In unknown file:
   ?: 0 [#f #f]

ERROR: In procedure #f:
ERROR: Wrong type to apply: #f

这种差异是什么情况?

0 个答案:

没有答案