@Def("(is Function) call(arg)")
@Doc("Invokes the given function.")
public static class Call implements Intrinsic {
public Obj invoke(Context context, Obj left, Obj right) {
FnObj function = left.asFn();
Obj fnArg = right;
// Make sure the argument matches the function's pattern.
Callable callable = function.getCallable();
if (!PatternTester.test(context, callable.getPattern(), fnArg,
callable.getClosure())) {
throw context.error(Name.NO_METHOD_ERROR, "The argument \"" +
context.getInterpreter().evaluateToString(fnArg) + "\" does not match the " +
"function's pattern " + callable.getPattern());
}
return function.invoke(context, fnArg);
}