sdr 0.7

net.cscott.sdr.calls.ast
Class Apply

java.lang.Object
  extended by net.cscott.sdr.calls.ast.AstNode
      extended by net.cscott.sdr.calls.ast.SeqCall
          extended by net.cscott.sdr.calls.ast.Apply

public class Apply
extends SeqCall

Apply represents a invocation of a call or concept, with zero or more arguments. The call field of the Apply gives an expression for the call (which can be converted to a Call object with CallDB.lookup(String) or to an Evaluator using Expr.evaluate(Class, DanceState)). Note that 'and' is a concept used to sequentially join calls: the caller's "slip and slide" would be represented as:

 and(slip, slide)
 (Apply (Expr and 'slip 'slide))
 
The children of this node represent the arguments. Numeric or matcher arguments are represented as text beneath a "literal" expression, to distinguish them from similarly-named functions which might be evaluated to yield a Call value. For example, "twice (trade and roll)" is:
 _fractional(2, _roll(trade))
 (Apply _fractional '2 (Expr _roll 'trade))
 

Version:
$Id: Apply.java,v 1.9 2006-10-19 21:00:09 cananian Exp $
Author:
C. Scott Ananian
Tests:
Actual code for examples in the class description:
js> a = new Apply(new Expr("and", Expr.literal("slip"), Expr.literal("slide")))
(Apply (Expr and 'slip 'slide))
js> a.toShortString()
and(slip, slide)
js> importPackage(net.cscott.sdr.util)
js> a = new Apply(new Expr("_fractional", Expr.literal(Fraction.TWO),
  >                        new Expr("_roll", Expr.literal("trade"))))
(Apply (Expr _fractional '2 (Expr _roll 'trade)))
js> a.toShortString()
_fractional(2, _roll(trade))

Field Summary
 Expr call
           
 
Fields inherited from class net.cscott.sdr.calls.ast.AstNode
type
 
Constructor Summary
Apply(Expr call)
           
 
Method Summary
<T> SeqCall
accept(TransformVisitor<T> v, T t)
          Visitor pattern implementation for transformations.
<RESULT,CLOSURE>
RESULT
accept(ValueVisitor<RESULT,CLOSURE> v, CLOSURE cl)
          Visitor pattern implementation for computations.
 String argsToString()
           
 Apply build(Expr call)
          Factory: creates new Apply only if it would differ from this.
 Evaluator evaluator(DanceState ds)
           
 boolean isIndeterminate()
          True if the result of SeqCall.parts() can not be used for fractionalization.
static Apply makeApply(String callName)
           
 Expr parts()
          How many 'parts' are represented by this SeqCall.
 String toShortString()
          Emit an apply in the form it appears in the call definition lists.
 
Methods inherited from class net.cscott.sdr.calls.ast.AstNode
toString, valueOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

call

public final Expr call
Constructor Detail

Apply

public Apply(Expr call)
Method Detail

parts

public Expr parts()
Description copied from class: SeqCall
How many 'parts' are represented by this SeqCall. Should be Expr.literal(Fraction.ONE) for all but Part.

Specified by:
parts in class SeqCall

isIndeterminate

public boolean isIndeterminate()
Description copied from class: SeqCall
True if the result of SeqCall.parts() can not be used for fractionalization.

Specified by:
isIndeterminate in class SeqCall

accept

public <T> SeqCall accept(TransformVisitor<T> v,
                          T t)
Description copied from class: AstNode
Visitor pattern implementation for transformations. Each AstNode accepts a TransformVisitor and a value, and returns an instance of its own type (ie, Seq.accept(tv, "A") returns a Seq). The 't' parameter is a closure.

Specified by:
accept in class SeqCall

accept

public <RESULT,CLOSURE> RESULT accept(ValueVisitor<RESULT,CLOSURE> v,
                                      CLOSURE cl)
Description copied from class: AstNode
Visitor pattern implementation for computations. Each AstNode accepts a ValueVisitor and a closure, and returns an object of the appropriate result type.

Specified by:
accept in class AstNode

argsToString

public String argsToString()
Overrides:
argsToString in class AstNode

evaluator

public Evaluator evaluator(DanceState ds)
                    throws BadCallException
Throws:
BadCallException

toShortString

public String toShortString()
Emit an apply in the form it appears in the call definition lists.


makeApply

public static Apply makeApply(String callName)

build

public Apply build(Expr call)
Factory: creates new Apply only if it would differ from this.


sdr 0.7

Copyright © 2006-2009 C. Scott Ananian