This file contains hidden or 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
| $leela.eat('dog food'); | |
| $leela.bark(); | |
| $leela.eat('grass'); | |
| my $old_tag = $leela.tag(); | |
| $leela.tag = 'Leela Follett'; | |
| $leela.wag(); | |
| say $leela.name ~ '\'s tag said ' ~ $old_tag ~ ', now it says ' ~ $leela.tag; |
This file contains hidden or 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 Tail | |
| { | |
| method wag() | |
| { | |
| say "swish, swish, swish"; | |
| } | |
| } | |
| class Dog is Animal | |
| { |
This file contains hidden or 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
| my $dog = Animal.new( name => 'Leela' ); | |
| $dog.eat('dog food'); | |
| $dog.sleep(); |
This file contains hidden or 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 Animal | |
| { | |
| has Str $.name; | |
| method eat( $food ) | |
| { | |
| say "$.name is eating some $food"; | |
| } | |
| method sleep($self:) |
This file contains hidden or 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
| my $stream; | |
| { | |
| my $previous = 0; | |
| $stream = sub { $previous++ }; | |
| } |
This file contains hidden or 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
| my $stream; | |
| { | |
| my $previous = 0; | |
| $stream = sub { $previous++ }; | |
| } | |
| my $limited_stream; | |
| { | |
| my $previous = 0; | |
| $limited_stream = sub { return $previous if $previous++ < 10; return; }; |
This file contains hidden or 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
| while( defined (my $val = $stream->() ) ) | |
| { | |
| say "We've reached number $val!"; | |
| } |
This file contains hidden or 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
| my @list = 1..100; | |
| for @list -> $left, $center = '', $right = '' | |
| { | |
| say "$left - $center - $right"; | |
| } |
This file contains hidden or 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
| my @list = 1..100; | |
| for @list -> $left, $center?, $right? | |
| { | |
| say "$left - $center - $right"; | |
| } | |
This file contains hidden or 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
| my @list = 1..100; | |
| for @list -> $left, $center, $right | |
| { | |
| say "$left - $center - $right"; | |
| } | |
| ~/Documents/Projects/rakudo |