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

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

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

Revision 4997 Revision 5071
25} 25}
26 26
27loadMacros("Value.pl"); 27loadMacros("Value.pl");
28loadMacros("PGcommonFunctions.pl"); 28loadMacros("PGcommonFunctions.pl");
29 29
30=head3 Formula("$formula") 30=head3 Formula("formula")
31 31
32# 32#
33# The main way to get a formula 33# The main way to get a MathObject Formula object (an equation
34# that depends on one or more variables).
34# 35#
35 36
36=cut 37=cut
37 38
38 39
39sub Formula {Value->Package("Formula")->new(@_)} 40sub Formula {Value->Package("Formula")->new(@_)}
40 41
41 42
42 43
43=head3 Compute($formula,$value) 44=head3 Compute("formula"[,var=>value,...])
44 45
45# 46#
46# Parse a formula and evaluate it 47# Compute the value of a formula and return a MathObject appropriate
48# to its value. Set the object so that the correct answer will be
49# shown exatly as in the given string rather than by its usual
50# stringification. If the value is a Formula and any var=>value
51# pairs are specified, then the formula will be evaluated using
52# the given variable values. E.g.,
53#
54# $x = Compute("x+3",x=>2)
55#
56# will produce the equivalent of $x = Real(5).
47# 57#
48 58
49=cut 59=cut
50 60
51sub Compute { 61sub Compute {
54 $formula = $formula->eval(@_) if scalar(@_) || $formula->isConstant; 64 $formula = $formula->eval(@_) if scalar(@_) || $formula->isConstant;
55 $formula->{correct_ans} = $string; 65 $formula->{correct_ans} = $string;
56 return $formula; 66 return $formula;
57} 67}
58 68
59=head3 Context() 69=head3 Context(), Context(name) or Context(context)
60 70
61# 71#
62# Deal with contexts 72# Set or get the current context. When a name is given, the context
73# with that name is selected as the current context. When a context
74# reference is provided, that context is set as the current one. In
75# all three cases, the current context (after setting) is returned.
63# 76#
64 77
65=cut 78=cut
66 79
67sub Context {Parser::Context->current(\%context,@_)} 80sub Context {Parser::Context->current(\%context,@_)}
68%context = (); # locally defined contexts, including 'current' context 81%context = (); # Locally defined contexts, including 'current' context
69Context(); # Initialize context (for persistent mod_perl) 82Context(); # Initialize context (for persistent mod_perl)
70 83
71########################################################################### 84###########################################################################
72# 85#
73# stubs for trigonometric functions 86# stubs for trigonometric functions

Legend:
Removed from v.4997  
changed lines
  Added in v.5071

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9