//
// MPFunctionTerm.h
// MathKit
//
// Created by Kim Wittenburg on 12.11.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPTerm.h"
/*!
@header
This file contains the MPFunctionTerm class.
*/
/*!
@define MPEvaluateExpression
@abstract Evaluates the receiver's child at the specified index and assigns
the evaluation result to a variable.
@discussion If errors occur during evaluation this macro returns
nil. Also there has to exist a NSError *__autoreleasing * pointer called error.
@param var
The name of the variable that will be declared in this macro. It
will be of the type NSDecimalNumber * and contain
the result of the evaluation.
@param index
The index of the child to be evaluated.
*/
#define MPEvaluateExpression(var, index) NSDecimalNumber *var = [[self expressionAtIndex:index] evaluate:error]; if (var == nil) return nil
@class MPFunctionTerm, MPFunction, MPParsedExpression;
/*!
@class MPFunctionTerm
@abstract A function term represents the term of a generic function.
@discussion This class is an abstract class that can not be evaluated. It is
the common superclass of all terms that represent @link
//apple_ref/occ/cl/MPFunction@/link instances.
*/
@interface MPFunctionTerm : MPTerm
/*!
@method initWithFunction:errors:
@abstract Initializes a MPFunctionTerm from the specified
@link //apple_ref/occ/cl/MPFunction@/link instance.
@discussion This method parses the children of the specified
function and stores the respective parsed
expressions. They are accessible using the @link
//apple_ref/occ/instm/MPFunctionTerm/expressionAtIndex:@/link
method.
Whether the children should contain a variable definition is
determined using the @link
//apple_ref/occ/instm/MPFunction/expectsVariableDefinitionInChildAtIndex:@/link
@param function
The function to initialize the receiver with. This method parses
the function's children. If any of them contain syntax errors
they are returned indirectly through the errors
parameter.
@param errors
If any of the function's children contain syntax
errors they are returned indirectly through this parameter. In
that case the method returns nil. If there are no
errors the parameter is not modified. This parameter is never set
to an empty array.
@return A new MPFunctionTerm instance.
*/
- (instancetype)initWithFunction:(MPFunction *)function
errors:(NSArray *__autoreleasing *)errors; /* designated initializer */
/*!
@method expressionAtIndex:
@abstract Returns a @link
//apple_ref/occ/cl/MPParsedExpression@/link instance that
represents the child at anIndex of the function that
is represented by the receiver.
@param anIndex
The index of the child.
@return A parsed expression that represents th
*/
- (MPParsedExpression *)expressionAtIndex:(NSUInteger)anIndex;
@end