in reply to Re^3: Optimizing non-alphanumeric method calls
in thread Optimizing non-alphanumeric method calls

Here is a real code translation of "(1+7)/4":

use constant NUM23343688 => Sidef::Types::Number::Number->new('1'); use constant NUM25174720 => Sidef::Types::Number::Number->new('7'); use constant NUM24946728 => Sidef::Types::Number::Number->new('4'); ((main::NUM23343688)->${\'+'}(main::NUM25174720))->${\'/'}(main::NUM24 +946728);

Note that currently I'm using the reference-dereference technique for calling non-alphanumeric methods. What I'm really looking for, it's an way to avoid this inefficient approach without any other trade-offs.

Replies are listed 'Best First'.
Re^5: Optimizing non-alphanumeric method calls
by LanX (Saint) on Sep 27, 2015 at 19:56 UTC
    Interesting, I wasn't aware of this trick to fool the parser. (I suppose the special symbols are put directly into the stash of the class)

    Using _add instead of + as method name should make it easier.

    But replacing ${\'+'} with $_add holding the code ref is the fastest.

    Problems with chains do not exist.

    Btw: Are you aware that Perl supports operater overloading?

    (This won't be faster, rather slower but more readable)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!