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
Wish: 'hard assignment' operator #15464
Comments
From @epaCreated by @epaI don't know about you, but I find my code full of checks like this: foreach my $i (@items) { (Here 'exists' could be more appropriate than 'defined' if the score Or perhaps this: die if defined $x; Or perhaps they can be written in a more 'topical' way as foreach my $i (@items) { That might be a bit faster, only doing the hash lookup once, but it is The wish is to have a 'hard assignment' operator which will set foreach my $i (@items) { $x := $y; The addition of the // operator to the language simplified a lot of Perl Info
|
From @iabynOn Wed, Jul 20, 2016 at 06:46:29AM -0700, Ed Avis wrote:
For the cases where it is an error to assign to a non-undef lvalue, for (@flags) { So I would expect a hard-assignment operator which just prints a generic -- |
The RT System itself - Status changed from 'new' to 'open' |
From @epaDave Mitchell <davem <at> iabyn.com> writes:
It depends. If validating user-supplied data such as command line arguments, It's similar for checks done with the // operator. For user-supplied data my $separator = $opt{separator} // die 'the separator option is required'; But for internal data, where as the programmer you're pretty sure it will my $page = $h{page} // die; Of course, you can start off with the plain 'die;' style for quick hacking So while I would still keep some manual checks in my code for cases that -- |
From @kentfredricOn 21 July 2016 at 01:46, Ed Avis <perlbug-followup@perl.org> wrote:
This feature is too niche for a top level language syntax. I'd probably be looking more into a utility for `Hash::Util` that lock_defined( \%score ); Or at variable level, maybe you want a CPAN Module that adds magic to use Imaginary::WriteOnce; But generally the idea of "explode on write" seems very bad. I can understand "explode on missing", ie: $x := $y{path};
But you wanted the opposite to that, and that disturbs me. $x := $y{path}
Because I frequently find use for the former of those two examples, -- KENTNL - https://metacpan.org/author/KENTNL |
From @ap* Ed Avis <perlbug-followup@perl.org> [2016-07-20 15:48]:
You don’t need a new language feature. sub ensure_undef ($) : lvalue { defined $_[0] ? croak 'Unexpected defined value' : $_[0] } foreach my $i (@items) { Regards, |
@iabyn - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#128678 (status was 'rejected')
Searchable as RT128678$
The text was updated successfully, but these errors were encountered: