Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!news From: gat@robotics.jpl (Erann Gat) Newsgroups: comp.lang.lisp Subject: In defense of call/cc (and a plug for T) Message-ID: <1991Feb12.233157.20820@elroy.jpl.nasa.gov> Date: 12 Feb 91 23:31:57 GMT Sender: news@elroy.jpl.nasa.gov (Usenet) Organization: Jet Propulsion Laboratory, Pasadena, California Lines: 51 Nntp-Posting-Host: robotics.jpl.nasa.gov This is a (probably) vain plea to see call-with-current-continuation included in common lisp. There are a number of reasons that call/cc should be included. 1. It cannot be implemented in terms of existing CL constructs, so you can't build it even if you want to. You can build a downward-only call/cc, but see the note below. 2. It is not that hard to implement. Including call/cc would not make compilers that much more complex. All that call/cc does is copy the stack onto the heap. 3. Call/cc makes it INFINITELY less painful to write coroutines. For example, here's a short piece of code that allows you to interleave the execution of an arbitrary number of arbitrary functions: (This is written in T, which allows continuations to take an arbitrary number of arguments and return them as multiple values.) (define (scheduler . fns) (set *queue* (append *queue* fns)) (if (null? *queue*) (escape) (let ( (fn (pop *queue*)) ) (fn) (scheduler)))) (define-syntax (define-coroutine name&args . body) `(define ,name&args (call/cc scheduler) ,@body)) (call/cc (lambda (esc) (define escape esc))) There. Coroutines in ten lines of fairly transparent code, but it requires upward continuations so you can't do this sort of thing in CL as it stands now. BTW: T is NOT just another dialect of Scheme. It provides an object primitive which cannot be implemented in pure Scheme. (You can come very close, but you can't implement it exactly.) The T object construct, besides providing an elegant vehicle for doing object-oriented programming, also has the pleasant side effect of elegantly solving the SETQ/SETF problem. It also lets you do things like redefine a function to give it a different name and still have (SET (new-name ...) ...) work. T also has a structure primitive which lets you access all the slot names and accessor functions in a very neat way. It also extends call/cc as described above. Unfortunately, no one is commercializing T, so it's hard to get support or good development environmnts. So, if we can't have T, can't we at least get call/cc with our CL? (And STYPES? And Objects? And... :-) E.