in reply to Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
in thread Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
Seems like the method display as written would actually print all the cells in one row -- method iterate doesn't have an explicit hook for "reached end of line". That's fine, since we have $.max available within the object.
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*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
by TheDamian (Vicar) on Apr 27, 2003 at 21:57 UTC | |
Re: Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
by TheDamian (Vicar) on Apr 27, 2003 at 21:44 UTC |
In Section
Cool Uses for Perl