On Fri, Apr 12, 2002 at 12:00:54PM +0100, Jonathan E. Paton wrote:
> > > Haven't you heard? In perl 6, "for" will replace "foreach" and the
> > > C-style "for" will be called "loop." Larry says that the C-style
> > > "for" loop is used far less often than the "foreach" style. Sounds
> > > like it's being deprecated...
> >
> > I've heard about this mythical perl6 thingy. Wasn't that the project
> > Larry was going to write apocalypses about first, one for every chapter
> > of the Camel? With 4 apocalypses in 1.5 years, 20 something chapters in
> > the Camel, I'm not to focussed on perl6.
>
> Give the man time! Perl 5 has been around for seven year (or more), so
> what's wrong with it taking, err, seven years to write all the apocalypses?
Nothing. It just means that I don't have to bother with perl6 for
another 7 years. And it also means I'm not going to lose focus
on the thing that matters, perl5, for another 7 years.
> Seriously, I can find 12 chapters worth anything in terms of difficultly,
> lots of fringe features are going to be shifted into modules... like
> low level IO, formats (bye bye rarely used feature), regex's (j/k) etc.
Just because they are moved into modules doesn't mean they suddenly
become non-important, or don't have to work correctly anymore.
And if those modules aren't automatically loaded on demand (if they aren't
Perl becomes like Python, where you can't do anything interesting without
first loading a set of modules), perlgolf wouldn't be so interesting in
perl6. You'd first have to ruin your score loading the modules.
Of course, if the modules are loaded automatically on demand, the
difference between 'core feature' and 'module feature' vanishes
on the language level.
> Most of these you wouldn't mind using a module for, as long as it was
> part of the core. Many perl features are core, that don't need to be...
> e.g. networking/unix permissions stuff. Removing these makes a far cleaner
> language.
Yeah, it's called Python, which doesn't allow you to do anything
interesting without first doing a bunch of imports.
I don't care for a "clean language". There are lots of nice and clean
languages around. Python and Haskell, to name a few. I always remained
programming in Perl not because it was "clean", but because it so
*useful*. Probably because it *isn't* "clean".
As for "cleanness", this is my interpretation of how perl6 is going
to work:
%foo = ();
if %foo {"key"} {print "Hello 1"}
####
%foo = ();
if %foo{"key"} {print "Hello 2"}
####
%foo = ();
if %foo{"key"}{print "Hello 3"}
Case 1 will print "Hello 1"; this is a block after the if statement.
Case 2 will not print anything. The print is in the 'then' part
of the if.
Case 3 will be a syntax error - an if statement with a condition,
but not block.
You call this **CLEAN**? Not even in Python can a space influence
control flow that significantly. (In fact, in Python, Java, C, Pascal,
awk, and perl5, whitespace between an aggregates names and its index is
optional. Not mandatory, not forbidden, no, optional).
> Maybe to awaken your interest, you should remember that Perl 6 may offer
> great golfing oppertunity, since you'll be able to choose either Perl 5 or
> Perl 6. This means that you could overtake Eugene or Lars or whoever has
> taken the top spot... and the other 30 or so people above you by:
>
> perl -5e'winning golf solution here'
>
> isn't that going to be cruel, with many more oppertunities for varient
> solutions.
If I had an interest in participating in golfing tournements, I'd
join the pros and learn APL.
> > Let's deal with things that exist. Like perl5. Perl 5.8 certainly isn't
> > marking 'for' as deprecated, so it won't disappear any sooner than 5.12.
> > BTW, if Larry is going to rename 'for' to 'loop', then he plans to keep
> > it around. Doesn't sound deprecated at all to me.....
>
> 'foreach' is really a workaround since 'for' was already taken. Larry
What do you mean "workaround"? In Perl5, the 'foreach' and 'for' keywords
are interchangable.
'for (@list)'
and
'foreach (my $i = 0; $i < @list; $i ++)'
are both valid perl5. There's no workaround, just an alternative name.
> does some renaming, changes the behaviour a bit, and hey presto... making
> loops of all kinds gets easier. This lovely snippet shows the most common
> use of 'for' loop in Perl 5.
>
> for 1 .. 100 -> $line {
> print "$line: @array[$line]\n";
> }
>
> Now, that's definately more beautiful in my book, the 'foreach' style is:
"Definately more beautiful"? It still has three parts, a keyword,
a list and an interator. Swapping the order a bit and exchanging
'(' and ')' for a '->' don't fill me with warm fuzzy feelings.
>
> foreach my $line (1 .. 100) {
> print "$line: @array[$line]\n";
> }
And of course there's also the underappreciated 'map':
map {print "$_: $array[$_]\n"} 1 .. 100;
or
{my $i = 0; map {$i ++; print "$i: $_\n"} @array [1 .. 100]}
which has its own merits.
> And in C style that would be:
>
> for (my $line = 1; $line <= 100; $line++) {
> print "$line: @array[$line]\n";
> }
You won't hear me advocating a C-style for loop to iterate
over an array.
Abigail