[33121] in Perl-Users-Digest
Perl-Users Digest, Issue: 4397 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 23 21:09:20 2015
Date: Mon, 23 Mar 2015 18:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 23 Mar 2015 Volume: 11 Number: 4397
Today's topics:
Re: An error on page 142 of The Camel Book. <kaz@kylheku.com>
Re: An error on page 142 of The Camel Book. <rweikusat@mobileactivedefense.com>
Re: An error on page 142 of The Camel Book. <bauhaus@futureapps.invalid>
Re: An error on page 142 of The Camel Book. <rweikusat@mobileactivedefense.com>
Re: An error on page 142 of The Camel Book. <bauhaus@futureapps.invalid>
Re: An error on page 142 of The Camel Book. <rweikusat@mobileactivedefense.com>
Re: An error on page 142 of The Camel Book. <kaz@kylheku.com>
Re: An error on page 142 of The Camel Book. <bauhaus@futureapps.invalid>
Re: An error on page 142 of The Camel Book. (Seymour J.)
Re: An error on page 142 of The Camel Book. (Seymour J.)
Re: An error on page 142 of The Camel Book. <kaz@kylheku.com>
Re: An error on page 142 of The Camel Book. <kaz@kylheku.com>
Re: An error on page 142 of The Camel Book. <news@todbe.com>
Re: An error on page 142 of The Camel Book. <news@todbe.com>
Re: An error on page 142 of The Camel Book. (Seymour J.)
Re: Error Messages <jurgenex@hotmail.com>
Re: Wait, lexical variables in loops do NOT always real <jblack@nospam.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 22 Mar 2015 23:09:49 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <20150322154836.867@kylheku.com>
On 2015-03-22, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
> I specifically mentioned this in the other posting:
>
> Even in the latter case, it's not uncommon for compilers to
> recognize tests which should occur after the loop body and
> generate appropriate machine code. Which amounts to a tacit
> admission of the logic error in the code --- the computer
> wouldn't need to correct it automatically had the human been
> willing to do it right to begin with ....
Okay, and so if I understand the above correctly, the automatic corrections in
this:
> jmp .L2
> .p2align 4,,10
> .p2align 3
> .L3:
> leal 1(%rbx), %ebp
> movl %ebx, %esi
> movl $.LC0, %edi
> xorl %eax, %eax
> movl %ebp, %ebx
> call printf
> .L2:
> movq 8(%r12), %rdi
> xorl %esi, %esi
> movl $10, %edx
> call strtol
> cmpl %eax, %ebx
> jl .L3
> ---------------
tell us that this should really have been written:
int i = 0;
goto L2;
do {
printf("%d\n", i++);
L2:
} while (i < atoi(argv[1]));
------------------------------
Date: Sun, 22 Mar 2015 23:41:35 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <87mw34txao.fsf@doppelsaurus.mobileactivedefense.com>
Kaz Kylheku <kaz@kylheku.com> writes:
> On 2015-03-22, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
>> I specifically mentioned this in the other posting:
>>
>> Even in the latter case, it's not uncommon for compilers to
>> recognize tests which should occur after the loop body and
>> generate appropriate machine code. Which amounts to a tacit
>> admission of the logic error in the code --- the computer
>> wouldn't need to correct it automatically had the human been
>> willing to do it right to begin with ....
>
> Okay, and so if I understand the above correctly, the automatic corrections in
> this:
>
>> jmp .L2
>> .p2align 4,,10
>> .p2align 3
>> .L3:
>> leal 1(%rbx), %ebp
>> movl %ebx, %esi
>> movl $.LC0, %edi
>> xorl %eax, %eax
>> movl %ebp, %ebx
>> call printf
>> .L2:
>> movq 8(%r12), %rdi
>> xorl %esi, %esi
>> movl $10, %edx
>> call strtol
>> cmpl %eax, %ebx
>> jl .L3
>> ---------------
>
> tell us that this should really have been written:
>
> int i = 0;
>
> goto L2;
> do {
> printf("%d\n", i++);
> L2:
> } while (i < atoi(argv[1]));
If I had been writing machine code, that's what I should have done.
But since I was using C, I just picked the construct which most closely
matched the intended algorithm and relied on the compiler to translate
that to someting sensible.
BTW, a possible counter-argument for all of this I think I should
mention: In the early 1970s, people started to consider 'algebraic
languages' the way to move forward. Because they were lacking experience
with them, they tended towards a 'kitchen sink' approach: Rather include
features than omit them. Fourty years of practice enable us to
distinguish between "features which proved to be useful" and "ideas
which didn't beget anything". For the given case, this means "no
pre-increment", "post-increment isn't an expression" and "nothing but
for-loops". The language designed around these tenets is called 'go'.
------------------------------
Date: Mon, 23 Mar 2015 12:14:16 +0100
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <meosgn$mk2$1@dont-email.me>
On 23.03.15 00:41, Rainer Weikusat wrote:
> BTW, a possible counter-argument for all of this I think I should
> mention:
Loops show so much of history which has found followers, I think,
who want to be served.
I'd like a loop (one of two) that, I think, would be sufficiently
different. It can be left at only one point such that:
- this point is syntactically identifiable
- there is only one piece of syntax for that
- the loop never needs dummy variables
Does this combination exist in any language?
(2 loop constructs, of which one is of this kind.)
I'm glad that Perl has efficient iterators so that I can mostly
drop "for(;;)".
------------------------------
Date: Mon, 23 Mar 2015 14:19:55 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <871tkf4wz8.fsf@doppelsaurus.mobileactivedefense.com>
"G.B." <bauhaus@futureapps.invalid> writes:
> On 23.03.15 00:41, Rainer Weikusat wrote:
>> BTW, a possible counter-argument for all of this I think I should
>> mention:
>
> Loops show so much of history which has found followers, I think,
> who want to be served.
> I'd like a loop (one of two) that, I think, would be sufficiently
> different. It can be left at only one point such that:
>
> - this point is syntactically identifiable
> - there is only one piece of syntax for that
> - the loop never needs dummy variables
>
> Does this combination exist in any language?
Enter the absurdities of terminology used past it's 'best before end'
date by people who are probably not even aware of what it originally
meant and why this was considered something to avoid: While you've
worded that somewhat differently, "it can be left at only one point" is
still easily recognizable as "it should have a single point of exit". As
it stands, all 'structured programming' control constructs usually
satisfy this condition: 'Point of exit' (or "point where it's left") is
the location where execution continues afterwards, eg, a loop like
while (the_sun_wont_shine()) {
.
.
.
}
<- always exists here, regardless of any code in the loop body (which
doesn't deliberately change the control flow in arbitrary ways, eg,
a goto or die)
Even this restriction is sometimes inconvenient and constructs like
multi-level breaks exist so that it can be circumvented then. Example of
a multi-exit subroutine and how it could be used:
------
sub is_it_even
{
goto its_odd if $_[0] & 1;
}
{
is_it_even($ARGV[0]);
print("even number 0\n");
last;
its_odd:
print("odd number 0\n");
}
{
is_it_even($ARGV[1]);
print("even number 1\n");
last;
its_odd:
print("odd number 1\n");
}
------
The people who invented 'loop control verbs' didn't violate their own
principles because they were too stupid to understand them and the
people who justify writing spaghetti code in the name of avoiding loop
control are just seeking to justify their inability or unwillingness to
think straigt ...
------------------------------
Date: Mon, 23 Mar 2015 17:10:35 +0100
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <mepds9$rp4$1@dont-email.me>
On 23.03.15 15:19, Rainer Weikusat wrote:
> hile you've
> worded that somewhat differently, "it can be left at only one point"
Actually, I worded something else entirely:
That there should be two kinds of loops, one of
the kind that you describe, and one of the kind
that I have described.
------------------------------
Date: Mon, 23 Mar 2015 16:21:09 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <87sicv3csq.fsf@doppelsaurus.mobileactivedefense.com>
"G.B." <bauhaus@futureapps.invalid> writes:
> On 23.03.15 15:19, Rainer Weikusat wrote:
>> hile you've
>> worded that somewhat differently, "it can be left at only one point"
>
> Actually, I worded something else entirely:
>
> That there should be two kinds of loops, one of
> the kind that you describe, and one of the kind
> that I have described.
I have to admit that I frequently can't make any sense of your texts
(regardless of language) because they appear to be some kind of
'reminders to self' referring to some thoughts of yours you didn't
communicate.
------------------------------
Date: Mon, 23 Mar 2015 16:37:32 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <20150323093445.492@kylheku.com>
On 2015-03-23, G.B. <bauhaus@futureapps.invalid> wrote:
> On 23.03.15 15:19, Rainer Weikusat wrote:
>> hile you've
>> worded that somewhat differently, "it can be left at only one point"
>
> Actually, I worded something else entirely:
>
> That there should be two kinds of loops, one of
> the kind that you describe, and one of the kind
> that I have described.
I cannot make sense of your posting several parents upthread.
It seems to be a poor quality machine translation from another language.
The intent seems to be to give requirements for a pair of looping constructs;
however, I cannot infer any of the actual requirements.
If you are unable to articulate requirements in English, consider adding
copious examples of the syntax you desire, its input conditions, and its
expected results (states of objects afterward, outputs, ...)
------------------------------
Date: Mon, 23 Mar 2015 20:12:11 +0100
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <mepogq$c1h$1@dont-email.me>
On 23.03.15 17:37, Kaz Kylheku wrote:
> The intent seems to be to give requirements for a pair of looping constructs;
> however, I cannot infer any of the actual requirements.
This isn't unexpected if there are no (mainstream?) languages
that have such loops; I would be repeating the existing
definitions from the established apparatus to which you have
been alluding.
But, frankly, I find it difficult to give examples of
something that I do not know to exist?
I'll try again, adding more context. This is about syntax,
and its meaning in terms of control flow, not states.
"I'd like a loop (one of two) that, I think, would be sufficiently
different. It can be left at only one point such that:
- this point is syntactically identifiable
- there is only one piece of syntax for that
- the loop never needs dummy variables"
0. This kind of loop should have one exit.
1. "syntactically identifiable" should mean, really as
usual, that the language defines a sequence of symbols
that means "exit this loop!" (when ...) and nothing else;
2. and that nothing else can mean "exit this loop!" (*)
More in a moment.
3. Rainer was on the right track precisely when mentioning
the "classically structured" Pascal style. But that did
require dummy variables given the restrictions imposed on
the loop test, IIRC, say
test := init;
while P(test) do begin ex3; test := ... end
In Perl, "goto", "return", or "exit" can be used to express
loop exit, in addition to "last". Of course, conditions
that are put in the places discussed, such as
while (...)
etc., can make a loop exit, too. Here, the context is that part
of syntax which, besides expressing "loop", hints at the
possibility of a loop exit. ("Here, at this point in the text.")
So, if one wants to syntactically identify loop exits in Perl,
then one needs to look for them in many places and also in two
ways. A reader will pay attention to "goto", "return", "last"
etc., so there is more than one piece of syntax for "exiting
a loop". Each has slightly different implications regarding
control flow. (No surprise, as it's TIMTOWTDI at work.)
Add to that the different syntactically framed exit conditions
already mentioned.
I might be tempted to adduce one of Perl's "looping constructs"
as a working model of what I have in mid, namely
map { ... } ( ... );
as, by intent, this should do {...} for all $_ in (...),
and then "exit". Somewhat like your "ideal loops" working
behind the scenes? But then, I _could_ "goto X" out of this
map's block, thus breaking map's implicit control structure.
But map is there, exemplifying one "normal" exit to the next
statement, after all $_ have been processed.
__
(*) exit normally; as, "to be honest", no loop can purport to
catch all "deaths".
------------------------------
Date: Mon, 23 Mar 2015 17:04:14 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <55107fce$1$fuzhry+tra$mr2ice@news.patriot.net>
In <87h9tcd9h7.fsf@doppelsaurus.mobileactivedefense.com>, on
03/22/2015
at 09:10 PM, Rainer Weikusat <rweikusat@mobileactivedefense.com>
said:
>As I wrote in the original postings, loops come in two kinds,
>'execute 0 or more times' and 'execute 1 or more times' and I
>advocate picking the one which makes the most sense in any given
>situation, regardless of what a compiler might or might not be
>capable of.
Over the past half century, I've encounter "0 or more" more often than
"1 or more". I often use both in the same program. PL/I is an example
of how to handle it well; it has multiple optional clause on a DO that
can be combined[1] to achieve the desired effect. The one thing
missing is iterating over array elements rather than over subscripts.
[1] You can get similar effects in Perl with, e.g., last
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Mon, 23 Mar 2015 09:46:10 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <55101922$3$fuzhry+tra$mr2ice@news.patriot.net>
In <20150321205211.627@kylheku.com>, on 03/22/2015
at 04:37 AM, Kaz Kylheku <kaz@kylheku.com> said:
>The fact that n is actually the constant 1024 which is greater than
>zero is not a sufficient justification for skipping the first test.
Why is it not a valid compiler optimization?
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Mon, 23 Mar 2015 21:37:03 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <20150323143144.618@kylheku.com>
On 2015-03-23, Shmuel Metz <spamtrap@library.lspace.org.invalid> wrote:
> In <87h9tcd9h7.fsf@doppelsaurus.mobileactivedefense.com>, on
> 03/22/2015
> at 09:10 PM, Rainer Weikusat <rweikusat@mobileactivedefense.com>
> said:
>
>>As I wrote in the original postings, loops come in two kinds,
>>'execute 0 or more times' and 'execute 1 or more times' and I
>>advocate picking the one which makes the most sense in any given
>>situation, regardless of what a compiler might or might not be
>>capable of.
>
> Over the past half century, I've encounter "0 or more" more often than
> "1 or more".
However, the difference is a big deal in scanning and parsing. E.g. in regex
we have * (zero or more) versus + (one or more).
So that could partially explain the fuss being made over this in a Perl
newsgroup.
I can just see it. You are a crazy moron if you use *. The natural
thing is always one or more:
R+
Furthermore, in the rare cases you need zero or more, you can do this:
do this:
(R+)?
So the whole Kleene Star zero-or-more stupidity is never necessary. :)
------------------------------
Date: Mon, 23 Mar 2015 21:41:27 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <20150323144015.269@kylheku.com>
On 2015-03-23, Shmuel Metz <spamtrap@library.lspace.org.invalid> wrote:
> In <20150321205211.627@kylheku.com>, on 03/22/2015
> at 04:37 AM, Kaz Kylheku <kaz@kylheku.com> said:
>
>>The fact that n is actually the constant 1024 which is greater than
>>zero is not a sufficient justification for skipping the first test.
>
> Why is it not a valid compiler optimization?
Far from that; and in fact that it's optimization which your compiler *does*
removes any shred of justification for writing crazy looking do/while bullshit
instead of for (i = 0; i < 1024; i++).
------------------------------
Date: Mon, 23 Mar 2015 15:40:09 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <meq4mv$kb$2@dont-email.me>
On 3/23/2015 04:14, G.B. wrote:
> On 23.03.15 00:41, Rainer Weikusat wrote:
>> BTW, a possible counter-argument for all of this I think I should
>> mention:
>
> Loops show so much of history which has found followers, I think,
> who want to be served.
> I'd like a loop (one of two) that, I think, would be sufficiently
> different. It can be left at only one point such that:
>
> - this point is syntactically identifiable
> - there is only one piece of syntax for that
> - the loop never needs dummy variables
>
> Does this combination exist in any language?
> (2 loop constructs, of which one is of this kind.)
>
> I'm glad that Perl has efficient iterators so that I can mostly
> drop "for(;;)".
If there were a finite number of for(;;)'s, that would leave more
for the rest of us that actually like them. ;)
------------------------------
Date: Mon, 23 Mar 2015 15:47:06 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <meq540$kb$3@dont-email.me>
On 3/23/2015 14:37, Kaz Kylheku wrote:
>
> I can just see it. You are a crazy moron if you use *. The natural
> thing is always one or more:
>
> R+
>
> Furthermore, in the rare cases you need zero or more, you can do this:
> do this:
>
> (R+)?
>
> So the whole Kleene Star zero-or-more stupidity is never necessary. :)
Nothing in the world is 'necessary' if there is an equivalent alternative. ;)
------------------------------
Date: Mon, 23 Mar 2015 18:45:04 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: An error on page 142 of The Camel Book.
Message-Id: <55109770$1$fuzhry+tra$mr2ice@news.patriot.net>
In <20150323144015.269@kylheku.com>, on 03/23/2015
at 09:41 PM, Kaz Kylheku <kaz@kylheku.com> said:
>Far from that; and in fact that it's optimization which your
>compiler *does* removes any shred of justification for writing
>crazy looking do/while bullshit instead of
>for (i = 0; i < 1024; i++).
Then it's a good thing that I never suggested writing crazy looking
code. My point is that the important issue is code maintainability and
readability, not efficiency. Saving femtoseconds doesn't matter if it
takes you enough time to debug[1] to wipe out the savings. BTW, I
could make a case that your for is crazy looking in Perl[2], given the
existence of foreach.
[1] You do debug, I hope.
[2] However reasonable it may be in C
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Sun, 22 Mar 2015 15:11:08 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Error Messages
Message-Id: <vafuga12m226q8thaaciej0l8j0uoibea2@4ax.com>
Henry Law <news@lawshouse.org> wrote:
>On 20/03/15 21:34, jurgenex@hotmail.com wrote:
>> I would assume that competent programmers know how to start a Perl
>> program
>
>Indeed so you would. So turn your logic round the other way: since
>_this_ programmer doesn't know how to start a Perl program that way ...
>what?
>
>Actually, I'm surprised you don't recognise the poster's name and recall
>the (long) history.
You are right. For whatever reason my filter for him was deactivated, I
really don't know what happened.
I am truly sorry, this is fixed now and he is back where he belongs.
jue
------------------------------
Date: Mon, 23 Mar 2015 14:22:28 -0500
From: John Black <jblack@nospam.com>
Subject: Re: Wait, lexical variables in loops do NOT always reallocate per-iteration.
Message-Id: <MPG.2f7a23ebddae562698981c@news.eternal-september.org>
In article <IuadnW2wZeg5tpDInZ2dnUVZ572dnZ2d@giganews.com>, see.my.sig@for.my.address says...
> > .... Finally, the following dangerous-looking code actually works fine:
> >
> > for $i (1..10) {
> > my @array = somefunc($i);
> > $AoA[$i] = \@array;
> > }
> >
> > That?s because the lexically scoped my @array variable is created
> > afresh on each pass through the loop...
>
> But on further experimentation, I see that it's NOT always true that
> lexical variables in loops re-allocate each iteration. They only do it
> if they have non-zero ref count.
>
> In the example above, a reference to @array is being stored in an
> array-of-array-refs on each iteration, so Perl retains a copy of
> @array each iteration.
>
> HOWEVER, if the ref count of a lexical variable declared in a loop is
> zero when loop bottom is reached, Perl re-uses the same memory address
> like C does. So the code which The Camel Book gives above not only
> LOOKS dangerous, it IS dangerous because it's misleading.
Why on earth name the array anyway? Even if it works, it adds confusion and probably costs
performance. Why not create anonymous arrays and store their references in @AoA?
John Black
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4397
***************************************