Class Applicable2<R,A0,A1>

java.lang.Object
net.hydromatic.morel.eval.ApplicableImpl
net.hydromatic.morel.eval.Applicable2<R,A0,A1>
Type Parameters:
R - return type
A0 - type of argument 0
A1 - type of argument 1
All Implemented Interfaces:
Applicable, Describable
Direct Known Subclasses:
Codes.ListNth, Codes.ListTake, Codes.RealCompare, Codes.StringSub

public abstract class Applicable2<R,A0,A1> extends ApplicableImpl
Applicable whose argument is a 3-tuple.

Implementations that use Applicable3 are more efficient and concise than ApplicableImpl because there is no need to create an ephemeral tuple (Java List) to pass the arguments, and Java's generics provide the casting.

But the rewrite assumes that the function is strict (always evaluates all arguments, even if the function throws) and doesn't use EvalEnv, so it is not appropriate for all functions. For example, andalso evaluates its arguments lazily and therefore cannot be an Applicable2.

If a function has an Applicable2 implementation and the argument tuple is evaluated whole, the old evaluation path will be used. For example, the first call below uses apply and the second uses apply:


 - Math.pow (2.0, 3.0);
 val it = 8.0 : real
 - Sys.plan ();
 val it = "apply2(fnValue Math.pow, constant(2.0), constant(3.0))" : string
 - Math.pow (List.hd [(2.0, 3.0)]);
 val it = 8.0 : real
 - Sys.plan ();
 val it =
   "apply(fnValue Math.pow, argCode apply(fnValue List.hd, argCode tuple(tuple(constant(2.0), constant(3.0)))))"
   : string
 
 
See Also:
  • Constructor Details

    • Applicable2

      protected Applicable2(BuiltIn builtIn, Pos pos)
    • Applicable2

      protected Applicable2(BuiltIn builtIn)
  • Method Details