The Seasoned Schemer, letcc and guile

前端 未结 1 1135
小蘑菇
小蘑菇 2021-01-02 16:12

A few questions here, regarding letcc that is used in The Seasoned Schemer.

(define (intersect-all sets)
  (letcc hop
    (letrec
      ((A (lam         


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 16:33

    1. "Functional" has several meanings, but no popular meaning contradicts continuations in any way. But they can be abused into creating code that is hard to read. They're not tools that can be "abused for program flow" -- they are program flow tools.

    2. Can't help you there. I know that there was semi-recent on continuations in Guile, but I don't know where things stand. It should definitely have call-with-current-continuation, usually also under the more friendly name of call/cc, and let/cc is a simple macro that can be built with call/cc.

      I can tell you that in Racket there is a let/cc builtin together with a bunch of others builtins in the same family, and additionally there's a whole library of various control operators (with an extensive list of references.).

    3. Simple uses of let/cc are indeed similar to a catch/throw kind of thing -- more specifically, such continuations are commonly known as "escape continuations" (or sometimes "upward"). This is the kind of use that you have in that code, and that is often used to implement an abort or a return.

      But continuations in Scheme are things that can be used in any place. For a very simple example that shows this difference, try this:

      (define (foo f) (f 100))
      (let/cc k (+ (foo k) "junk") (more junk))
      
    4. Finally, if you want to read more about continuations, you can see the relevant parts of PLAI, there's also a more brief by-example overview that Matthew Might wrote, and you can see some class notes that I wrote that are based on PLAI, with some examples that were inspired by the latter post.

    0 讨论(0)
提交回复
热议问题