README
1NAME
2 Math::SimpleVariable - simple representation of mathematical variables
3
4SYNOPSIS
5 use Math::SimpleVariable;
6
7 # Make a variable
8 my $foo = new Math::SimpleVariable(name => 'foo', value => 0.3);
9
10 # Some of the available accessors
11 # Note that many are identical, but you might want to change
12 # their behaviour in derived variable classes...
13 my $name = $foo->name(); # yields 'foo'
14 print $foo->stringify(), "\n"; # prints 'foo'
15 my $id = $foo->id(); # yields 'foo'
16 my $value = $foo->value(); # yields 0.3
17 print $foo->evaluate(), "\n"; # prints 0.3
18
19 # Make a second variable
20 my $bar = $foo->clone();
21 $bar->{name} = 'bar'; # changes the name (and as a consequence the id())
22 print $bar->value(), "\n"; # prints the same value, 0.3
23
24DESCRIPTION
25 Math::SimpleVariable is a simple representation of mathematical
26 variables, with an obligatory name and an optional value. This class on
27 itself might not seem very useful at first sight, but you might want to
28 derive different types of variables for some application. That way,
29 objects of the derived variable class can be accessed interchangeably
30 with the here provided protocols.
31
32 Math::SimpleVariable has two data fields - name and value - that can be
33 accessed and modified as if the variable object is a hash. E.g.
34
35 $var->{name} = 'foo';
36
37 sets the name of the object $var to 'foo', and
38
39 my $val = $var->{value};
40
41 reads the value of the $var object into $val.
42
43 In addition, the following accessor methods are available for
44 Math::SimpleVariable objects:
45
46 $var->name()
47 Returns $var->{name}
48
49 $var->id()
50 Returns $var->name() for Math::SimpleVariable objects. The purpose
51 of id() is to provide some unique identifier when using variables in
52 some higher level concept, e.g. a matrix representation of a set of
53 equations. Depending on your needs, you might want to change the
54 implementation of id() in derived classes.
55
56 stringify()
57 Returns a printable representation of the variable. For
58 Math::SimpleVariable objects, returns $var->name(). Again, you might
59 want to override this for derived classes.
60
61 value()
62 Returns $var->{value}
63
64 evaluate()
65 Returns a numerical evaluation of the variable. For
66 Math::SimpleVariable objects, returns $var->value(). You might want
67 to override this behaviour in derived classes, athough I cannot
68 think of any place where this might come in useful :-). evaluate()
69 is still there for reasons of orthogonality.
70
71SEE ALSO
72 perl(1).
73
74AUTHOR
75 Wim Verhaegen <wimv@cpan.org>
76
77COPYRIGHT
78 Copyright (C) 2001 Wim Verhaegen. All rights reserved. This program is
79 free software; you may redistribute and/or modify it under the same
80 terms as Perl itself.
81
82