Re: Is there a way to bulky feed?

2009-07-10 Thread Xiao Yafeng
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 +...@b3} == @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..100 - $x {
func1($x) if $pid = fork;
   }
  above code will loop 100  times, fork 100
processes and waste most of memory on machine.
   if I can say,
my @b[1]; for 1..100 - @b{
   func2(@b) if $pid = fork;
}
   IMHO, preceding code will be better in term of memory
utilization.


Re: Is there a way to bulky feed?

2009-07-10 Thread yary
I understand now. Given a large list, you'd like to assign chunks of
the list to an array, easily, while looping. In other words, you're
looking for a way to abbreviate this:

my $chunk_size=10_000;
my @big=''..'mnop';
for ^...@big :by $chunk_size {
  my @chu...@big[$_..($_+$chunk_size,@big.end).min]
  ... # Do stuff with @chunk
}

I'm a perl6 novice so there probably is a more elegant way to write
the above already.

From your original email, I like this idea-
for ''..'mnop' - *...@chunk[10_000] { ... } # @chunk is 1 elems or less
though I think the syntax has to change a bit. I used the *@ sigil
because chunk is slurpy, but only up to 10,000 items. Wrong on a
couple levels?

By the way, you shouldn't predeclare @chunk as you did in the
original example-
  my @a = 1 2 3 4; my @b[2]; for @a -@b {;}
the @b in the pointy block is a new declaration that shadows the
earlier my @b[2] declaration.


Is there a way to bulky feed?

2009-07-09 Thread Xiao Yafeng
My question is: could I write below code in perl6:
my @a = 1 2 3 4; my @b[2]; for @a -
@b {;} # 2 loops like for @a - $b[0],$b[1]{;}
my @a = 1 2 3 4; my @b; for @a - @b
{;} # 1 loop
my @a = 1 2 3 4; my @b[2];
grep(@b){say 'yes' if +...@b3} == @a;   # 2 loops like
grep {$^a+$^b 3} == @a;
my @a = 1 2 3 4; grep{say 'yes' if +...@_
=10} == @a;   # slurp

Since memory is cheaper and cheaper, bulky feed can maximize to make use of
memory and reduce loops.
Any thoughts?


Re: Is there a way to bulky feed?

2009-07-09 Thread yary
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 +...@b3} == @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.