Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Limbic Region (3985)

Limbic Region
  (email not shown publicly)
http://gatcomb.org/joshua/perl.html

I love to code perl. If you want to hire me, see details on my homepage.
Thursday May 19, 2005
02:19 PM

Even More Fun With Pugs And Perl6

[ #24776 ]

I found 5 things that didn't work as expected today when porting p5 code to p6. I really think this is a great way to improve your p6 skills as well as find subtle bugs

1. my %hash = map { $_ => $_ } @array;
That correctly doesn't work. It was just unexpected. Either of the following two does work (as designed):
        my %hash = map { $_ => $_; } @array;
        my %hash = map -> $_ { $_ => $_ } @array;

2. sub foo (Int $bar) {say $bar;} foo('hello')
I was hoping for a type check error. Instead it just says "hello\n". While this is a bug, it is unclear what the proper behavior should be. My recollection that the difference between int and Int is that 1 would autocovert for you but wouldn't remember doing it while the other would be an outright failure. Autrijus has encouraged me to write p6.l about it so the proper behavior can have a test added (which I will do).

3. 0 .. $foo - 3 didn't work as expected. I needed to do 0 .. ($foo - 3). This apparently was a bug introduce with infix operators that had already been fixed. Regardless it should have a test for it to make sure it doesn't get unfixed. I believe iblech volunteered for the job.

4. my $i=3; my @array = 1..5; @array[ --$i ]++; say $i
That printed 1 and not 2. This apparently has already been fixed as well but should have a "make sure it doesn't break again" test.

5. while ( my @combo = sort { $^a $^b } ) { ... }
This doesn't work. Autrijus agrees that it is a bug but wants a minimal test case. I am going to try and provide it.

For challenge and more information, see
http://perlmonks.org/index.pl?node_id=458728

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Your first can also be written this way, I believe:
    #             |
    #             V
    my %hash = map:{ $_ => $_ } @array;
    The colon turns it into an adverbial block to map.
    • Scratch that. Looks like adverbial blocks can't be in the middle of an argument list, so it would be:
      my %hash = @array.map:{ $_ => $_ };