>>>>> "W" == Wizard <[EMAIL PROTECTED]> writes:
>> my Complex $c = 3+4i;
>> my $plain = 1.1;
>> $plain = $c;
W> This might be even more "Complex" than that - what if Complex can be
W> reduced? Should it? for instance:
W> my Complex $c = 3+4i;
W> my Complex $d = 4i;
W> my $plain = $c / $d;
W> Does $plain (which is actually '3' after reducing) get promoted to
W> Complex, or does the result from the division get demoted? ....
wouldn't the new value actually be 3/4i + 1? i think you would need
$c - 4i
to get just a real part out.
W> Perhaps there could be a sort of 'try' for conversion that returns the best
W> possible result? for instance:
W> my Complex $c = 3+4i;
W> my Complex $d = <unknown qty>;
W> my $plain = try_demote( $c / $d );
W> $plain now ISA Complex if it couldn't demote the result of the math, or it
W> ISA scalar (int or float) if it could. Now if you need to know, then just
W> check:
W> $plain = try_demote( $c / $d );
W> # the '(or)'s here are alternate forms, not comparison
W> if( $plain.type == "Complex" (or) $plain.Complex ){
W> print "It promoted!\n";
W> }
or as dan said in internal, if plain is not tagged with any type, it
just gets the complex value. that would be handled by the $plain.Complex
case as all untyped scalars can take any value. but i think a simpler
and faster test of no typing should be in there. another post in
internals had psuedo code with that test
Buddha Buck <[EMAIL PROTECTED]> wrote:
if (destPMC is specified as typeX) {
if (srcPMC ISA typeX) {
destPMC <- srcPMC
} else {
destPMC <- typeX.convert(srcPMC);
}
} else {
destPMC <- srcPMC
}
i take that first if to mean destPMC has any fixed type. else it just
takes on the type of the source.
W> elsif( $plain.type == "Scalar" (or) $plain.Scalar ) {
W> print "Result was reduced!\n";
W> }
plain scalars should handle any type. maybe that example should be int
or float? if you assign a complex value to an int/float it should reduce
to the real part of the value and assign that (with int/float conversion
as needed).
if you wanted the imaginary part only you would have to do:
$imag = $complex.imaginary
or would this be possible?
my $imag is imaginary ; # not complex!
$imag = $complex ;
that would cause the imaginary method/extraction to be called on
$complex and the scalar int/float would be assigned to $imag. $imag
could also have an int/float property which would further reduce the
value.
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org