Attached is a small example of what I've written up as a "rough draft" of sorts. You are welcome to take or leave it. I've named the build "Archimedes" which I thought was somewhat appropriate.
Mark,
In there the functions and operators take directly number as arguments... why ? Why don't they take sub-expressions ? (it should be something like setOperand(MathObject ob))... wether it can be computable or not could be checked at set time but they should, I believe, only be checked at run-time...
Also, you differentiate between Operators and Functions... I don't really see why... the difference is mostly notational.
I also think Multiply and Adds should be multi-argument, not just binary...
So I would sort of revise Sqrt.java into:
private MathObject argument;
public void setParent(MathObject parent)
public MathObject getParent... public void setOperand(MathObject argument) {
this.argument = argument;
} public MathObject evaluate(EvaluatingContext context)
throws EvaluationException {MathObject argEvaluated = argument.evaluate(context);
if ( EvaluatingContext instanceof DoubleEvaluating ) {
double argAsDouble =
((DoubleEvaluating)context).getAsDouble(argEvaluated);
return new Double(Math.sqrt(argAsDouble));
// or (to plug re-using object factories)
// return context.makeDoubleResult( Math.sqrt(argAsDouble));
} // follow with other types...
}// call to evaluate could also be specialized beforehand
(i.e. Sqrt could be a type of DoubleNumericFunction, having evaluateDouble and the context would only call evaluateDouble)
How does it taste ?
Paul
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
