Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6

by jkahn (Friar)
on Apr 27, 2003 at 06:33 UTC ( #253453=note: print w/ replies, xml ) Need Help??


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:

loop { $life.display(); $life.calculate(); }
Then there's no nasty surprise when someone does:
# somewhere far, far, away $life.display; `shell-script;clear`; # weird stuff on screen tty $life.display; # refresh terminal *only*
later. I recognize that's personal preference, but Side Effects Are Scary.


Comment on Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
Select or Download Code
Re: Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
by TheDamian (Priest) on Apr 27, 2003 at 21:44 UTC
    Quite so. Fixed in the original node. Thanks!

    (Hopefully someone will tie this back to the thread on "Damian Isn't Infallible" :-)

Re: Re: Re: Prolegemona To A Future Scripting Language: Game Of Life In Perl 6
by TheDamian (Priest) on Apr 27, 2003 at 21:57 UTC
    As for changing the control flow in .display, yes, I was tempted to do so too.

    But that went beyond "idiomaticization" and became an issue of software engineering. In the end I deliberately didn't hoist the call to .calculate because I felt it was more important to preserve as much comparability with the original as was consistent with an idiomatic Perl 6 implementation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://253453]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-04-20 22:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls