Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Last active December 11, 2017 21:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/919f75cbe48b2aadeeedf75bc9434176 to your computer and use it in GitHub Desktop.
Save zoffixznet/919f75cbe48b2aadeeedf75bc9434176 to your computer and use it in GitHub Desktop.
class Foo {
has $.times = 0;
method meow { ++$!times }
}
my $o = Foo.new;
# method $o: calling
meow $o:;
# Standard calling
$o.meow;
$o.?meow;
$o.+meow;
$o.*meow;
# Hyper calling
$o».meow;
$o».?meow;
$o».+meow;
$o».*meow;
# Name-in-string calling
$o."meow"();
$o.?"meow"();
$o.+"meow"();
$o.*"meow"();
# Hyper name-in-string calling
$o»."meow"();
$o».?"meow"();
$o».+"meow"();
$o».*"meow"();
# methodop $variable calling
my $meth = $o.^lookup: 'meow';
$o.$meth;
$o.?$meth;
$o.+$meth;
$o.*$meth;
# Hyper methodop $variable calling
$o».$meth;
$o».?$meth;
$o».+$meth;
$o».*$meth;
# $variable() calling
$meth($o);
$meth.($o);
$meth».($o);
# &variable calling
my &meth = $o.^lookup: 'meow';
$o.&meth;
$o.?&meth;
$o.+&meth;
$o.*&meth;
# Hyper &variable calling
&meth = $o.^lookup: 'meow';
$o».&meth;
$o».?&meth;
$o».+&meth;
$o».*&meth;
# &variable() calling
meth($o);
meth $o;
&meth($o);
&meth.($o);
&meth».($o);
# Meta assign op calling
my $v = $o;
$v .= meow;
# Function composition
($o.^lookup('meow') ∘ {$_})($o);
say "Saw {$o.times} different ways to call a method";
# OUTPUT: Saw 43 different ways to call a method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment