This file contains 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
grammar Picker { | |
rule combination($rx, $narity) { | |
:my %*PICKED; | |
<choose($rx)> ** $narity | |
} | |
rule choose($rx) { | |
$<choice>=$rx <?{ | |
if %*PICKED{ ~$<choice> } { |
This file contains 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; | |
sub G($s) {gather $s()} | |
sub T($s) {take $s} | |
say qq{{ | |
<html> | |
<body> | |
<h1>Green Bottles...</h1> | |
{G { my $n = 10; | |
while $n > 0 {my $m = $n--; T qq{ |
This file contains 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
# naive approximation: pi = 1 - /1/3 + 1/5 ... | |
# language: perl6 / nqp | |
my $limit := 20_000; | |
my $n := 1; | |
my $pi_over_4 := 0.0; | |
while $n < $limit { | |
## my $m := 4.0*$n - 1.0; # this was making $m a Rat |
This file contains 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
# In the following Ruby code `xx -5` is treated as a method call, | |
# `yy -5` as an arithmetic expression. | |
# | |
def xx(n) ; 37 - n; end | |
puts xx -5 # output is 42 | |
yy = 37 | |
puts yy -5 # output is 32 |
This file contains 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; | |
grammar Brainfuck::Grammar { | |
rule TOP {^ [<cmd> || .+? ]* $} | |
proto token cmd { <...> } | |
token cmd:sym<ptr-inc> {\>} | |
token cmd:sym<ptr-dec> {\<} | |
token cmd:sym<inc> {\+} | |
token cmd:sym<dec> {\-} | |
token cmd:sym<input> {\,} |
This file contains 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; | |
use Test; | |
grammar G { | |
## use rule :ignorecase; # nyi in rakudo. not what we want anyway | |
## use sym :ignorecase #?? | |
rule TOP { <prop> + } | |
rule num {[\d|'.']+} | |
proto rule prop {<...>} | |
rule prop:sym<line-width> {:i <sym> ':' <num> } | |
rule prop:sym<line-height>:i { <sym> ':' <num> } |
NewerOlder