package kawa.standard;
import kawa.lang.*;
import gnu.mapping.*;

/**
 * Implement the Scheme standard function "call-with-current-continuation".
 * This is a restricted version, that only works for escape-like applications.
 * @author Per Bothner
 */

public class callcc extends Procedure1
{
  /** Call a precedure with the current continuation. */
  public static Object apply (Procedure proc)
  {
    Continuation cont = new Continuation ();
    try
      {
	return proc.apply1 (cont);
      }
    catch (CalledContinuation ex)
      {
	if (ex.continuation != cont)
	  throw ex;
	return ex.value;
      }
    finally
      {
	cont.invoked = true;
      }
  }

  public Object apply1 (Object arg1)
  {
    Procedure proc;
    try
      {
	proc = (Procedure) arg1;
      }
    catch (ClassCastException ex)
      {
	throw new GenericError ("argument to call/cc is not procedure");
      }
    return apply (proc);
  }

}

@@ -398,16 +398,26 @@
   %7B%0A    
+kawa.lang.
 Continua
@@ -432,16 +432,26 @@
 t = new 
+kawa.lang.
 Continua

Add disambiguation.