Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It seems to me that if it were pursued, you'd want a general conditional assignment operator. I chose ?= for notation because I don't think it conflicts with any existing syntax, and it has some intuitive appeal to me, because of the resemblance to, e.g., ||=. Follow it with a comparison operator and the value to compare. If the comparison is true, do the assignment:
# syntax lvalue ?= op value; # ex: $lowest = $_ if $lowest > $_; $lowest ?= > $_; # ex: $highest = substr($_, 10, 5) if $highest lt substr($_, 10, 5) $highest ?= lt substr($_, 10, 5); # ex: $foo ||= $bar, using the generalized ?= operator $foo ?= || $bar;
The last isn't quite equivalent to $foo ||= $bar, for cases where $foo and $bar are different values of false. ||= would do the assignment; ?= would not.

Unary tests could work, if Perl understands that unary operators operate on the lvalue, and I think in that case that ! should be combinable with other ops, since we already have $a ||= $b to denote $a = $b if !$a:

# ex: $foo = $default if !defined($foo) $foo ?= !defined $default; # ex: $foo{'bar'} = $default if exists($foo{'bar'}) # That is, we're resetting the value, but not creating it $foo{'bar'} ?= exists $default;
That's not going to win any converts from //= notation, and there's not much clamor for exists-based-defaulting, but it did seem a logical extension.

Update: extending a little further, we could make unary operators into mutators by making the value optional. If no value is given, the result of the (unary) operation is assigned back to the lvalue:

# $foo = uc($foo) $foo ?= uc; # even do arrays! @arr ?= reverse;
Operators that can be unary or binary present a syntactic problem. What is meant by
# $foo = 5 if -$foo? # $foo = $foo - 5 if $foo - 5? $foo ?= - 5;
? I think assuming binary operators in those cases make sense, while in the unambiguous case of no argument, you could negate a value with minimal typing:
$foo{$bar}{$baz} ?= -;

The PerlMonk tr/// Advocate

In reply to Re: Thoughts on some new operators for perl (6 or 7) by Roy Johnson
in thread Thoughts on some new operators for perl (6 or 7) by BigLug

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (9)
    As of 2018-05-22 16:23 GMT
    Find Nodes?
      Voting Booth?