jsint
Class Closure
java.lang.Object
jsint.Procedure
jsint.Closure
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Runnable, SchemeProcedure
- Direct Known Subclasses:
- Macro
public class Closure
- extends Procedure
- implements java.lang.Cloneable
A closure is a user-defined procedure. It is "closed" over the
environment in which it was created. To apply the procedure, bind
the parameters to the passed in variables, and evaluate the body.
- Author:
- Peter Norvig, Copyright 2000, peter@norvig.com, license
subsequently modified by Jscheme project members
licensed under zlib licence (see license.txt)
- See Also:
- Serialized Form
Constructor Summary |
Closure(java.lang.Object parms,
java.lang.Object body,
LexicalEnvironment lexenv)
Make a closure from a body and the analyze time environment it
was defined in. |
Method Summary |
java.lang.Object |
apply(java.lang.Object[] args)
Apply a closure to a vector of arguments. |
Closure |
copy(LexicalEnvironment lexenv)
Make a copy, but with a runtime environment. |
java.lang.Object |
setName(java.lang.Object name)
If the procedure has not yet been named, name it. |
java.lang.String |
toString()
|
Methods inherited from class jsint.Procedure |
apply, apply, catching, getName, makeArgArray, makeArgArray, nParms, run, stripExceptionWrapper, synchronize, throwObject, throwRuntimeException, toStringArgs, tryCatch, tryFinally |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Closure
public Closure(java.lang.Object parms,
java.lang.Object body,
LexicalEnvironment lexenv)
- Make a closure from a body and the analyze time environment it
was defined in. To create a closure at execute time, use .copy()
apply
public java.lang.Object apply(java.lang.Object[] args)
- Apply a closure to a vector of arguments. Do this by creating a
new LexicalEnvironment containing the arguments, and then
evaluating the body of the closure in that new frame.
- Specified by:
apply
in interface SchemeProcedure
- Specified by:
apply
in class Procedure
copy
public Closure copy(LexicalEnvironment lexenv)
- Make a copy, but with a runtime environment.
toString
public java.lang.String toString()
- Overrides:
toString
in class Procedure
setName
public java.lang.Object setName(java.lang.Object name)
- Description copied from class:
Procedure
- 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".
- Overrides:
setName
in class Procedure