Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Last active January 7, 2016 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awwaiid/268cf5a3517a87806897 to your computer and use it in GitHub Desktop.
Save awwaiid/268cf5a3517a87806897 to your computer and use it in GitHub Desktop.
# 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