Posted by
michael
on from the book-of-revelations dept.
rob_99 writes: "The third installment of the Apocalypse is out!" You may have missed the first or second Apocalypses. This one is roughly "all about operators".
Concatenating strings
by
seanadams.com
·
· Score: 4, Insightful
He stresses the importance of good huffman coding, then goes on to change the string concatenation operator "." to a three character sequence " _ "
...instead of:
$a . $b . $c
you'll say:
$a _ $b _ $c
String concatenation is such a commonly used perl feature that it deserves a single character operator. Discriminating between operators by the existence of white space before/after the character is an incredibly ugly kludge. Larry seems to admit it, too: This is to be construed as a feature
At least we don't have to use "+", like in JavaScript!
don't jump to conclusions:
by
Anonymous Coward
·
· Score: 4, Insightful
For all of those people who want to jump ship from perl6, all I can say is I'd give it some time. I've been playing around with the syntax in perl6, and I think people are giving it way too much short shrift, without thinking no less. Here, for example, are a couple of equivalent programs in perl6 and perl5:
Concatenating two arrays together:
perl5
my $biggest_index = (@array1 > @array2)? @array1:
@array2;
Comparing all of the elements in an array to one another for equality:
perl5:
for ($xx = 0; $xx @array1; $xx++)
{
($notequal = 1, last) if ($array1[$xx] ne $array2[$xx]);
}
if (@array1 != @array2)
{
$notequal = 1;
}
else
{
$notequal = 0;
}
Perl6:
$notequal = (@array1 ^!= @array2);
Perl5: setting an element to the first defined item:
my $element = (defined($a))? $a : (defined($b))? $b: 'default';
perl6:
my $element = $a// $b// 'default';
etc, etc. I could go on, but I'll leave it to damien && his exegesis...
Now, you could argue that things like the above don't belong in the language proper, and that it would be better to write functions to do them, but believe me, there are a hell of a lot of different low level functions that you can write, all with a little wrinkle here or there that makes them *slightly* different from the functions that you've written before - like doing cmp instead of ==, and so on.
So don't bolt before you see the final result.. I think its going to be really cool, especially being built on top of parrot....
Ed
(ps - as for the OO, I'd *also* hold my tongue if I were you. I've used the OO features of perl5 extensively, and its exceedingly flexible. There are aspects that I don't like (like no type checking of attributes as they are in a hash) but even this can be used to your advantage in programming.
so its definitely *not* worthless, and definitely something worth checking into. 50,000 line APIs don't just spring up overnight...
He stresses the importance of good huffman coding, then goes on to change the string concatenation operator "." to a three character sequence " _ "
...instead of:
$a . $b . $c
you'll say:
$a _ $b _ $c
String concatenation is such a commonly used perl feature that it deserves a single character operator. Discriminating between operators by the existence of white space before/after the character is an incredibly ugly kludge. Larry seems to admit it, too: This is to be construed as a feature
At least we don't have to use "+", like in JavaScript!
For all of those people who want to jump ship from perl6, all I can say is I'd give it some time. I've been playing around with the syntax in perl6, and I think people are giving it way too much short shrift, without thinking no less. Here, for example, are a couple of equivalent programs in perl6 and perl5:
// $b // 'default';
Concatenating two arrays together:
perl5
my $biggest_index = (@array1 > @array2)? @array1:
@array2;
for ($index = 0; $index $biggest_index; $index++)
{
$array1[$index] += $array2[$index];
}
perl6:
@array1 ^+= @array2;
Comparing all of the elements in an array to one another for equality:
perl5:
for ($xx = 0; $xx @array1; $xx++)
{
($notequal = 1, last) if ($array1[$xx] ne $array2[$xx]);
}
if (@array1 != @array2)
{
$notequal = 1;
}
else
{
$notequal = 0;
}
Perl6:
$notequal = (@array1 ^!= @array2);
Perl5: setting an element to the first defined item:
my $element = (defined($a))? $a : (defined($b))? $b: 'default';
perl6:
my $element = $a
etc, etc. I could go on, but I'll leave it to damien && his exegesis...
Now, you could argue that things like the above don't belong in the language proper, and that it would be better to write functions to do them, but believe me, there are a hell of a lot of different low level functions that you can write, all with a little wrinkle here or there that makes them *slightly* different from the functions that you've written before - like doing cmp instead of ==, and so on.
So don't bolt before you see the final result.. I think its going to be really cool, especially being built on top of parrot....
Ed
(ps - as for the OO, I'd *also* hold my tongue if I were you. I've used the OO features of perl5 extensively, and its exceedingly flexible. There are aspects that I don't like (like no type checking of attributes as they are in a hash) but even this can be used to your advantage in programming.
so its definitely *not* worthless, and definitely something worth checking into. 50,000 line APIs don't just spring up overnight...