jsint
Class Procedure

java.lang.Object
  extended byjsint.Procedure
All Implemented Interfaces:
java.lang.Runnable, SchemeProcedure, java.io.Serializable
Direct Known Subclasses:
Closure, Compile, Continuation, JLIB, Networking, Primitive, RawConstructor, RawMethod, Reflector, SNLP, Swing

public abstract class Procedure
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable, SchemeProcedure

Abstract superclass of Procedures. Procedures of no arguments, called "thunks", implement the Runnable interface. To invoke a Procedure from Java, use apply(Pair).

Author:
Peter Norvig, Copyright 1998, peter@norvig.com, license subsequently modified by Jscheme project members licensed under zlib licence (see license.txt)
See Also:
Serialized Form

Field Summary
 int maxArgs
           
 int minArgs
           
 java.lang.String name
           
 
Constructor Summary
Procedure()
           
Procedure(int minArgs, int maxArgs)
           
 
Method Summary
abstract  java.lang.Object apply(java.lang.Object[] args)
          Apply the procedure to an argument list, which is represented as a parameter-oriented array.
 java.lang.Object apply(Pair args)
          Convert an argument list into an argument array, and call apply on that.
 java.lang.Object apply(SchemePair args)
           
static java.lang.Object catching(Procedure E, Procedure F)
          Like tryCatch, but returns wrapped exception.
 java.lang.String getName()
           
 java.lang.Object[] makeArgArray(java.lang.Object[] code, Evaluator eval, LexicalEnvironment lexenv)
          Take the code that represents a call, evaluate arguments in the calling lexical environment and put results into an argument array.
 java.lang.Object[] makeArgArray(Pair args)
          Convert a list of arguments into an array expected by the procedure.
 int nParms()
          How many parameters does this procedure have.
 void run()
           
 java.lang.Object setName(java.lang.Object name)
          If the procedure has not yet been named, name it.
static java.lang.Object stripExceptionWrapper(java.lang.Object e)
           
static java.lang.Object synchronize(java.lang.Object x, Procedure p)
           
static java.lang.Object throwObject(java.lang.Object e)
           
static java.lang.Object throwRuntimeException(java.lang.RuntimeException E)
          provide scheme access to the exception throwing
 java.lang.String toString()
           
protected  java.lang.String toStringArgs()
           
static java.lang.Object tryCatch(java.lang.Object E, java.lang.Object F)
          provide scheme access to the "try/catch" expression of Java
static java.lang.Object tryFinally(java.lang.Object e, java.lang.Object f)
          Provide scheme access to finally - unwind-protect.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name

minArgs

public int minArgs

maxArgs

public int maxArgs
Constructor Detail

Procedure

public Procedure()

Procedure

public Procedure(int minArgs,
                 int maxArgs)
Method Detail

getName

public java.lang.String getName()

setName

public java.lang.Object setName(java.lang.Object name)
If the procedure has not yet been named, name it. The idea is if I do (define (id x) x) and then (define default-proc id), then the procedure is called "id".


nParms

public int nParms()
How many parameters does this procedure have. This is different than the number of arguments it expects. For example, list expects any number of arguments, but it has only one parameter.


toStringArgs

protected java.lang.String toStringArgs()

toString

public java.lang.String toString()

run

public void run()
Specified by:
run in interface java.lang.Runnable

apply

public abstract java.lang.Object apply(java.lang.Object[] args)
Apply the procedure to an argument list, which is represented as a parameter-oriented array. That is, if the procedure p has the parameter list (x y . z) and the call is (p 1 2 3 4) then args will be the array {1, 2, (3 4)}.

Specified by:
apply in interface SchemeProcedure

apply

public java.lang.Object apply(SchemePair args)
Specified by:
apply in interface SchemeProcedure

apply

public java.lang.Object apply(Pair args)
Convert an argument list into an argument array, and call apply on that.


catching

public static java.lang.Object catching(Procedure E,
                                        Procedure F)
Like tryCatch, but returns wrapped exception.


tryCatch

public static java.lang.Object tryCatch(java.lang.Object E,
                                        java.lang.Object F)
provide scheme access to the "try/catch" expression of Java


stripExceptionWrapper

public static java.lang.Object stripExceptionWrapper(java.lang.Object e)

tryFinally

public static java.lang.Object tryFinally(java.lang.Object e,
                                          java.lang.Object f)
Provide scheme access to finally - unwind-protect.


throwRuntimeException

public static java.lang.Object throwRuntimeException(java.lang.RuntimeException E)
                                              throws java.lang.RuntimeException
provide scheme access to the exception throwing

Throws:
java.lang.RuntimeException

throwObject

public static java.lang.Object throwObject(java.lang.Object e)
                                    throws java.lang.Throwable
Throws:
java.lang.Throwable

synchronize

public static java.lang.Object synchronize(java.lang.Object x,
                                           Procedure p)

makeArgArray

public java.lang.Object[] makeArgArray(java.lang.Object[] code,
                                       Evaluator eval,
                                       LexicalEnvironment lexenv)
Take the code that represents a call, evaluate arguments in the calling lexical environment and put results into an argument array. Note that code[0] is the procedure, not an argument. For example, (p 1 2 3 (+ 2 2)) turns into the code {p, 1, 2, 3, {+, 2, 2}}, and if p has the parameter list (x y . z) then p.makeArgArray(code, lexenv) would return {1, 2, (3 4)}.


makeArgArray

public java.lang.Object[] makeArgArray(Pair args)
Convert a list of arguments into an array expected by the procedure. (See apply for an explanation of what is expected.)