sdr 0.7

net.cscott.sdr.calls.ast
Class If

java.lang.Object
  extended by net.cscott.sdr.calls.ast.AstNode
      extended by net.cscott.sdr.calls.ast.Comp
          extended by net.cscott.sdr.calls.ast.If

public class If
extends Comp

If rejects its child as suitable for execution from the current formation unless its condition evaluates true.

Author:
C. Scott Ananian
Tests:
An If with no message
js> iff = new If(If.When.BEFORE, new Expr("true"), new Seq(Apply.makeApply("nothing")));
(If 'BEFORE (Expr true) (Seq (Apply 'nothing)))
An If with a message and the default priority:
js> iff = new If(If.When.AFTER, new Expr("true"), new Seq(Apply.makeApply("nothing")), "Message!");
(If 'AFTER (Expr true) (Seq (Apply 'nothing)) "Message!")
An If with a user-specified priority:
js> importPackage(net.cscott.sdr.util)
js> iff = new If(If.When.BEFORE, new Expr("true"), new Seq(Apply.makeApply("nothing")), "Message!", Fraction.ONE_HALF);
(If 'BEFORE (Expr true) (Seq (Apply 'nothing)) "Message!" 1/2)

Nested Class Summary
static class If.When
          When to evaluate an If: before or after its child.
 
Field Summary
 Comp child
          The child to evaluate, iff the condition is true.
 Expr condition
          The condition to evaluate.
 String message
          User-friendly message to report if the condition fails, or null.
 Fraction priority
          Priority of the message: if a parallel operation causes failures in multiple places, the one with the highest priority will be reported.
 If.When when
          Evaluate condition before or after the child is evaluated?
 
Fields inherited from class net.cscott.sdr.calls.ast.AstNode
type
 
Constructor Summary
If(If.When when, Expr condition, Comp child)
           
If(If.When when, Expr condition, Comp child, String msg)
           
If(If.When when, Expr condition, Comp child, String msg, Fraction priority)
           
 
Method Summary
<T> Comp
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()
           
 If build(Expr condition, Comp child)
          Factory: creates new If only if it would differ from this.
 
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

when

public final If.When when
Evaluate condition before or after the child is evaluated?


condition

public final Expr condition
The condition to evaluate. Should yield a boolean.


child

public final Comp child
The child to evaluate, iff the condition is true.


message

public final String message
User-friendly message to report if the condition fails, or null.


priority

public final Fraction priority
Priority of the message: if a parallel operation causes failures in multiple places, the one with the highest priority will be reported. The default priority is 1 if a message is specified, or else 0. Negative priorities can be used to specify nonfatal warnings.

Constructor Detail

If

public If(If.When when,
          Expr condition,
          Comp child)

If

public If(If.When when,
          Expr condition,
          Comp child,
          String msg)

If

public If(If.When when,
          Expr condition,
          Comp child,
          String msg,
          Fraction priority)
Method Detail

accept

public <T> Comp 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 Comp

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

build

public If build(Expr condition,
                Comp child)
Factory: creates new If only if it would differ from this.


argsToString

public String argsToString()
Overrides:
argsToString in class AstNode

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian