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
no no-op #7470
Comments
From @jidanniGentlemen, perl has no no-op. Why should perl have a no-op? Well, let's say we have a complicated No need to name the new no-op operator after me, just add it to the |
From @rgsDan Jacobson (via RT) wrote:
The usual practice is to use a bare C<;> or C<1> (which is even |
The RT System itself - Status changed from 'new' to 'open' |
@rgs - Status changed from 'open' to 'resolved' |
From @jidanniRafael> The usual practice is to use a bare C<;> or C<1> (which is even No so fast. Let me try it. $ perl -we 'C<1> if 1' Why don't you explain what you are talking about in an addition to Trying again. Well, while typing around, I have discovered a simple no-op: 1. Anyways, my point stands: Perl has not documented how to do a no-op. |
From RandyS@ThePierianSpring.orgOn 8/19/2004 6:23 PM, Dan Jacobson wrote:
err, the C<> notation is POD style markup. It's also used as a $ perl -we '1 if 1' $ perl -we 'do{} if 1' |
From @tamiasOn Fri, Aug 20, 2004 at 06:23:48AM +0800, Dan Jacobson wrote:
C<> is POD markup, used to distinguish code from text. Look at the
Yes, that's Rafael was telling you in the first place. Ronald |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, usually, the solution to the problem is a module: te@linux:~> cat nop.pm use strict; sub nop () { 1; } te@linux:~> perl -Mnop -le 'nop for ("a" .. "z"); print nop;' (I choose nop because it reminds me of assembler, is one letter shorter and If there is sufficient interest, that could hit CPAN - but I doubt it. Sick In related news, there is also '...', which is often used as a placeholder, te@linux:~> perl -le '... for ("z".."z")' I am not sure if it is possible to have a subroutine named '...', though :) Best wishes, Tels - -- The best thing about growing older is that it takes such a long time. -----BEGIN PGP SIGNATURE----- iQEVAwUBQSXnAncLPEOTuEwVAQE24Qf+J1MNaDBCnSnSy+UDr/3gJhdMttD/x64D |
From @nwc10On Fri, Aug 20, 2004 at 01:56:42PM +0200, Tels wrote:
I made a patch to implement ... (well, at least part of its perl6 Nicholas Clark |
From @RandalSchwartz
Tels> sub nop () { 1; } This is not a nop. If it were truly a nop, then these two subroutines sub first { 5; } We need a no-op that doesn't affect "last expression evaluated". -- |
From @rgsRandal L. Schwartz wrote:
And what should do: sub f { nop; } |
From rick@bort.caOn Fri, Aug 20, 2004 at 08:24:57PM +0200, Rafael Garcia-Suarez wrote:
Obviously that prints an empty list. But sub f () { nop; } should be inlined-out so that it prints 5. ;-) -- |
From @jidanniAll this is above the beginning user's head. 1 returns 1, and 0 returns 0. However, this still may be too abstruse. |
From whatever@davidnicol.comOn Fri, 2004-08-20 at 07:21, Nicholas Clark wrote:
Is the current behavior of threedots deprecated? from perlop: In scalar context, ".." returns a boolean value. The -- |
From ajs@ajs.comDan Jacobson wrote:
It's a bit hard to make out. If you really feel that perlop needs such a Perl has no "no-op" facility per se, but it is conventional to use $_ = "aaaabbbb"; There is nothing particularly interesting about a constant 1 that I would not bother using C<1> here, but knock yourself out if you're a As for Randal's assertion that a true no-op would not affect "last Dan, your original question seemed to be of the form: How do I modify: next if large_amount_of_work(); so that it does nothing? Now, I know I might be being dense here, but can't you simply comment |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, On Saturday 21 August 2004 03:38, david nicol wrote:
Oh, you learn something new each day.... In related news, when will .. and ... overloadable? :) Cheers, Tels - -- "Yeah. Whatever." -----BEGIN PGP SIGNATURE----- iQEVAwUBQScKPXcLPEOTuEwVAQHCMQf/VaUHcW4Y0yIyK3THw3kwXyhYuvRzkSfc |
From rick@bort.caOn Sat, Aug 21, 2004 at 10:39:24AM +0200, Tels wrote:
When you submit a patch? ;-) IIRC, the last time I looked at this it -- |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, On Saturday 21 August 2004 15:13, Rick Delaney wrote:
I don't think I am qualified to do this - overload.pm scares me and I dare
my $a = Math::BigInt->new(2) ** 255; for ($a .. $b) or even: perl -Mbignum -le "for (78901234567890 .. 78901234567899) { print $_; }" :-) Cheers, Tels - -- "My other computer is your Windows box." -- Dr. Brad (19034) on 2004-08-13 -----BEGIN PGP SIGNATURE----- iQEVAwUBQSdc5ncLPEOTuEwVAQGX8Qf9FW/9RV88A8wJO6OF5Tfya3W0eaOdz1Ym |
From rick@bort.caOn Sat, Aug 21, 2004 at 04:31:58PM +0200, Tels wrote:
Ok, but really. ;-) Anyway, aren't those taken care of by overloaded C<++>? If not, I think perl -Mbignum -le "for (1 .. 78901234567899) { print $_; }" Overloaded C<..> wouldn't help there. Or here: perl -Mbignum -le "@x = (1 .. 78901234567899); for (@x) { print $_; }" -- |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, On Saturday 21 August 2004 19:34, Rick Delaney wrote:
No, really thats the reason! Longstanding bug in "bignum"!
No, ".." bypasses the ":constant" stuff like this: te@linux:~> (Expected is 1 Math::BigInt, 2 Math::BigInt etc) Also, watch this: te@linux:~> perl -Mbignum -le 'my $a = 1234567890; for ($a .. $a+5) \ ".." so far rather defeats the bignum package. And as long as _any_ code package Foo; Thats not good, since the caller of foo() or bar() shouldn't need to care Cheers, Tels - -- "Yeah, baby, yeah!" -----BEGIN PGP SIGNATURE----- iQEVAwUBQSeJr3cLPEOTuEwVAQFxIgf/U/UthcjdIOl87/MJQdjLES76R0PeUbv7 |
From whatever@davidnicol.comOn Sat, 2004-08-21 at 02:59, Aaron Sherman wrote:
"perlstyle" might be ripe for some addenda -- |
From rick@bort.caOn Sat, Aug 21, 2004 at 07:43:03PM +0200, Tels wrote:
Yes, this could be a bug. The following patch makes that print Math::BigInt But this patch has nothing to do with C<..> as it doesn't touch perl -Mbignum -le 'print ref(1); @a = (1..5); for (@a) { print "$_ " . ref($_); }' The reason the patch helps is because foreach loops optimize for (1..5) { } into (sort of) for (my $i = 1; $i <= 5; $i++) { } so suitable overloaded '++' and '<=' (actually implemented using
This now prints 1234567890123456789 Math::BigInt Good for Math::BigInt, but what about stringier objects? Some class may for ("a" .. "z") { } to be optimized to for (my $s = "a"; $s le "z"; $s++) { } Note that this class provides overloaded 'le', not '<=' and so the patch
I agree with this from a philosophical view, but I'm not so sure from a @a = (1 .. shift); die with 'Range iterator outside integer range' than suck up all my swap -- Inline Patch--- perl-current/pp_ctl.c Sat Aug 14 18:54:20 2004
+++ perl-dev/pp_ctl.c Sat Aug 21 22:41:15 2004
@@ -1808,7 +1808,10 @@
if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
dPOPss;
SV *right = (SV*)cx->blk_loop.iterary;
- if (RANGE_IS_NUMERIC(sv,right)) {
+ if (SvAMAGIC(sv)) {
+ cx->blk_loop.iterlval = newSVsv(sv);
+ }
+ else if (RANGE_IS_NUMERIC(sv,right)) {
if ((SvOK(sv) && SvNV(sv) < IV_MIN) ||
(SvOK(right) && SvNV(right) >= IV_MAX))
DIE(aTHX_ "Range iterator outside integer range");
--- perl-current/pp_hot.c Sat Jul 31 12:44:58 2004
+++ perl-dev/pp_hot.c Sat Aug 21 22:34:33 2004
@@ -1855,7 +1855,17 @@
register SV* cur = cx->blk_loop.iterlval;
STRLEN maxlen = 0;
char *max = SvOK((SV*)av) ? SvPV((SV*)av, maxlen) : "";
- if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
+ if (SvAMAGIC(cur)) {
+ oldsv = *itersvp;
+ *itersvp = newSVsv(cur);
+ SvREFCNT_dec(oldsv);
+ if (SvTRUE(amagic_call(cur, (SV*)av, gt_amg,0)))
+ RETPUSHNO;
+ else
+ AMG_CALLun(cur, inc);
+ RETPUSHYES;
+ }
+ else if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) {
/* safe to reuse old SV */
sv_setsv(*itersvp, cur); |
From @jidanniAaron> (is perlop the right place for it?), Well, where better to look for something about no-op operator than on Aaron> then I would say something like: [Nice example deleted.] Aaron> There is nothing particularly interesting about a constant 1 Also mention that they can also use 0, if they prefer a false return Aaron> I would not bother using C<1> here Also if just reading perlop the user wouldn't know what was being Aaron> Dan, your original question seemed to be of the form: No. I am just miffed that mighty Perl does not have even one official word Aaron> Now, I know I might be being dense here, but can't you simply comment Here in Nurd Labs we work with Makefiles, so often no comments allowed P.S.: to those who are polluting my no-op bug with ".." "..." bugs: |
From whatever@davidnicol.comOn Sat, 2004-08-21 at 16:20, Dan Jacobson wrote:
I think perlsyn would benefit from having a noop mentioned [david@plaza david]$ perl -wle 'goto fuzz; print 1; fuzz: print 2' you have to put a semicolon or something there. Here's a patch. Inline Patch--- perlpod/perlsyn.pod Mon Aug 18 15:12:12 2003
+++ perlhacking/perlsyn.pod Sun Aug 22 00:53:21 2004
@@ -513,11 +513,14 @@
=head2 Goto
Although not for the faint of heart, Perl does support a C<goto>
statement. There are three forms: C<goto>-LABEL, C<goto>-EXPR, and
C<goto>-&NAME. A loop's LABEL is not actually a valid target for
-a C<goto>; it's just the name of the loop.
+a C<goto>; it's just the name of the loop. When you must create a
+goto target immediately before a labeled loop, or if you want to
+have more than one label referring to the same place, the labels
+can be separated with semicolons, which function as Perl's no-op.
The C<goto>-LABEL form finds the statement labeled with LABEL and
-- |
From @ysthOn Sat, Aug 21, 2004 at 03:59:41AM -0400, Aaron Sherman <ajs@ajs.com> wrote:
Yes, there is; 0 and 1 are exempt from the "Useless use of a constant |
From @ysthOn Fri, Aug 20, 2004 at 08:38:35PM -0500, david nicol <whatever@davidnicol.com> wrote:
In general, perl's tokenizer has separate "expecting an operator" and |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, On Sunday 22 August 2004 05:21, Rick Delaney wrote:
You are my hero :-)
Ah cool. Didn't know this.
Hm, Math::String would be such an object. See below. Let's do the for("a" .. "z") class aside and look at objects for the range. However, not only does the object need to accept strings as input, it also Math::String is such an object, although it works a bit different under the So: use Math::String; I think after your patch that should print Math::String a which is way cool :)
OTOH, @a = ('a' .. 'z') uses automagically ++ as operation (the 1..5) case te@linux:~> perl -wle 'my $c = "a9a"; $c .= ""; $c++; print $c' huh? In addition: te@linux:~> perl -wle 'for ("a" .. "b") { print $_ }' As I said, the rules for /[^a-z]/ strings are non-obvious to me. (I once For the "simple" case of a charset of "a".."z" Math::String should behave
I think it would die anyway, because arrays can currently not have more than te@linux:~> cat array.pl my_sqrt(5); sub my_sqrt for (@a) { print sqrt($_),"\n"; } for ($i = 1; $i < $_[0]; $i++) { print sqrt($i),"\n"; } Of course, I have no idea if this is really important. Grepping core modules There are very little users of bignum and as long as they don't post to a In any event, I mixed up the old bugs: I thought to remember a problem with Benchmark.pm similiar to this one: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-08/msg01059.html (btw, the speed difference is now *cough*only*cough* a factor of 400 for I remember that simple putting "use bignum;" atop broke Benchmark, because However, it was/is ref() that creates the problem: te@linux:~> cat bench.pl use Benchmark qw/cmpthese/; my $a = $b = 0; cmpthese ( -2, te@linux:~> perl bench.pl # line 880-882 of Benchmark: Back then I wanted to fix Benchmark (testing for ref() eq 'HASH' (or ARRAY OTOH, nobody has probably tried to feed bignums to each core module's Best wishes, Tels PS: Funny, the fix for the bug introcuded in - -- "Call me Justin, Justin Case." -----BEGIN PGP SIGNATURE----- iQEVAwUBQShq2HcLPEOTuEwVAQFSFQf+JbWg+aP/9vcxNIOQPDOuvY+vGO+k80Yk |
From @ysthOn Sun, Aug 22, 2004 at 11:43:52AM +0200, Tels <perl_dummy@bloodgate.com> wrote:
Magical string increment only applies to /^[a-zA-Z]*[0-9]*\z/ strings. |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- Moin, On Sunday 22 August 2004 12:10, Yitzchak Scott-Thoennes wrote:
Aaah! I wrongly remembered it the other way round..
Me neither :) Interesting is also if one of them is not the expected format: te@linux:~> perl -wle 'for ("a9" .. "az") { print $_ }' This goes to "z9" on my system. Presumable because "aa0" gt "az"? te@linux:~> perl -wle 'print "z9" lt "z9" ? "yes" : "no"' Okay. te@linux:~> perl -wle 'print "z8" gt "z9" ? "yes" : "no"' Okay. te@linux:~> perl -wle 'print "aa0" gt "z9" ? "yes" : "no"' perl -wle '$a = "z9"; $b = $a; $b++; print $b gt $a ? "yes" : "no"' As I said, automagical ++ is simple insane... Cheers, Tels - -- This email violates U.S. patent #6,756,999 <http://tinyurl.com/2vuqm>: [ [ Konsoles* ] [ Mozilla ] [ KMail ]] -----BEGIN PGP SIGNATURE----- iQEVAwUBQSh0zXcLPEOTuEwVAQHIuwf+Mzjn5suZiCoLwU8fM+CqH0JmT2N4bicP |
From @ysthOn Sun, Aug 22, 2004 at 12:26:14PM +0200, Tels <perl_dummy@bloodgate.com> wrote:
Not exactly. If it never reaches the range-end, it stops when it exceeds |
From rick@bort.caOn Sun, Aug 22, 2004 at 04:41:29PM +0200, Tels wrote:
Hmm, it applies for me. Are you sync'ed?
If you look at line 150 you'll see eval q[package Oscalar; use overload ('++' => sub { $ {$_[0]} += 2; $_[0] } ) ]; Also, I don't see that Oscalar has overloaded '>', but that's ok because -- |
From @jidannidavid> I think perlsyn would benefit from having a noop mentioned OK, but perlOP too, because that's the first place one would look for Also, fellas, please move all other new non-noop threads off this bug |
From whatever@davidnicol.comDan: How exactly did you get into the position of looking for a noop? I was a little surprised to find that the technique of separating labels There isn't an explicit no-op operator in perl. Why do you think one is needed? Nobody else seems On Mon, 2004-08-23 at 12:18, Dan Jacobson wrote:
|
From whatever@davidnicol.comOkay here is what Rafael said, in the form of a patch to perlop. Had We can list other things in this new section as they appear to be Maybe the section should be somewhere other than tacked at the end. But Inline Patch--- perl-current/pod/perlop.pod Wed Jun 30 07:36:41 2004
+++ perl-current-docpatch/pod/perlop.pod Thu Aug 26 02:00:31 2004
@@ -2197,5 +2197,10 @@
Math::GMP another one using an external C library
Choose wisely.
+=head2 Pseudo-operators
+
+C<1> and C<0>, the cheap no-ops, are special cased in the parser
+to avoid generating warnings on things like C<1 while foo()>.
+
=cut |
From @jidanni[I get the messages thru perlbug-followup apparently, so no need to CC me.] david> How exactly did you get into the position of looking for a noop? Often I use perl -e in Makefiles, emacs file local variables, and other I want to replace It turns out 0 and 1 is what I want. So the big and only problem is they weren't documented. Therefore document no-op or noop (0,1), please. david> There isn't an explicit no-op operator in perl. well C doesn't fit in Makefiles Anyway, perl already has no-op's, 0 and 1, just doesn't document them. |
From @ysthOn Fri, Aug 27, 2004 at 05:52:03AM +0800, Dan Jacobson <jidanni@jidanni.org> wrote:
You can use comments by breaking up your code into multiple -e switches For instance, to comment out the first statement in: say: (though the ' -e' break can come at arbitrary points, not just |
From whatever@davidnicol.comAfter some meditation I think it makes sense right after "Constant Folding." Inline Patch--- perl-current/pod/perlop.pod Wed Jun 30 07:36:41 2004
+++ perl-current-docpatch/pod/perlop.pod Fri Aug 27 21:07:42 2004
@@ -2057,10 +2057,15 @@
}
the compiler will precompute the number which that expression
represents so that the interpreter won't have to.
+=head2 Pseudo-operators
+
+C<1> and C<0>, the cheap no-ops, are special cased in the parser
+to avoid generating warnings on things like C<1 while foo()>.
+
=head2 Bitwise String Operators
Bitstrings of any size may be manipulated by the bitwise operators
(C<~ | & ^>).
|
From @jidannidavid> +C<1> and C<0>, the cheap no-ops, are special cased in the parser |
From @tamiasOn Fri, Aug 27, 2004 at 09:13:42PM -0500, david nicol wrote:
Nit: special-cased Ronald |
From @iabynOn Fri, Aug 27, 2004 at 09:13:42PM -0500, david nicol wrote:
I've accepted be basic idea of the patch, but changed the wording. Dave. -- Change 23250 by davem@davem-percy on 2004/09/01 20:46:13 From: david nicol <whatever@davidnicol.com> Affected files ... ... //depot/perl/pod/perlop.pod#121 edit Differences ... ==== //depot/perl/pod/perlop.pod#121 (text) ==== @@ -2059,6 +2059,14 @@ +=head2 No-ops Bitstrings of any size may be manipulated by the bitwise operators |
Migrated from rt.perl.org#31228 (status was 'resolved')
Searchable as RT31228$
The text was updated successfully, but these errors were encountered: