Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

silk
Class Closure  view Closure download Closure.java

java.lang.Object
  extended bysilk.Procedure
      extended bysilk.Closure
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Runnable
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.


Field Summary
(package private)  java.lang.Object body
           
(package private)  Environment env
           
(package private)  java.lang.Object parms
           
 
Fields inherited from class silk.Procedure
maxArgs, minArgs, name
 
Constructor Summary
Closure(java.lang.Object parms, java.lang.Object body, Environment env)
          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.
private  void computeArgs(java.lang.Object parms, int min)
          Compute minArgs and maxArgs from the parameter list
 Closure copy(Environment env)
          Make a copy, but with a runtime environment.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class silk.Procedure
apply, makeArgArray, makeArgArray, nParms, run, setName, throwObject, throwRuntimeException, toStringArgs, tryCatch, tryFinally
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

body

java.lang.Object body

env

Environment env

parms

java.lang.Object parms
Constructor Detail

Closure

public Closure(java.lang.Object parms,
               java.lang.Object body,
               Environment env)
Make a closure from a body and the analyze time environment it was defined in. To create a closure at execute time, use .copy()

Method Detail

computeArgs

private void computeArgs(java.lang.Object parms,
                         int min)
Compute minArgs and maxArgs from the parameter list


apply

public java.lang.Object apply(java.lang.Object[] args)
Apply a closure to a vector of arguments. Do this by creating a new Environment containing the arguments, and then evaluating the body of the closure in that new frame.

Specified by:
apply in class Procedure

copy

public Closure copy(Environment env)
Make a copy, but with a runtime environment.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).

Overrides:
toString in class Procedure