標高+1m

Don't be rational.

call/ccの合成の解

compose-c/cc

やりたかったのはこういうことでした。

たまに便利なことがあると思う。

(define (compose-c/cc . fs)
  (letrec ((vals (list->vector
                  (map (^ (f i)
                          (f (lambda (res)
                               (vector-set! vals i res)
                               (when cont (cont)))))
                             fs
                             (iota (length fs)))))
           (cont #f))
    (call/cc (lambda (k) (set! cont k)))
    (vector->list vals)))

(console-log (apply string-append
                 (compose-c/cc (^ (k) (timer (^ () (k "good")) 3)
                                  "hello ")
                               (^ (k) (timer (^ () (k "bye")) 2)
                                  "world")
                               (^ (k) (timer (^ () (k " :)")) 5)
                                  "!"))))