[system] / trunk / pg / lib / Value.pm Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/pg/lib/Value.pm

Revision 3715 Revision 3716
89 '-' => 'sub', 89 '-' => 'sub',
90 '*' => 'mult', 90 '*' => 'mult',
91 '/' => 'div', 91 '/' => 'div',
92 '**' => 'power', 92 '**' => 'power',
93 '.' => '_dot', # see _dot below 93 '.' => '_dot', # see _dot below
94 'x' => 'cross', 94 'x' => 'cross',
95 '<=>' => 'compare', 95 '<=>' => 'compare',
96 'cmp' => 'compare_string', 96 'cmp' => 'compare_string',
97}; 97};
98 98
451# \$f = Formula("1+x") and \$g = Formula("y") then Formula("\$f/\$g") will be 451# \$f = Formula("1+x") and \$g = Formula("y") then Formula("\$f/\$g") will be
452# (1+x)/y not 1+(x/y), as it would be without the implicit parentheses. 452# (1+x)/y not 1+(x/y), as it would be without the implicit parentheses.
453# 453#
454sub _dot { 454sub _dot {
455 my (\$l,\$r,\$flag) = @_; 455 my (\$l,\$r,\$flag) = @_;
456 return Value::_dot(\$r,\$l,!\$flag) if (\$l->promotePrecedence(\$r)); 456 return \$r->_dot(\$l,!\$flag) if (\$l->promotePrecedence(\$r));
457 return \$l->dot(\$r,\$flag) if (Value::isValue(\$r)); 457 return \$l->dot(\$r,\$flag) if (Value::isValue(\$r));
458 \$l = \$l->stringify; \$l = '('.\$l.')' unless \$\$Value::context->flag('StringifyAsTeX'); 458 if (\$\$Value::context->flag('StringifyAsTeX')) {\$l = \$l->TeX} else {\$l = \$l->pdot}
459 return (\$flag)? (\$r.\$l): (\$l.\$r); 459 return (\$flag)? (\$r.\$l): (\$l.\$r);
460} 460}
461# 461#
462# Some classes override this 462# Some classes override this
463# 463#
464sub dot { 464sub dot {
465 my (\$l,\$r,\$flag) = @_; 465 my (\$l,\$r,\$flag) = @_;
466 my \$tex = \$\$Value::context->flag('StringifyAsTeX'); 466 my \$tex = \$\$Value::context->flag('StringifyAsTeX');
467 \$l = \$l->stringify; \$l = '('.\$l.')' if \$tex; 467 if (\$tex) {\$l = \$l->TeX} else {\$l = \$l->pdot}
468 if (ref(\$r)) {\$r = \$r->stringify; \$r = '('.\$l.')' if \$tex} 468 if (ref(\$r)) {if (\$tex) {\$r = \$r->TeX} else {\$r = \$r->pdot}}
469 return (\$flag)? (\$r.\$l): (\$l.\$r); 469 return (\$flag)? (\$r.\$l): (\$l.\$r);
470} 470}
471
472#
473# Some classes override this to add parens
474#
475sub pdot {shift->stringify}
476
471 477
472# 478#
473# Compare the values of the objects 479# Compare the values of the objects
474# (list classes should replace this) 480# (list classes should replace this)
475# 481#
582sub Error { 588sub Error {
583 my \$message = shift; 589 my \$message = shift;
584 \$message = [\$message,@_] if scalar(@_) > 0; 590 \$message = [\$message,@_] if scalar(@_) > 0;
585 \$\$context->setError(\$message,''); 591 \$\$context->setError(\$message,'');
586 \$message = \$\$context->{error}{message}; 592 \$message = \$\$context->{error}{message};
587 die \$message . traceback() if \$\$context->{debug}; 593 die \$message . traceback() if \$\$context->flags('showTraceback');
588 die \$message . getCaller(); 594 die \$message . getCaller();
589} 595}
590 596
591# 597#
592# Try to locate the line and file where the error occurred 598# Try to locate the line and file where the error occurred

Legend:
 Removed from v.3715 changed lines Added in v.3716