Re: Can overloaded '+' return an array? If so, how?



xhoster@xxxxxxxxx wrote:

Yep. And, in fact, I would usually expect an overloaded addition
operator to turn something of the same class as (at least one of) it's
operands, so I suggest that not only should it return a ref, but a ref
that is blessed into ClassAct.

That expectation is not fulfilled either in mathematics or in Perl
native types.

In Perl, an int divided by an int is not necessarily an int.

In mathematics, the dot product of two vectors is a scalar. The outer
product is a matrix.

Thus, if the inability of an overloaded '+' to always return a scalar
was a conscious decision, I believe it was the wrong one. What if you
want to add two arrays?

Be all this as it may, my thanks to those who responded. I guessed
this is the way it would turn out, because I couldn't see anything I
was doing wrong. I'll have to add it to my list of Perl sins (along
with the inability to handle IEEE exceptional values in a standard
way).

Cheers,
-P.

.



Relevant Pages

  • Re: Why is java considered a language for "web" or "internet" programming?
    ... I don't remember reading exact things about Perl interpreter, ... load and parse bytecodes. ... I think, integer in Perl or Python or other scripting languages is some structure, with at the least field for type and value, and pointer to this structure you hold in 'i' variable. ... const int NNUM = 1000000; ...
    (comp.lang.java.help)
  • Curious benchmark results with Inline::C
    ... I've recently been toying around with Inline::C, benchmarking ... certain variations of C and Perl and examining the results. ... However, one function calls distance() to compute the distance, ... inline double inline_distance(int x, int y) ...
    (comp.lang.perl.misc)
  • Writing a module, Segmentation fault
    ... For the access to IGT+, I am writing a Module in Perl. ... banking::igtplus - Perl extension for blah blah blah ... int igt_ack( ... dXSARGS; ...
    (comp.lang.perl.modules)
  • Re: Help a perl dev learn c, my first cli
    ... struct stat es; ... int main ... It's definitely faster than perl. ... int lscount (char dir_path, int typeflag) ...
    (comp.unix.programmer)
  • Re: reading a few bytes into a file
    ... This is my first adventure into perl, ... so I am at a loss for a lot of data on the format of the file. ... and return that as an int to me. ... I just read the docs on unpack, and I do not follow what the purpose ...
    (perl.beginners)