[system] / trunk / pg / macros / Value.pl Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# View of /trunk/pg/macros/Value.pl

Thu Aug 11 14:19:26 2005 UTC (14 years, 6 months ago) by dpvc
File size: 1459 byte(s)
```Added new Set object class to the Parser.  It implements a finite set
of real numbers, for use with unions and intervals.  E.g., (1,2) U {3}
or (1,2) U {3,4,5}.  You can created Set objects in your perl code via
the Set() command, e.g, Set(3,4,5) or Set("{1,2,3}").  You should set
the Context to Context("Interval") if you plan to use Set objects, as
this defined the braces to form sets (rather than using them as
parentheses, which is the default WW behavior).  Note that in Interval
context, you can NOT use braces as parentheses.

Current, Set objects are only allowed to be sets of numbers.  It would
be possible to extend that in the future.
```

```    1 ###########################################################################
2 #
3 #  Declares functions needed for Value.pm
4 #
5
6 #
7 #  Constructors for the various types
8 #
9 sub String   {Value::String->new(@_)}
10 sub Real     {Value::Real->new(@_)}
11 sub Complex  {Value::Complex->new(@_)}
12 sub Point    {Value::Point->new(@_)}
13 sub Vector   {Value::Vector->new(@_)}
14 sub Matrix   {Value::Matrix->new(@_)}
15 sub List     {Value::List->new(@_)}
16 sub Interval {Value::Interval->new(@_)}
17 sub Set      {Value::Set->new(@_)}
18 sub Union    {Value::Union->new(@_)}
19
20 sub ColumnVector {Value::Vector->new(@_)->with(ColumnVector=>1,open=>undef,close=>undef)}
21
22 # sub Formula  {Value::Formula->new(@_)}
23 #
24 # #
25 # #  Parse a formula and evaluate it
26 # #
27 # sub Compute {
28 #   my \$formula = Formula(shift);
29 #   return \$formula->eval(@_);
30 # }
31
32 #
33 # Make a point or list a closed interval
34 #
35 sub Closed {
36   my \$x = shift;
37   if (Value::isValue(\$x)) {\$x->{open} = '['; \$x->{close} = ']'}
38   return \$x;
39 }
40
41 ###########################################################################
42 #
43 #  Make it possible to use  1+3*i  in perl rather than  1+3*\$i or 1+3*i()
44 #
45 #sub i ()  {Value::Complex->i};   #  defined in Parser.pl
46 #sub pi () {Value::Complex->pi};  #  defined in dangerousMacros.pl
47
48 ###########################################################################
49