[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Continuations



      Heresy!  Internally, T uses continuations all the  time  (surely
      you've seen these  while  crawling  through  the  stack with DEBUG).
      Users can also write them either by passing  LAMBDAs  or  by  using
      CATCH  (which is even  implemented as CALL-WITH-CONTINUATION).  The
      current T compiler doesn't take as much advantage of them as the
      prototype T  3.0  compiler does.  In  terms  of  running Lisp code,
      continuations are important for eliminating tail-recursion, etc.  Take
      a  peek  at  Abelson  &  Sussman, "Sturcture and  Interpretation  of
      Computer Programs."  But for general programming, passing
      continuations is  very  useful,  particularly  when you pass  more
      than  one;  each  indicates "what to do next" (i.e., how to continue
      the computation) in some particular  case,  which  can  lead to code
      that's  much  more  elegant than code that returns flags to the
      caller, or worse, multiple flags.  Continuations are  described  in
      the first   edition   of  Charniak,  Riesbeck,  and  McDermott,
      "Artificial Intelligence Programming," (Chapter 17,  I  think).   That
      section  has been  rewritten  in  the  new  edition  (which  Chris and
      I are just now finishing).

T does indeed use continuations internally and you can make them yourself
with LAMBDA expressions. In fact I do just that when compile TLOG (logic
programming) into T.  What T does not support is just the type of
continuations decribed in AI Programming, the kind that let you return to a
previous state of the computation.  Doing it with LAMBDAs is not as nice,
and its supported in COMMON LISP.

	You might  also  want  to read the "LAMBDA papers," a collection of
	tech reports from MIT written by Steele and Sussman in the days
	when  Scheme was still  being invented.  Steele's thesis also gives
	a pretty thorough description of the  continuation-passing  style
	(CPS),  e.g.,  how  any Lisp program  can  be  transformed  into
	CPS, which permits all sorts of optimizations.  "Returning"  a
	value  means  calling  the  continuation with that  value  as an
	argument.  The reason multiple-values (in Common Lisp) are
	semantically nice is that  they  can  (should)  be  viewed  as a
	notation/mechanism   for   calling  the  continuation  with  several
	arguements, not just one.

Thanks for the pointers.