On Fri, Jul 10, 2009 at 12:29 AM, yary <not....@gmail.com> wrote:

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

What I thought is reducing loop times.
In some case, we don't need pop a item from a list one by one. Acoording to
memory capacity of machine, we can get  more than  one items from the list.
for a simple example,
                          for 1..1000000 -> $x {
                                    func1($x) if $pid = fork;
                                   }
                  above code will loop 1000000  times, fork 1000000
processes and waste most of memory on machine.
                   if I can say,
                my @b[10000]; for 1..1000000 -> @b{
                                   func2(@b) if $pid = fork;
}
               IMHO, preceding code will be better in term of memory
utilization.

Reply via email to