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

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

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

Revision 5391 Revision 5392
1loadMacros("MathObjects.pl"); 1loadMacros("MathObjects.pl");
2 2
3sub _contextLimitedComplex_init {}; # don't load it again 3sub _contextLimitedComplex_init {LimitedComplex::Init()}; # don't load it again
4 4
5=head3 Context("LimitedComplex") 5=head3 Context("LimitedComplex")
6 6
7 ########################################################## 7 ##########################################################
8 # 8 #
44 # Context("LimitedComplex-strict"); 44 # Context("LimitedComplex-strict");
45 # 45 #
46 46
47=cut 47=cut
48 48
49##################################################
49# 50#
50# Handle common checking for BOPs 51# Handle common checking for BOPs
51# 52#
52package LimitedComplex::BOP; 53package LimitedComplex::BOP;
53 54
217} 218}
218 219
219############################################## 220##############################################
220############################################## 221##############################################
221 222
222package main; 223package LimitedComplex;
223 224
224# 225sub Init {
226
227 #
225# Now build the new context that calls the 228 # Build the new context that calls the
226# above classes rather than the usual ones 229 # above classes rather than the usual ones
227# 230 #
228 231
229$context{LimitedComplex} = Parser::Context->getCopy("Complex"); 232 my $context = $main::context{LimitedComplex} = Parser::Context->getCopy("Complex");
230$context{LimitedComplex}->operators->set( 233 $context->operators->set(
231 '+' => {class => 'LimitedComplex::BOP::add'}, 234 '+' => {class => 'LimitedComplex::BOP::add'},
232 '-' => {class => 'LimitedComplex::BOP::subtract'}, 235 '-' => {class => 'LimitedComplex::BOP::subtract'},
233 '*' => {class => 'LimitedComplex::BOP::multiply'}, 236 '*' => {class => 'LimitedComplex::BOP::multiply'},
234 '* ' => {class => 'LimitedComplex::BOP::multiply'}, 237 '* ' => {class => 'LimitedComplex::BOP::multiply'},
235 ' *' => {class => 'LimitedComplex::BOP::multiply'}, 238 ' *' => {class => 'LimitedComplex::BOP::multiply'},
236 ' ' => {class => 'LimitedComplex::BOP::multiply'}, 239 ' ' => {class => 'LimitedComplex::BOP::multiply'},
237 '/' => {class => 'LimitedComplex::BOP::divide'}, 240 '/' => {class => 'LimitedComplex::BOP::divide'},
238 ' /' => {class => 'LimitedComplex::BOP::divide'}, 241 ' /' => {class => 'LimitedComplex::BOP::divide'},
239 '/ ' => {class => 'LimitedComplex::BOP::divide'}, 242 '/ ' => {class => 'LimitedComplex::BOP::divide'},
240 '^' => {class => 'LimitedComplex::BOP::power'}, 243 '^' => {class => 'LimitedComplex::BOP::power'},
241 '**' => {class => 'LimitedComplex::BOP::power'}, 244 '**' => {class => 'LimitedComplex::BOP::power'},
242 'u+' => {class => 'LimitedComplex::UOP::plus'}, 245 'u+' => {class => 'LimitedComplex::UOP::plus'},
243 'u-' => {class => 'LimitedComplex::UOP::minus'}, 246 'u-' => {class => 'LimitedComplex::UOP::minus'},
244); 247 );
245# 248 #
246# Remove these operators and functions 249 # Remove these operators and functions
247# 250 #
248$context{LimitedComplex}->lists->set( 251 $context->lists->set(
249 AbsoluteValue => {class => 'LimitedComplex::List::AbsoluteValue'}, 252 AbsoluteValue => {class => 'LimitedComplex::List::AbsoluteValue'},
250); 253 );
251$context{LimitedComplex}->operators->undefine('_','U'); 254 $context->operators->undefine('_','U');
252$context{LimitedComplex}->functions->disable('Complex'); 255 $context->functions->disable('Complex');
253foreach my $fn ($context{LimitedComplex}->functions->names) 256 foreach my $fn ($context->functions->names) {$context->{functions}{$fn}{nocomplex} = 1}
254 {$context{LimitedComplex}->{functions}{$fn}{nocomplex} = 1} 257 #
255#
256# Format can be 'cartesian', 'polar', or 'either' 258 # Format can be 'cartesian', 'polar', or 'either'
257# 259 #
258$context{LimitedComplex}->flags->set(complex_format => 'either'); 260 $context->flags->set(complex_format => 'either');
259 261
262 #########################
263
260$context{'LimitedComplex-cartesian'} = $context{LimitedComplex}->copy; 264 $context = $main::context{'LimitedComplex-cartesian'} = $main::context{LimitedComplex}->copy;
261$context{'LimitedComplex-cartesian'}->flags->set(complex_format => 'cartesian'); 265 $context->flags->set(complex_format => 'cartesian');
262 266
267 #########################
268
263$context{'LimitedComplex-polar'} = $context{LimitedComplex}->copy; 269 $context = $main::context{'LimitedComplex-polar'} = $main::context{LimitedComplex}->copy;
264$context{'LimitedComplex-polar'}->flags->set(complex_format => 'polar'); 270 $context->flags->set(complex_format => 'polar');
265 271
272 #########################
273
266$context{'LimitedComplex-cartesian-strict'} = $context{'LimitedComplex-cartesian'}->copy; 274 $context = $main::context{'LimitedComplex-cartesian-strict'} = $main::context{'LimitedComplex-cartesian'}->copy;
267$context{'LimitedComplex-cartesian-strict'}->flags->set(strict_numeric => 1); 275 $context->flags->set(strict_numeric => 1);
268$context{'LimitedComplex-cartesian-strict'}->functions->disable('All'); 276 $context->functions->disable('All');
269 277
278 #########################
279
270$context{'LimitedComplex-polar-strict'} = $context{'LimitedComplex-polar'}->copy; 280 $context = $main::context{'LimitedComplex-polar-strict'} = $main::context{'LimitedComplex-polar'}->copy;
271$context{'LimitedComplex-polar-strict'}->flags->set(strict_numeric => 1); 281 $context->flags->set(strict_numeric => 1);
272$context{'LimitedComplex-polar-strict'}->functions->disable('All'); 282 $context->functions->disable('All');
273 283
284 #########################
285
274$context{'LimitedComplex-strict'} = $context{'LimitedComplex'}->copy; 286 $context = $main::context{'LimitedComplex-strict'} = $main::context{'LimitedComplex'}->copy;
275$context{'LimitedComplex-strict'}->flags->set(strict_numeric => 1); 287 $context->flags->set(strict_numeric => 1);
276$context{'LimitedComplex-strict'}->functions->disable('All'); 288 $context->functions->disable('All');
277 289
278Context("LimitedComplex"); 290 #########################
291
292 main::Context("LimitedComplex"); ### FIXME: probably should require the author to set this explicitly
293}
279 294
2801; 2951;

Legend:
Removed from v.5391  
changed lines
  Added in v.5392

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9