sdr 0.7

net.cscott.sdr.calls
Class ExprList

java.lang.Object
  extended by net.cscott.sdr.calls.ExprList

public class ExprList
extends Object

The ExprList contains ExprFunc definitions and the basic machinery used to evaluate generic Exprs.


Field Summary
static ExprFunc<Fraction> _ADD_NUM
          Simple math: addition.
static ExprFunc _APPLY
           
static ExprFunc<String> _COUPLE_NUM_PATTERN
          The _COUPLE_NUM_PATTERN is mostly for determining when we're "at home".
static ExprFunc<Fraction> _DIVIDE_NUM
          Simple math: division.
static ExprFunc<String> _FACING_PATTERN
           
static ExprFunc<Fraction> _FLOOR
          Simple math: return integer part of a fraction.
static ExprFunc<Fraction> _FRACTION
          Simple math: return fractional part of a number.
static ExprFunc _IF
           
static ExprFunc<String> _INOUT_PATTERN
          Check whether dancers are facing "in" or "out" of the center of the formation.
static ExprFunc<Fraction> _MOD_NUM
          Simple math: modulo.
static ExprFunc<Fraction> _MULTIPLY_NUM
          Simple math: multiplication.
static ExprFunc<String> _PROPERTY
          The _PROPERTY function interrogates the dance engine's environment, as exposed by DanceState.property(String, String).
static ExprFunc<String> _ROLL_PATTERN
           
static ExprFunc<String> _SELECTION_PATTERN
          Check the order of the selected dancers within the given formation.
static ExprFunc<Fraction> _SUBTRACT_NUM
          Simple math: subtraction.
static ExprFunc<String> _SWEEP_PATTERN
           
static ExprFunc LITERAL
           
static ExprFunc<Fraction> NUM_DANCERS
           
 
Method Summary
static
<T> T
evaluate(String atom, Class<T> type, DanceState ds, List<Expr> args)
          This method evaluates Expr nodes.
static
<T> boolean
isConstant(String atom, Class<T> type, List<Expr> args)
          This method tells whether an Expr will result in a constant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LITERAL

public static final ExprFunc LITERAL

_IF

public static final ExprFunc _IF

_APPLY

public static final ExprFunc _APPLY

_ADD_NUM

public static final ExprFunc<Fraction> _ADD_NUM
Simple math: addition.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _add num '2 '1)")
(Expr _add num '2 '1)
js> c.evaluate(fc, ds).toProperString()
3

_MULTIPLY_NUM

public static final ExprFunc<Fraction> _MULTIPLY_NUM
Simple math: multiplication.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _multiply num '3 '2)")
(Expr _multiply num '3 '2)
js> c.evaluate(fc, ds).toProperString()
6

_SUBTRACT_NUM

public static final ExprFunc<Fraction> _SUBTRACT_NUM
Simple math: subtraction.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _subtract num '3 '2)")
(Expr _subtract num '3 '2)
js> c.evaluate(fc, ds).toProperString()
1

_DIVIDE_NUM

public static final ExprFunc<Fraction> _DIVIDE_NUM
Simple math: division.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _divide num '3 '2)")
(Expr _divide num '3 '2)
js> c.evaluate(fc, ds).toProperString()
1 1/2

_MOD_NUM

public static final ExprFunc<Fraction> _MOD_NUM
Simple math: modulo.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _mod num '3/4 '1/2)")
(Expr _mod num '3/4 '1/2)
js> c.evaluate(fc, ds).toProperString()
1/4

_FLOOR

public static final ExprFunc<Fraction> _FLOOR
Simple math: return integer part of a fraction.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _floor '3 3/4)")
(Expr _floor '3 3/4)
js> c.evaluate(fc, ds).toProperString()
3
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _floor (Expr _subtract num '0 '3 3/4))")
(Expr _floor (Expr _subtract num '0 '3 3/4))
js> c.evaluate(fc, ds).toProperString()
-4

_FRACTION

public static final ExprFunc<Fraction> _FRACTION
Simple math: return fractional part of a number.

Tests:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> fc = java.lang.Class.forName('net.cscott.sdr.util.Fraction'); undefined
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _fraction '3 3/4)")
(Expr _fraction '3 3/4)
js> c.evaluate(fc, ds).toProperString()
3/4
js> // note that (floor(n) + fraction(n)) = n
js> c=net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _fraction (Expr _subtract num '0 '3 3/4))")
(Expr _fraction (Expr _subtract num '0 '3 3/4))
js> c.evaluate(fc, ds).toProperString()
1/4

NUM_DANCERS

public static final ExprFunc<Fraction> NUM_DANCERS

_ROLL_PATTERN

public static final ExprFunc<String> _ROLL_PATTERN

_SWEEP_PATTERN

public static final ExprFunc<String> _SWEEP_PATTERN

_FACING_PATTERN

public static final ExprFunc<String> _FACING_PATTERN

_COUPLE_NUM_PATTERN

public static final ExprFunc<String> _COUPLE_NUM_PATTERN
The _COUPLE_NUM_PATTERN is mostly for determining when we're "at home".

Tests:
Dancers in pattern are in "reading order":
js> let expr = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _COUPLE NUM PATTERN)");
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET); undefined
js> sc = java.lang.Class.forName("java.lang.String")
class java.lang.String
js> expr.evaluate(sc, ds)
33424211

_INOUT_PATTERN

public static final ExprFunc<String> _INOUT_PATTERN
Check whether dancers are facing "in" or "out" of the center of the formation. Dancers facing south or west in the top-right quadrant (positive x and y) are facing "in", dancers facing north or east in the top quadrant are facing "out". Where in/out direction can not be determined, this function uses an "x".

Tests:
js> FormationList = FormationList.js(this); undefined;
js> SD = StandardDancer; undefined
js> e = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _INOUT PATTERN)");
(Expr _INOUT PATTERN)
js> f=FormationList.PARALLEL_RH_WAVES ; f.toStringDiagram()
^    v    ^    v

^    v    ^    v
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> e.evaluate(java.lang.Class.forName("java.lang.String"), ds);
oioiioio
js> f = FormationList.TRADE_BY; f.toStringDiagram()
^    ^

v    v

^    ^

v    v
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> e.evaluate(java.lang.Class.forName("java.lang.String"), ds);
ooiiiioo
js> f = Formation.SQUARED_SET ; f.toStringDiagram()
     3Gv  3Bv

4B>            2G<

4G>            2B<

     1B^  1G^
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> e.evaluate(java.lang.Class.forName("java.lang.String"), ds);
iiiiiiii
js> f = Formation.SQUARED_SET.rotate(ExactRotation.ONE_EIGHTH) ; f.toStringDiagram()
     4BQ       3GL

4GQ                 3BL



1B7                 2G`

     1G7       2B`
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> e.evaluate(java.lang.Class.forName("java.lang.String"), ds);
iiiiiiii
js> f = FormationList.SINGLE_STATIC_SQUARE ; f.toStringDiagram("|")
|     v
|
|>         <
|
|     ^
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> e.evaluate(java.lang.Class.forName("java.lang.String"), ds);
iiii
js> f = FormationList.THAR ; f.toStringDiagram("|")
|       <
|
|       >
|v    ^    v    ^
|       <
|
|       >
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> e.evaluate(java.lang.Class.forName("java.lang.String"), ds);
xxxxxxxx

_SELECTION_PATTERN

public static final ExprFunc<String> _SELECTION_PATTERN
Check the order of the selected dancers within the given formation.

Tests:
Dancers in pattern are in "reading order":
js> let expr = net.cscott.sdr.calls.ast.AstNode.valueOf(
  >           "(Expr _SELECTION PATTERN 'BOY)");
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET); undefined
js> sc = java.lang.Class.forName("java.lang.String")
class java.lang.String
js> expr.evaluate(sc, ds)
_XX__XX_
Examples using the MATCH predicate:
js> FormationList = FormationList.js(this); undefined;
js> SD = StandardDancer; undefined
js> f = FormationList.RH_OCEAN_WAVE; f.toStringDiagram()
^    v    ^    v
js> // label those dancers
js> f= f.mapStd([SD.COUPLE_1_BOY, SD.COUPLE_1_GIRL,
  >              SD.COUPLE_3_BOY, SD.COUPLE_3_GIRL]); f.toStringDiagram()
1B^  1Gv  3B^  3Gv
js> ds = new DanceState(new DanceProgram(Program.PLUS), f); undefined;
js> function test(sel, pat) {
  >   let c = net.cscott.sdr.calls.ast.AstNode.valueOf(
  >           "(Expr MATCH (Expr _SELECTION PATTERN '"+sel+") '\""+pat+"\")");
  >    return PredicateList.valueOf(c.atom).evaluate(ds, c.args)
  > }
js> test('BOY', '____')
false
js> test('BOY', 'x_x_')
true
js> test('BOY', '_x_x')
false
js> test('CENTER', '_xx_')
true
js> test('HEAD', 'xxxx')
true
js> test('SIDE', '____')
true
js> test('COUPLE 1', 'xx__')
true
js> test('SIDE', '_xx_')
false
js> // wildcards
js> test('BOY', 'x...')
true

_PROPERTY

public static final ExprFunc<String> _PROPERTY
The _PROPERTY function interrogates the dance engine's environment, as exposed by DanceState.property(String, String).

Tests:
js> let expr = net.cscott.sdr.calls.ast.AstNode.valueOf("(Expr _PROPERTY 'foo 'bar)");
js> sc = java.lang.Class.forName("java.lang.String"); undefined
js> // default dance state contains no property mappings
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET); undefined
js> expr.evaluate(sc, ds)
bar
js> // construct a simple property map
js> m = new java.util.HashMap(); m.put('foo', 'bat'); m.toString();
{foo=bat}
js> ds = new DanceState(new DanceProgram(Program.PLUS), Formation.SQUARED_SET, m); undefined
js> expr.evaluate(sc, ds)
bat
Method Detail

evaluate

public static <T> T evaluate(String atom,
                             Class<T> type,
                             DanceState ds,
                             List<Expr> args)
                  throws ExprFunc.EvaluationException
This method evaluates Expr nodes.

Throws:
ExprFunc.EvaluationException

isConstant

public static <T> boolean isConstant(String atom,
                                     Class<T> type,
                                     List<Expr> args)
This method tells whether an Expr will result in a constant.


sdr 0.7

Copyright © 2006-2009 C. Scott Ananian