Re: How to write this properly in Perl 6?
In data 28 mai 2009 alle ore 00:13:19, Mark J. Reed markjr...@gmail.com ha scritto: You can write a sub to return the next step: sub bondigi { state $n=1; return (Bon Digi Bon Digi, Bon xx $n, Digi xx $n++); } Nahh. That's too easy... It's not fun :-) but I think an idiomatic Perl 6 solution would have a proper lazy Iterator. Yes, that's more interesting. -- Cosimo
Re: How to write this properly in Perl 6?
Mark (): but I think an idiomatic Perl 6 solution would have a proper lazy Iterator. How do we write one of those? Like this, I think: $ perl6 -e '.say for gather { my $n = 1; loop { take bon digi bon digi; take bon for ^$n; take digi for ^$n; ++$n } }' That currently parses in Rakudo, but hangs since we don't have Laziness. // Carl
Re: How to write this properly in Perl 6?
In data 27 mai 2009 alle ore 23:46:40, John M. Dlugosz 2nb81l...@sneakemail.com ha scritto: Anything in the existing implementation that's hostile to Perl 6? Just port it over by lightly editing the text or using a p5 module importer. Yes, right, but that wouldn't use Perl 6 features. To write from scratch, I suppose it's just a recursive function that talks and drinks beer. About the beer drinking, that's one of the main points :) I think the interesting part is when you want to see it from the real-world game point of view, so in this case, writing a function that returns the next correct word. In the Perl 5 solution, I wrote a function that allows you to do this: # Up to any number of repeats my $iter = bon_digi_sequence(5); while (my $word = $iter-()) { print $word, ' '; } I'm not saying it's difficult, of course. To me it's interesting to know from others (because I don't know) how would you go writing this function with the weapons Perl 6 gives you. -- Cosimo
How to write this properly in Perl 6?
Hi cool people, the Amazing Perl 6 thread was amazing. It reminded me how Perl 6 looks interesting and fun. So... how can I write properly, for some meaning of properly, the Perl 6 equivalent of this: http://search.cpan.org/dist/Games-BonDigi/ ? ( if it's not clear, you can run the example http://cpansearch.perl.org/src/COSIMO/Games-BonDigi-0.02/examples/generate_bondigi.pl ) -- Cosimo
Re: How to write this properly in Perl 6?
Cosimo (): the Amazing Perl 6 thread was amazing. It reminded me how Perl 6 looks interesting and fun. So... how can I write properly, for some meaning of properly, the Perl 6 equivalent of this: http://search.cpan.org/dist/Games-BonDigi/ ? Not sure if I grokked the whole set of rules, but here's a one-liner that does it: $ perl6 -e 'say (bon digi bon digi, bon xx ++$*n, digi xx $*n).join(, ) while *' // Carl
Re: How to write this properly in Perl 6?
Cosimo Streppone cosimo-at-streppone.it |Perl 6| wrote: Hi cool people, the Amazing Perl 6 thread was amazing. It reminded me how Perl 6 looks interesting and fun. So... how can I write properly, for some meaning of properly, the Perl 6 equivalent of this: http://search.cpan.org/dist/Games-BonDigi/ ? ( if it's not clear, you can run the example http://cpansearch.perl.org/src/COSIMO/Games-BonDigi-0.02/examples/generate_bondigi.pl ) Anything in the existing implementation that's hostile to Perl 6? Just port it over by lightly editing the text or using a p5 module importer. To write from scratch, I suppose it's just a recursive function that talks and drinks beer. You need external libraries for those, but the recursion is easy. --John
Re: How to write this properly in Perl 6?
Em Qua, 2009-05-27 às 23:46 +0200, Carl Mäsak escreveu: Not sure if I grokked the whole set of rules, but here's a one-liner that does it: $ perl6 -e 'say (bon digi bon digi, bon xx ++$*n, digi xx $*n).join(, ) while *' It does, but it would be prettier if it was lazy... for 2..* - $n { (bon digi bon digi, bon xx $n, digi xx $n).join(, ) } == $*OUT; Or put that into an array for more controlled fun... my @a == map { (bon digi bon digi, bon xx $n, digi xx $n).join(, ) }, 2..*; say @a[5]; But that still doesn't run in rakudo, since it doesn't support lazyness yet... daniel
Re: How to write this properly in Perl 6?
You can write a sub to return the next step: sub bondigi { state $n=1; return (Bon Digi Bon Digi, Bon xx $n, Digi xx $n++); } but I think an idiomatic Perl 6 solution would have a proper lazy Iterator. How do we write one of those?