esskar has asked for the wisdom of the Perl Monks concerning the following question:
hi,
i wrote a package Foo::Expression::Arithmetic, a package Foo::Number and a package Foo::Variable. I used overload to be able to do the following:
i wrote a package Foo::Expression::Arithmetic, a package Foo::Number and a package Foo::Variable. I used overload to be able to do the following:
$c1 and $c2 are now objects of type Foo::Expression::Arithmetic. Foo::Expression::Arithmetic has a output function, so outputing $c1 and $c2 gives me the following:my $x1 = Foo::Number->new()->value( 10 ); my $x2 = Foo::Number->new()->value( 20 ); my $x3 = Foo::Number->new()->value( 30 ); my $x4 = Foo::Number->new()->value( 40 ); my $v1 = Foo::Variable->new()->name( 'a' )->value( 50 ); my $c1 = $v1 - $x1 + $x2 + $x3 - $x4; my $c2 = $c1 * $v1;
a - 10 + 20 + 30 - 40 # $c1 a - 10 + 20 + 30 - 40 * a # $c2Now i want to be able to do the following:
not achieve the following output:my $c3 = ( $x1 + $x2 ) * $v1;
( 10 + 20 ) * a # $c3
is not working. :-( Any ideas?use overload '(' => \&left_parenthesis, ')' => \&right_parenthesis,
2006-02-07 Retitled by Arunbear, as per Monastery guidelines
Original title: 'overload'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using overload to parse arithmetic terms
by japhy (Canon) on Feb 07, 2006 at 12:52 UTC | |
by blokhead (Monsignor) on Feb 07, 2006 at 14:41 UTC | |
by japhy (Canon) on Feb 07, 2006 at 15:38 UTC | |
by esskar (Deacon) on Feb 07, 2006 at 16:07 UTC | |
Re: Using overload to parse arithmetic terms
by Tomte (Priest) on Feb 07, 2006 at 12:30 UTC | |
by esskar (Deacon) on Feb 07, 2006 at 12:43 UTC | |
by Tomte (Priest) on Feb 07, 2006 at 12:57 UTC |
Back to
Seekers of Perl Wisdom