Last active
January 7, 2016 03:54
-
-
Save awwaiid/268cf5a3517a87806897 to your computer and use it in GitHub Desktop.
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
# namespace | |
class A::B { | |
# "Smiley" type adverb Str:D | |
# Named param -- adverb with default True value | |
method say-hi(Array[Str:D] :$names) { | |
# precedence dropper | |
say $names.map: {"hi $_"}; | |
} | |
} | |
# Namespace separator | |
my $x = A::B.new; | |
# Dynamic namespace | |
my $x = ::("A::B").new | |
# Invocant marker | |
say-hi($x: names => [<me you>]); | |
# Prefix operator method | |
my $a = 1; | |
$a.:<++>; # like ++$a | |
# signature literal | |
my $sig = :(Int $foo); | |
# object hashes | |
my $x = :{ (now) => "when?" }; | |
# Binding | |
my $y := $a; | |
# Container identity | |
$y =:= $a; # True | |
# Compile-time (read-only) binding | |
my $z ::= $y; | |
# longname? | |
sub infix:<ya> { ... } | |
# Colon-Pair (often seen as adverbs) | |
my $x = 'cat'; | |
:foo # 'foo' => True | |
:foo(5) # 'foo' => 5 | |
:foo('dog') # 'foo' => 'dog' | |
:foo($x) # 'foo' => 'cat' | |
:foo<bar> # 'foo' => 'bar' | |
:foo<bar baz> # 'foo' => ('bar', 'baz') | |
:foo<$x> # 'foo' => '$x' | |
:foo<<$x>> # 'foo' => 'cat' | |
:foo<<$x dog>> # 'foo => ('cat', 'dog') | |
Pair.new('foo', 'bar') # 'foo' => 'bar' | |
# Loop labels | |
MYLABEL: for ^100 { | |
for ^200 { | |
last MYLABEL; | |
} | |
} | |
# Twigil for formal named param for a block (like $^x) | |
say { $:add ?? $^a + $^b !! $^a - $^b }( 4, 5 ) :!add | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment