Fun with call/cc (was RE: [Python-Dev] Stackless Python (original) (raw)

Tim Peters tim_one@email.msn.com
Mon, 7 Aug 2000 17:52:18 -0400


[Tim]

On the one hand, I don't think I know of a language not based on Scheme that has call/cc (or a moral equivalent).

[Jeremy Hylton]

ML also has call/cc, at least the Concurrent ML variant.

So it does! I've found 3 language lines that have full-blown call/cc (not counting the early versions of REBOL, since they took it out later), and at least one web page claiming "that's all, folks":

  1. Scheme + derivatives (but not including most Lisps).

  2. Standard ML + derivatives (but almost unique among truly functional languages):

    http://cm.bell-labs.com/cm/cs/what/smlnj/doc/SMLofNJ/pages/cont.html

    That page is pretty much incomprehensible on its own. Besides callcc (no "/"), SML-NJ also has related "throw", "isolate", "capture" and "escape" functions. At least some of them appear to be addressing Kent Pitman's specific complaints about the excruciating interactions between call/cc and unwind-protect in Scheme.

  3. Unlambda. This one is a hoot! Don't know why I haven't bumped into it before:

    http://www.eleves.ens.fr:8080/home/madore/programs/unlambda/ "Your Functional Programming Language Nightmares Come True"

    Unlambda is a deliberately obfuscated functional programming language, whose only data type is function and whose only syntax is function application: no lambdas (or other "special forms"), no integers, no lists, no variables, no if/then/else, ... call/cc is spelled with the single letter "c" in Unlambda, and the docs note "expressions including c function calls tend to be hopelessly difficult to track down. This was, of course, the reason for including it in the language in the first place".

    Not all frivolous, though! The page goes on to point out that writing an interpreter for Unlambda in something other than Scheme exposes many of the difficult issues (like implementing call/cc in a language that doesn't have any such notion -- which is, after all, almost all languages), in a language that's otherwise relentlessly simple-minded so doesn't bog you down with accidental complexities.

Doesn't mean call/cc sucks, but language designers have been avoiding it in vast numbers -- despite that the Scheme folks have been pushing it (& pushing it, & pushing it) in every real language they flee to .

BTW, lest anyone get the wrong idea, I'm (mostly) in favor of it! It can't possibly be sold on any grounds other than that "it works, for real Python programmers with real programming problems they can't solve in other ways", though. Christian has been doing a wonderful (if slow-motion ) job of building that critical base of real-life users.