in reply to Re: Logical/defined or as lvalue
in thread Logical/defined or as lvalue

We have ($w? $x : $y)= $z so why not?

Replies are listed 'Best First'.
Re^3: Logical/defined or as lvalue
by LanX (Saint) on Sep 03, 2024 at 21:31 UTC
    Well yes, according to Wikipedia is PHP implementing the "Elvis operator"
    • $x ?: $y
    as
    • $x ? $x : $y

    But I think Perl has bigger fish to frie.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      My point was that if the ternary conditional is an lvalue, then I don't see why not to make the '||' and '//' operators lvalues. It would result in better consistency.
      ... implementing the "Elvis operator" ... as $x ? $x : $y

      Actually, I read the opposite from the Wiki article:

      ... the Elvis operator expression A ?: B is approximately equivalent to the ternary conditional expression A ? A : B

      ... something like ... x = f() ?: g() ... is equivalent to ... the conditional ternary operator x = f() ? f() : g() except that it does not evaluate f() twice if it yields truthy.

      Accentuations by me.

      Greetings,
      🐻

      $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

        That makes PHP's Elvis operator a value-preserving logical-OR operator, like Perl's ||.

        According to the article, || also has this function in Common Lisp, Clojure, Lua, Object Pascal, Python, Ruby, and JavaScript. It's rather disingenuous to call the article "Elvis operator".

        In C, || is normalizes the value to 0 or 1.

Re^3: Logical/defined or as lvalue
by ikegami (Patriarch) on Sep 04, 2024 at 16:51 UTC

    Many reasons why not. I already gave the two primary ones: lack of readability (due to its rare and unexpected use) and lack of usefulness.

    If anything, I read your post as an argument against ( W ? X : Y ) = Z. But that has at least some modicum of usefulness.