This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my token param-x { | |
<[ab]>+ { say <matched word only> } || | |
[ \w+ { say <after first word> } '=' \w+ ] | |
} | |
my token param-y { | |
[ \w+ {say 'after first word'} '=' {say <after equals> } \w+ ] || | |
<[ab]>+ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#use Grammar::Tracer; | |
grammar g { | |
token keywords { 'or' } | |
token BASEIDENT {\w+<!after <keywords>>} | |
token BASEIDENT_SIMPLER {\w+<!after 'or'>} | |
token TOP { <BASEIDENT> } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
class C { | |
has $.a is rw = 3 | |
} | |
my $o = C.new; | |
say $o.a; | |
$o.a = 4; # ok | |
say $o.a; | |
$o.a(5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
class C { has $.a = 3; | |
multi method a(Int $i) { | |
$!a = $i * 2 | |
} | |
} | |
my $o = C.new; | |
$o.a(4); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl6 | |
use v6; | |
use Test; | |
plan 4; | |
# based on within clause from Grammar::Modelica | |
grammar TestWithSemi { | |
rule TOP {^<ps>$} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
# this tests that you can define mutators, that do more interesting | |
# things than merely assigning the value! | |
# For this variant we do some fakery and use a lexical as backing | |
# store instead of an attribute. | |
use Test; | |
plan 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class c { | |
sub double() is rw { | |
my $storage = 0; | |
Proxy.new( | |
FETCH => method () { say self.WHAT; $storage * 2 }, | |
STORE => method ($new) { $storage = $new }, | |
) | |
} | |
method m { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
x='' | |
for (i = 0; i < 100000; i++) { | |
x += y | |
} | |
console.log(x.length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perl 6 version that runs faster than Perl 5 equivalent | |
my int ($a, $one, $three, $limit) = (42, 1, 3, 10000000); | |
loop (my int $i = 0; $i < $limit; $i++) { | |
$a += $one + $a%$three | |
} | |
say $a | |
# Perl 5 equivalent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use MONKEY-SEE-NO-EVAL; | |
my $simple_arith_sub = q:to/END_SIMPLE_ARITH_SUB/; | |
sub { | |
my $r = 0; | |
for (1..10_000_000) { | |
$r += 1 + $r % 3 | |
} | |
print $r, "\n"; | |
} |
NewerOlder