Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 ( [id://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.

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
    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.

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
    Quite so. Fixed in the original node. Thanks!

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found