in reply to A set of new operators. In keeping with the design of Perl?

Perhaps the best example of this is $var ||= 100; which is shorthand for $var = 100 unless $var; or even if( not $var ) { $var = 100; }

Actually, it's a shorthand for $var = $var || 100;, just like how $var += 4; is a shorthand for $var = $var + 4;

?<:= ?>:= ?<=:= ?>=:= ?lt:= ?gt:= ?ge:= ?le:=

I don't like them. Too hard to remember and too ugly.

maybe in perl 6?

http://dev.perl.org/perl6/list-summaries/p6summary.2003-02-09.pod.html#shortcut%20=

Finally, is it possible to invent new operators using overload? Or would you have to resort to source filters to implement this outside of the core?

No; yes.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re: Re: A set of new operators. In keeping with the design of Perl?
by BrowserUk (Patriarch) on May 19, 2003 at 07:54 UTC

    Thanks for the link juerd, I hadn't seen that discussion. However, I think that my idea is quite different to that proposal which suggested a short-hand for the trinary operator involving 3 operands.

    eg. $var ??= $x : $y;

    The operators I am seeking only involve 2 operands.

    Too hard to remember ...

    This: $var = $var op $expr ? $var : $expr;

    becomes this: $var ?op:= $expr;

    Is that hard to remember?

    ...and too ugly.

    Agreed, they ain't beauiful. I was trying to retain the notions of the ternary and the operators and the assignment, but as they are no longer ternary, maybe the ? or the final = could be dropped:

    # Instead of these these or these? $lvalue ?<:= $rvalue; $lvalue <:= $rvalue; $lvalue ?<: $rvalue; + $lvalue ?>:= $rvalue; $lvalue <=:= $rvalue; $lvalue ?>: $rvalue; + $lvalue ?<=:= $rvalue; $lvalue >:= $rvalue; $lvalue ?<=: $rvalue; + $lvalue ?>=:= $rvalue; $lvalue >=:= $rvalue; $lvalue ?>=: $rvalue; + $lvalue ?lt:= $rvalue; $lvalue lt:= $rvalue; $lvalue ?lt: $rvalue; + $lvalue ?gt:= $rvalue; $lvalue le:= $rvalue; $lvalue ?gt: $rvalue; + $lvalue ?ge:= $rvalue; $lvalue gt:= $rvalue; $lvalue ?ge: $rvalue; + $lvalue ?le:= $rvalue; $lvalue ge:= $rvalue; $lvalue ?le: $rvalue;

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller