http://qs321.pair.com?node_id=11107823


in reply to how to self define a operator

What you want to do would require modifying the language with new syntax. Hopefully needless to say, such endeavors are difficult, dangerous, and likely to be a waste of time, even if you are already a language specialist. To wit, the ~~ (smartmatch) binary operator was added to a public release almost 12 years ago, and it's still not stable.

You might be able to hack something together with source filters that sort of works in limited cases, but please don't. Odds of something like that breaking in simultaneously spectacular and sneaky fashion are unacceptably high for anything other than toy programs.

Would you mind sharing more details on what you are actually trying to accomplish (apart from inventing syntax)? A proper description of what you are actually working on would help us help you. There may well be an easy, elegant solution in pure Perl.

Replies are listed 'Best First'.
Re^2: how to self define a operator
by toothedsword (Sexton) on Oct 22, 2019 at 07:49 UTC

    Thank you very much for your reply!

    What I want to do is making the PDL more simple, as simple as matlab :D.

    for example, if we want to transfer the values from $t(1:4,0,0) to $d1(0,0:3), we can not write as below, because the dimensions are not same.

    $d1(0,0:3) .= $t(1:4,0,0);

    We have to write as this:

    $d1(0,0:3) .= $t(1:4,0,0)->reshape($d1(0,0:3)->dims);

    So I think if I can generate a "_=" which equal to .= $t(1:4,0,0)->reshape($d1(0,0:3)->dims or using a new method "rp" as $d1(0,0:3)->rp($t(1:4,0,0));