[system] / trunk / pg / macros / parserFunction.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/parserFunction.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5550 Revision 5551
1=head1 NAME
1 2
3parserFunction.pl - An easy way of adding new functions to the current context.
4
5=head1 DESCRIPTION
6
7This file implements an easy way of creating new functions that
8are added to the current Parser context. (This avoids having to
9do the complicated procedure outlined in the docs/parser/extensions
10samples.)
11
12To create a function that can be used in Formula() calls (and by
13students in their answers), use the parserFunction() routine, as
14in 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
25The first parameter to parserFunction is the name of the function
26or the name with its argument list. In the first case, the
27names of the variables are taken from the formula for the
28function, and are listed in alphabetical order.
29
30The second argument is the formula used to compute the value
31of the function. It can be either a string or a Parser Formula
32object.
33
34=cut
35
2loadMacros('MathObjects.pl'); 36loadMacros('MathObjects.pl');
3 37
4sub _parserFunction_init {parserFunction::Init()}; # don't reload this file 38sub _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 user-defined functions 40# The package that will manage user-defined functions
42# 41#
43package parserFunction; 42package parserFunction;
44our @ISA = qw(Parser::Function); 43our @ISA = qw(Parser::Function);

Legend:
Removed from v.5550  
changed lines
  Added in v.5551

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9