[system] / trunk / pg / lib / Value.pm Repository:
ViewVC logotype

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

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

Revision 2606 Revision 2609
53 'Vector' => 5, 53 'Vector' => 5,
54 'Matrix' => 6, 54 'Matrix' => 6,
55 'List' => 7, 55 'List' => 7,
56 'Interval' => 8, 56 'Interval' => 8,
57 'Union' => 9, 57 'Union' => 9,
58 'String' => 10,
58 'Formula' => 10, 59 'Formula' => 11,
59}; 60};
60 61
61# 62#
62# Binding of perl operator to class method 63# Binding of perl operator to class method
63# 64#
107# 108#
108sub makeValue { 109sub makeValue {
109 my $x = shift; 110 my $x = shift;
110 return $x if ref($x); 111 return $x if ref($x);
111 return Value::Real->make($x) if matchNumber($x); 112 return Value::Real->make($x) if matchNumber($x);
112 return $x unless matchInfinite($x); 113 if (matchInfinite($x)) {
113 my $I = Value::Infinity->new(); 114 my $I = Value::Infinity->new();
114 $I = $I->neg if $x =~ m/^$$Value::context->{pattern}{-infinity}$/; 115 $I = $I->neg if $x =~ m/^$$Value::context->{pattern}{-infinity}$/;
115 return $I; 116 return $I;
117 }
118 if ($Parser::installed) {return $x unless $$Value::context->{strings}{$x}}
119 return Value::String->make($x);
116} 120}
117 121
118# 122#
119# Get a printable version of the class of an object 123# Get a printable version of the class of an object
120# 124#
124 my $class = class($value); 128 my $class = class($value);
125 $class = 'Infinity' if $class eq 'Formula' && 129 $class = 'Infinity' if $class eq 'Formula' &&
126 $value->{tree} && $value->{tree}{isInfinite}; 130 $value->{tree} && $value->{tree}{isInfinite};
127 $class .= ' Number' if $class =~ m/^(Real|Complex)$/; 131 $class .= ' Number' if $class =~ m/^(Real|Complex)$/;
128 $class .= ' of Intervals' if $class eq 'Union'; 132 $class .= ' of Intervals' if $class eq 'Union';
133 $class = 'Word' if $class eq 'String';
129 return showType($value->{tree}) if $class eq 'Formula'; 134 return showType($value->{tree}) if $class eq 'Formula';
130 return 'an '.$class if $class =~ m/^[aeio]/i; 135 return 'an '.$class if $class =~ m/^[aeio]/i;
131 return 'a '.$class; 136 return 'a '.$class;
132} 137}
133 138
135# Get a printable version of the type of an object 140# Get a printable version of the type of an object
136# 141#
137sub showType { 142sub showType {
138 my $value = shift; 143 my $value = shift;
139 my $type = $value->type; 144 my $type = $value->type;
145 return 'a Word' if $type eq 'String';
140 return 'a Complex Number' if $value->isComplex; 146 return 'a Complex Number' if $value->isComplex;
141 return 'an '.$type if $type =~ m/^[aeio]/i; 147 return 'an '.$type if $type =~ m/^[aeio]/i;
142 return 'a '.$type; 148 return 'a '.$type;
143} 149}
144 150
463use Value::Vector; 469use Value::Vector;
464use Value::Matrix; 470use Value::Matrix;
465use Value::List; 471use Value::List;
466use Value::Interval; 472use Value::Interval;
467use Value::Union; 473use Value::Union;
474use Value::String;
468# use Value::Formula; 475# use Value::Formula;
469 476
470use Value::AnswerChecker; # for WeBWorK 477use Value::AnswerChecker; # for WeBWorK
471 478
472########################################################################### 479###########################################################################

Legend:
Removed from v.2606  
changed lines
  Added in v.2609

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9