On Wed, Jul 8, 2009 at 8:45 PM, Xiao Yafeng <xyf.x...@gmail.com> wrote:

> Any thoughts?
>

First let's fix the whitespace in your post so it's easier to read-

My question is: could I write below code in perl6:

# 2 loops like for @a -> $b[0],$b[1] {;}
my @a = <1 2 3 4>; my @b[2]; for @a ->@b {;}

my @a = <1 2 3 4>; my @b; for @a -> @b{;}    # 1 loop

# 2 loops like grep {$^a+$^b >3} <== @a;
my @a = <1 2 3 4>; my @b[2];
  grep(@b){say 'yes' if +...@b>3} <== @a;

# slurp
my @a = <1 2 3 4>; grep{say 'yes' if +...@_>=10} <== @a;

One style point, generally a list of numbers is written as
my @a = 1..4; # list of numbers, <1 2 3 4> is a list of strings
my @a = '1'..'4' # equivalent to <1 2 3 4>

As for your original question, I am not quite sure what you're asking. Do
you want a simpler way to write
for 一..四 {say "$^x $^y";}
一 二
三 四
(... which assumes that unicode sequencing is working, I can't test that on
my machine!)

Or do you want something like-
for <yuht! yee sahm say> -> $a {for <eee arr> ->$b {say "$a $b"}}

Or using more memory and less looping (at least superficially!)
for 'a'..'d' X <A Z> {say "$^p $^q"};

In other words, if you can write some code that runs and tell us how you'd
like to simplify it, I might be able to answer better.

Reply via email to