LoginSignup
0
0

More than 5 years have passed since last update.

Perl 6 の for ループが lazy になった

Last updated at Posted at 2013-02-04

Rakudo Star 2013.01 より for ループがデフォルトで lazy な挙動をするようになった。これが何を意味するか正確には把握していないが、ブロックの末尾にある for ループが LEAVE フェーズより後に実行されるようになったことには注意が必要そうだ:

use v6;

sub f() {
    LEAVE { say 'leaving' }
    for 1..3 {
        say $_;
    }
}

f;
say 4;

# => leaving
# => 1
# => 2
# => 3
# => 4

当然ながら、 for ループの後に文が続く場合、ループは文より先に実行される:

use v6;

sub f() {
    LEAVE { say 'leaving' }
    for 1..3 {
        say $_;
    }
    say 'returning';
}

f;
say 4;

# => 1
# => 2
# => 3
# => returning
# => leaving
# => 4
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0