Skip to content

Instantly share code, notes, and snippets.

/sample.pl Secret

Created March 23, 2016 13:15
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 anonymous/ee9caad3bc145cdfef37 to your computer and use it in GitHub Desktop.
Save anonymous/ee9caad3bc145cdfef37 to your computer and use it in GitHub Desktop.
failing with error : Cannot look up attributes in a type object
class MyInt is Int {
method square(){
self * self;
}
class Prime {
has $.start is rw = 2;
method is_prime(MyInt $val){
my Bool $flag = True;
loop {
last if $!start >= $val;
do {
$flag = False;
last;
} if $val % $!start == 0;
$!start += 1;
}
return $flag;
}
}
method test(){
Prime.is_prime(self);
}
}
print (1..10).eager.map(->$x { MyInt.new($x) }).grep(*.test).map(*.square);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment