

1  =head1 NAME 
1  
2  


3  parserFunction.pl  An easy way of adding new functions to the current context. 


4  


5  =head1 DESCRIPTION 


6  


7  This file implements an easy way of creating new functions that 


8  are added to the current Parser context. (This avoids having to 


9  do the complicated procedure outlined in the docs/parser/extensions 


10  samples.) 


11  


12  To create a function that can be used in Formula() calls (and by 


13  students in their answers), use the parserFunction() routine, as 


14  in the following examples: 


15  


16  parserFunction(f => "sqrt(x+1)2"); 


17  


18  $x = Formula('x'); 


19  parserFunction(f => sqrt($x+1)2); 


20  


21  parserFunction("f(x)" => "sqrt(x+1)2"); 


22  


23  parserFunction("f(x,y)" => "sqrt(x*y)"); 


24  


25  The first parameter to parserFunction is the name of the function 


26  or the name with its argument list. In the first case, the 


27  names of the variables are taken from the formula for the 


28  function, and are listed in alphabetical order. 


29  


30  The second argument is the formula used to compute the value 


31  of the function. It can be either a string or a Parser Formula 


32  object. 


33  


34  =cut 


35  
2  loadMacros('MathObjects.pl'); 
36  loadMacros('MathObjects.pl'); 
3  
37  
4  sub _parserFunction_init {parserFunction::Init()}; # don't reload this file 
38  sub _parserFunction_init {parserFunction::Init()}; # don't reload this file 
5  


6  =head1 DESCRIPTION 


7  


8  #################################################################### 


9  # 


10  # This file implements an easy way of creating new functions that 


11  # are added to the current Parser context. (This avoids having to 


12  # do the complicated procedure outlined in the docs/parser/extensions 


13  # samples.) 


14  # 


15  # To create a function that can be used in Formula() calls (and by 


16  # students in their answers), use the parserFunction() routine, as 


17  # in the following examples: 


18  # 


19  # parserFunction(f => "sqrt(x+1)2"); 


20  # 


21  # $x = Formula('x'); 


22  # parserFunction(f => sqrt($x+1)2); 


23  # 


24  # parserFunction("f(x)" => "sqrt(x+1)2"); 


25  # 


26  # parserFunction("f(x,y)" => "sqrt(x*y)"); 


27  # 


28  # The first parameter to parserFunction is the name of the function 


29  # or the name with its argument list. In the first case, the 


30  # names of the variables are taken from the formula for the 


31  # function, and are listed in alphabetical order. 


32  # 


33  # The second argument is the formula used to compute the value 


34  # of the function. It can be either a string or a Parser Formula 


35  # object. 


36  # 


37  


38  =cut 


39  


40  # 
39  # 
41  # The package that will manage userdefined functions 
40  # The package that will manage userdefined functions 
42  # 
41  # 
43  package parserFunction; 
42  package parserFunction; 
44  our @ISA = qw(Parser::Function); 
43  our @ISA = qw(Parser::Function); 