I think method display should actually look like this:
method display { iterate { print $.grid[$^x][$^y] ?? '+' :: '.'; print "\n" if ($^x == $.max); # print each row on own line } print "\n"; # blank line follows grid print "Turn $(++$.count), press enter to continue" print " or ctl-c to quit"; <$*IN>; .calculate(); } # end method display
A separate style comment: wouldn't it be a bit cleaner to remove the .calculate(); line from method display and change the loop at the top so that it reads:
Then there's no nasty surprise when someone does:loop { $life.display(); $life.calculate(); }
later. I recognize that's personal preference, but Side Effects Are Scary.# somewhere far, far, away $life.display; `shell-script;clear`; # weird stuff on screen tty $life.display; # refresh terminal *only*
In reply to Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
by jkahn
in thread Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
by jaldhar
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |