Re: [Mathlib-develop] Path Function & problems with funcion calls
Status: Beta
Brought to you by:
st_mueller
From: Stefan M. <st...@he...> - 2003-02-22 19:23:25
|
mark wrote: > On Thursday 20 Feb 2003 7:40 pm, Stefan Mueller wrote: > >>>While testing it I notived a problem with function calls >>> >>>entering >>> >>> >>>>path >>> >>>runs the path function and sets the ans variable but doesn't display >>>anything >>> >>>while entering >>> >>> >>>>path() >>> >>>displays the result of the function call. >> >>I'll have a look into it. >> >>Kind regards, >> Stefan. > > > > This seems to be connected to the function being treated as a variable rather > than a function when the brackets are ommitted. > > There is a similar problem if there is a space between the function name and > the brackets. If you enter > >>sin (5) > > > then you get a null pointer error. > > After checking it seems that MathLib treats VariableTokens and FunctionTokens > in the same way. It first checks for a variable with that name then for a > function. > > Therefore it might be an idea to combine VariableTokens and FunctionTokens > into one class (Say ReferenceToken) since this would ensure consistent > behaviour regardless of how the function or variable is entered. > > One difficulty is the fact that VariableToken descends from OperandToken while > FunctionToken descends from OperatorToken. RefereenceToken would have to be a > subclass of OperandToken which would mean that it would have to store any > parameters being passed to the variable or function. > > Though this would have the advantage of making functions more consistent with > keyword functions such as IF and WHILE. You're right, the mentioned approach looks very nice. There is also another advantage. To move functions into a descendent of OperandToken would clean up the handling of Expression-Tokens. In the future expression-tokens should only handle operands like +,*/^ this will simplify handling of priorities and evaluation of expressions. I'll start working on it right away. I propose to call the new token FunctionVariable-token since it cannot be determined during parsing if a token is a variable or a function. Kind regards, Stefan. |