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
#`[Nim example: | |
# Thanks to Nim's 'iterator' and 'yield' constructs, | |
# iterators are as easy to write as ordinary | |
# functions. They are compiled to inline loops. | |
iterator oddNumbers[Idx, T](a: array[Idx, T]): T = | |
for x in a: | |
if x mod 2 == 1: | |
yield x |
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
#!/usr/bin/env raku | |
use MONKEY-SEE-NO-EVAL; | |
#| takes markdown file and evals all code lines delimited by '```perl6 xxx ```' | |
sub MAIN( | |
$filename!, #= '/pathto/example.md' | |
) { | |
my @lines = $filename.IO.lines or die 'no file found'; | |
my $toggle = False; |
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
#viz. https://rosettacode.org/wiki/100_doors | |
#`[ Elm for comparison | |
import List exposing (indexedMap, foldl, repeat, range) | |
import Html exposing (text) | |
import Debug exposing (toString) | |
type Door = Open | Closed | |
toggle d = if d == Open then Closed else Open |
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
sub dims-match( @a ) { | |
given @a { | |
when *== 0 { '' } | |
when *== 1 { .first } | |
when *>= 2 { .&type-hint } | |
} | |
} | |
gather { | |
for $.dictionary.type-to-dims.kv -> $key, $value { |
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
say my @input = (1, 4, -3, -6, 5, 6); | |
sub demerge( $aoa is rw, $value ) { | |
state $first = 1; | |
state $newi = 0; | |
state $last; | |
my $this = $value.sign; | |
if $first { |
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.d; | |
grammar Timestamp { | |
token TOP { <year><month><day>T<hours><minutes> } | |
token year { \d**4 } | |
token month { \d**2 } | |
token day { \d**2 } | |
token hours { \d**2 } | |
token minutes { \d**2 } | |
} |
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 Grammar::Tracer; | |
grammar Timestamp { | |
token TOP{^<y><m><d>T<hr><mn>$} | |
token y {\d**4} | |
token m {\d**2} | |
token d {\d**2} | |
token hr {\d**2} | |
token mn {\d**2} | |
} |
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 Grammar::Tracer; | |
grammar Timestamp { | |
token TOP{^<y><m><d>T<hr><mn>$} | |
token y {\d**4} | |
token m {\d**2} | |
token d {\d**2} | |
token hr {\d**2} | |
token mn {\d**2} | |
} |
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 Grammar::Tracer; | |
grammar Timestamp { | |
token TOP{^<y><m><d>T<hr><mn>$} | |
token y {\d**4} | |
token m {\d**2} | |
token d {\d**2} | |
token hr {\d**2} | |
token mn {\d**2} | |
} |
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
class Point { | |
has Int $.x; | |
has Int $.y; | |
method distance(Point $other) { | |
abs(self.y - $other.y) + abs(self.x - $other.x); | |
} | |
#`[ | |
method Str { |
NewerOlder