New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
operators '|||' and '&&&' #15220
Comments
From Ulrich.Windl@rz.uni-regensburg.deHi! While writing a program for perl-5.10, I wondered whether the is an AND-equivalent for '//' for a closure like Where '???' is the operator that doesn't exist. Regards, |
From @TuxOn Thu, 10 Mar 2016 04:10:02 -0800, "Ulrich Windl" (via RT)
When the defined-or was introduced, there was: the "err" keyword, which Later it has been removed.
Currently there is none. One of the reasons for removal was the fact
Personally, I'd love to see the return of "err" (or whatever name would
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @leonerdOn Thu, 10 Mar 2016 04:10:02 -0800
There's no need for a "defined-and" operator in Perl, because there is -- leonerd@leonerd.org.uk |
From @kentfredricOn 11 March 2016 at 01:50, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> wrote:
I'm going to have to know what interpretation of code is expected from Both my interpretations don't hold the same behaviour as &&
-- KENTNL - https://metacpan.org/author/KENTNL |
From @kentfredric |
From Ulrich.Windl@rz.uni-regensburg.de
"a // b" is the shortcut for "defined(a) or b" ("defined(a) ? a : b"), and "a &&& b" would be a shortcut for "defined(a) and b". Did I miss the obvious?
|
From zefram@fysh.orgUlrich Windl wrote:
$ perl -lwe 'print +(3 // 4)' defined(a) evaluates to 1 if a is defined, not to a.
This is a more accurate explanation of //.
I presume it would be defined(a) ? b : a. It's not brilliantly useful. -zefram |
From Ulrich.Windl@rz.uni-regensburg.de
You are right! I wasn't fully awake, sorry!
It would be useful in the original context. I tired to make this a one-liner: die unless (defined($hi));
OK. Ulrich |
From zefram@fysh.orgUlrich Windl wrote:
my $index_by_name = sub { $header_i{(shift)} // die }; This is a defined-or situation, not defined-and. -zefram |
From Ulrich.Windl@rz.uni-regensburg.de
Thanks, I forgot "If no "return" is found and if the last statement is an expression, its value is returned." (wisdom from "man perlsub")
|
From @AbigailOn Thu, Mar 10, 2016 at 04:25:17PM +0100, Ulrich Windl wrote:
You don't even need that; it works with an explicit return as well: sub {return $header_i {+shift} // die} Abigail |
From @AbigailOn Thu, Mar 10, 2016 at 04:10:02AM -0800, Ulrich Windl wrote:
Perl has wasted years [1] of bike-shedding over the spelling of the defined-or [1] '|||' was floating around on IRC at least as early as 1997. '//' came Abigail |
From @bulk88On Thu Mar 10 04:10:00 2016, Ulrich.Windl@rz.uni-regensburg.de wrote:
??? looks like unicode replacement characters in an IDE. Very bad choice for an operator. Atleast with C's ? there will very soon be a ":" to the right of it to verify it isn't replacement character. "???" can be bad UTF conversion of source code. -- |
From @ap* Ulrich Windl <perlbug-followup@perl.org> [2016-03-10 13:15]:
First, an aside: under strict vars, this would never work, no matter how As for what you asked about, you can achieve this already, by using the return $_ for $header_i{(shift)} // (); (Depending on circumstances you might also use a grep or map instead. Or I’ve used this idiom a fair amount.
Who knows. The symmetry argument almost certainly didn’t come up though, Judging by the fact that //() has become an idiom for me, a defined-and
At least &&& is already sometimes valid syntax in contexts where this * H.Merijn Brand <h.m.brand@xs4all.nl> [2016-03-10 13:20]:
That was a low-precedence version of defined-or, so it’s irrelevant to * Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> [2016-03-10 13:55]:
Incorrect. No undefined value is true, but that doesn’t mean every * Zefram <zefram@fysh.org> [2016-03-10 15:50]:
It’s useful enough that shell has *only* defined-and, and no defined-or. * bulk88 via RT <perlbug-followup@perl.org> [2016-03-14 19:15]:
This seems like it must be humour, in which case it is so bone dry that Anyway, this ticket should probably be closed. Regards, |
@cpansprout - Status changed from 'open' to 'rejected' |
From @xsawyerxOn 06/20/2016 07:31 AM, Aristotle Pagaltzis wrote:
I fail to see how this comment adds *anything* to the conversation.
This seems right to me. Does anyone object to closing this? |
From Ulrich.Windl@rz.uni-regensburg.de
No ;-) |
Migrated from rt.perl.org#127684 (status was 'rejected')
Searchable as RT127684$
The text was updated successfully, but these errors were encountered: