sdr 0.5

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(Condition.makeCondition("true"), new Seq(Apply.makeApply("nothing")));
(If (Condition true) (Seq (Apply nothing)))
An If with a message and the default priority:
js> iff = new If(Condition.makeCondition("true"), new Seq(Apply.makeApply("nothing")), "Message!");
(If (Condition true) (Seq (Apply nothing)) "Message!")
An If with a user-specified priority:
js> importPackage(net.cscott.sdr.util)
js> iff = new If(Condition.makeCondition("true"), new Seq(Apply.makeApply("nothing")), "Message!", Fraction.ONE_HALF);
(If (Condition true) (Seq (Apply nothing)) "Message!" 1/2)

Field Summary
 Comp child
          The child to evaluate, iff the condition is true.
 Condition 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.
 
Fields inherited from class net.cscott.sdr.calls.ast.AstNode
type
 
Constructor Summary
If(Condition condition, Comp child)
           
If(Condition condition, Comp child, String msg)
           
If(Condition 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(Condition 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

condition

public final Condition condition
The condition to evaluate


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(Condition condition,
          Comp child)

If

public If(Condition condition,
          Comp child,
          String msg)

If

public If(Condition 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(Condition 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.5

Copyright © 2006-2009 C. Scott Ananian