| |
%{
// define string concatenation
static class StringAddition implements IBinaryEvaluator
{
private java.lang.reflect.Type fBaseType;
public StringAddition() throws ClassNotFoundException
{
fBaseType = Class.forName( "LambdaF.StringValue" );
}
public java.lang.reflect.Type getBaseType()
{
return fBaseType;
}
public Value compute( Value aLeft, Value aRight ) throws ArgumentException
{
if ( (aLeft instanceof StringValue) && (aRight instanceof StringValue) )
{
String lLeft = ((StringValue)aLeft).getValue();
String lRight = ((StringValue)aRight).getValue();
return new StringValue( lLeft.concat( lRight ) );
}
else
throw new ArgumentException( "argument type mismatch" );
}
public int getOperator()
{
return Operator.PLUS;
}
}
}%
let
in
// initialize module
%{
try
{
Value.ValueEvaluator.registerEvaluator( new StringAddition() );
}
catch (Exception e)
{
System.out.println( "Warning: String addition ignored!" );
}
return EmptyForm.EMPTY;
}% (||)
end
|