RE: array/hash manipulation [was :what's with 'with'?]

2001-07-25 Thread Sterin, Ilya

Yes, a what you described would work just fine, but I am wondering if just a
loop control variable that can be possibly set at the begining of the loop
which would not necessarily exit the loop, but rather yield kind of a true
or false.

for ($a, $b, $c) (@A, @B, @C) : @B  ### This would assign a true|false 1|0
to control variable when it reaches this loop number.

But I guess incrementing/decrementing the control variable would work just
fine, since it can later be accessed in the loop and to the shortest array.

It can be easily done with a few lines of code without any special vars,
etc..., just by incrementing a counter, while comparing to the shortes
array, but I'm wondering if a control variable would yield other benefits
and if nothing else decrease the amount of written code.

Ilya


-Original Message-
From: David L. Nicol
To: Sterin, Ilya
Cc: Perl 6 Language
Sent: 07/24/2001 6:03 PM
Subject: Re: array/hash manipulation [was :what's with 'with'?]

"Sterin, Ilya" wrote:

> But now I am trying to figure out, if you are not comparing elements
of the
> array and for example if you need to loop through 3 arrays at the same
time,
> but you need to know, whithin the loop, when the shortest array's last
> element is reached, how would that be accomplished within the loop if
the
> array would just be reset and continue until the longest end is
reached?
> 
> Ilya

You have three generator functions that each produce one element at a
time,
and they, and a fourth, flag-checking function (possibly the loop
control variable itself) all have access to a flag that is decremented
by each generator when it starts looping.  For instance, rewrite

for ($c,$d,$e) (@A, @B, @C) { ... };

into something very similar if not exactly like this:



{   
my $arrays_index=0;
while ($arrays_index < @A
and $arrays_index < @B
and $arrays_index < @C){
local (*c, *d, *e) =
($A[$arrays_index % @A],
 $B[$arrays_index % @B],
 $C[$arrays_index % @C]);

...

$arrays_index+=1;
};
};


a workaround of some kind would be required for empty arrays, or
maybe having it die on an empty array is fine.


-- 
   David Nicol 816.235.1187
"Hush!" said the little boy's mother.  But it was too late.  The
emperor's agents had already heard his meek, innocent question and
were rushing through the crowd.  The emperor's agents took the boy
away and he was never, ever, seen or heard from again.



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-21 Thread Sterin, Ilya

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, July 21, 2001 5:50 AM
> To: Sterin, Ilya; 'raptor '; Perl 6 Language
> Subject: RE: array/hash manipulation [was :what's with 'with'?]
>
>
> "Sterin, Ilya" <[EMAIL PROTECTED]> wrote:
> > Just one question, how
> > would merge behave on two different sized arrays.
> >
> > @a = (1..5);
> > @b = (1..10);
> > merge(@a, @b);
> >
> > ##Would return (1,1,2,2,3,3,4,4,5,5,??
> >
> > Would it stop on the shortest array.  Couldn't quite find such
> explanation
> > in the RFC.
> >
> I don't think I specified this in the RFC, since I remember having some
> debates with Damian and others about it that weren't resolved. Now that
> I've had a chance to think about this some more, I think the correct
> behaviour is for the shorter list to reset to the start and continue.

That would be one possible way, but when comparing two array of different
lengths, I guess I would expect undef to compare to the elements of the
longest array that bypassed the length of the shortest array, but that
wouldn't be a problem, just extra code to undef all elements of the shortes
array to equal the length of the longest array.

$shor_arr[$_] = undef for (($#long_arr - $#shor_arr)..$#long_arr);

But now I am trying to figure out, if you are not comparing elements of the
array and for example if you need to loop through 3 arrays at the same time,
but you need to know, whithin the loop, when the shortest array's last
element is reached, how would that be accomplished within the loop if the
array would just be reset and continue until the longest end is reached?


Ilya


>It
> is this behaviour that is the source of J and APL's broadcasting
> flexibility. For details see:
>   http://www.jsoftware.com/primer/agreement.htm
>
> --
>   Jeremy Howard
>   [EMAIL PROTECTED]



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-21 Thread Sterin, Ilya



> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, July 21, 2001 5:50 AM
> To: Sterin, Ilya; 'raptor '; Perl 6 Language
> Subject: RE: array/hash manipulation [was :what's with 'with'?]
>
>
> "Sterin, Ilya" <[EMAIL PROTECTED]> wrote:
> > Just one question, how
> > would merge behave on two different sized arrays.
> >
> > @a = (1..5);
> > @b = (1..10);
> > merge(@a, @b);
> >
> > ##Would return (1,1,2,2,3,3,4,4,5,5,??
> >
> > Would it stop on the shortest array.  Couldn't quite find such
> explanation
> > in the RFC.
> >
> I don't think I specified this in the RFC, since I remember having some
> debates with Damian and others about it that weren't resolved. Now that
> I've had a chance to think about this some more, I think the correct
> behaviour is for the shorter list to reset to the start and continue.

That would be one possible way, but when comparing two array of different
lengths, I guess I would expect undef to compare to the elements of the
longest array that bypassed the length of the shortest array, but that
wouldn't be a problem, just extra code to undef all elements of the shortes
array to equal the length of the longest array.

$shor_arr[$_] = undef for (($#long_arr - $#shor_arr)..$#long_arr);

But now I am trying to figure out, if you are not comparing elements of the
array and for example if you need to loop through 3 arrays at the same time,
but you need to know, whithin the loop, when the shortest array's last
element is reached, how would that be accomplished within the loop if the
array would just be reset and continue until the longest end is reached?


Ilya


>It
> is this behaviour that is the source of J and APL's broadcasting
> flexibility. For details see:
>   http://www.jsoftware.com/primer/agreement.htm
>
> --
>   Jeremy Howard
>   [EMAIL PROTECTED]



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-21 Thread jh_lists

"Sterin, Ilya" <[EMAIL PROTECTED]> wrote:
> Just one question, how
> would merge behave on two different sized arrays.
> 
> @a = (1..5);
> @b = (1..10);
> merge(@a, @b);
> 
> ##Would return (1,1,2,2,3,3,4,4,5,5,??
> 
> Would it stop on the shortest array.  Couldn't quite find such explanation
> in the RFC.
> 
I don't think I specified this in the RFC, since I remember having some
debates with Damian and others about it that weren't resolved. Now that
I've had a chance to think about this some more, I think the correct
behaviour is for the shorter list to reset to the start and continue. It
is this behaviour that is the source of J and APL's broadcasting
flexibility. For details see:
  http://www.jsoftware.com/primer/agreement.htm

-- 
  Jeremy Howard
  [EMAIL PROTECTED]



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Sterin, Ilya



> -Original Message-
> From: Jeremy Howard [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 20, 2001 8:40 PM
> To: Sterin, Ilya; 'raptor '; [EMAIL PROTECTED]
> Subject: Re: array/hash manipulation [was :what's with 'with'?]
>
>
> "Sterin, Ilya" <[EMAIL PROTECTED]> wrote:
> > Hmmm. Didn't think about that.  That would be a nice way, that
> way you can
> > manipulate it's behaviour depending with how many aliases you provide.
> >
> > for my $el1, $el2 ( (@foo, @bar) ) {
> > print "$el\n"
> >  }
> >
> > $el1 and $el2 would of course be aliases, right?
> >
> I don't think that this special purpose notation is necessary. With the
> improved 'want' proposed by Damian, the following should be easy
> to achieve:
>
>   @a = (1,2,3,4);
>   for ($b,$c) (@a) { print "$b $c"}
>   # prints:
>   # 1 2
>   # 3 4
>   %d = (a=>1, b=>2);
>   for ($b,$c) (@a) { print "$b $c"}
>   # prints:
>   # a 1
>   # b 2
>
> Which with the merge() RFC makes the desired behaviour for multiple lists
> easy:
>
>   @a = (1,2);
>   @b = (3,4);
>   for ($b,$c) merge(@a,@b) { print "$b $c"}
>   # prints:
>   # 1 3
>   # 2 4

Now this would be cool.  I guess this would be easier to interleave the
arrays, than to implement new ways of calling loops.  Just one question, how
would merge behave on two different sized arrays.

@a = (1..5);
@b = (1..10);
merge(@a, @b);

##Would return (1,1,2,2,3,3,4,4,5,5,??

Would it stop on the shortest array.  Couldn't quite find such explanation
in the RFC.

Ilya



>
> So, no really new syntax, no special purpose behaviour, just the obvious
> extension of for-iterators to list context, and the introduction
> of one new
> function (which happens to have many other applications).
>



Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Jeremy Howard

"Sterin, Ilya" <[EMAIL PROTECTED]> wrote:
> Hmmm. Didn't think about that.  That would be a nice way, that way you can
> manipulate it's behaviour depending with how many aliases you provide.
>
> for my $el1, $el2 ( (@foo, @bar) ) {
> print "$el\n"
>  }
>
> $el1 and $el2 would of course be aliases, right?
>
I don't think that this special purpose notation is necessary. With the
improved 'want' proposed by Damian, the following should be easy to achieve:

  @a = (1,2,3,4);
  for ($b,$c) (@a) { print "$b $c"}
  # prints:
  # 1 2
  # 3 4
  %d = (a=>1, b=>2);
  for ($b,$c) (@a) { print "$b $c"}
  # prints:
  # a 1
  # b 2

Which with the merge() RFC makes the desired behaviour for multiple lists
easy:

  @a = (1,2);
  @b = (3,4);
  for ($b,$c) merge(@a,@b) { print "$b $c"}
  # prints:
  # 1 3
  # 2 4

So, no really new syntax, no special purpose behaviour, just the obvious
extension of for-iterators to list context, and the introduction of one new
function (which happens to have many other applications).





Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Jeremy Howard

"John Porter" wrote:
> Sterin, Ilya wrote:
> > Don't really know which would be more helpful, since I first need to
find a
> > scenerio where I would use this facility, then what result would I
expect
> > once the shortest list runs out.
>
> Let us ask the PDL folks.
>
> In fact, I'm quite sure this has been done already.
>
Well, I'm not a PDL folk, but I'm a p6-data folk so perhaps I qualify.

The interest in non-matching indices comes in 'broadcasting', which,
assuming the element-wise operators mentioned by Larry, works like this:

  @b = (1,2,3);
  @c = (2,4,6);
  @d := @b :* @c;   # Returns (2,8,18)
  @e := 3 :* @c;# Returns (6,12,18)

Notice that the scalar '3' is 'broadcast' across the length of @c just as if
it was the list (3,3,3).

Or if you prefer text-crunching examples to number crunching, it works like
this:

  @people = ('adam', 'eve ', 'bob ');
  @scores = (7,9,5);  # Score for each person
  @histogram := '#' :x @scores; # Returns ('xxx','x','x')
  print join("\n", @people . ' ' . @histogram);

Notice that the scalar '#' has been broadcast across the length of @scores.

For more information, see:
  http://dev.perl.org/rfc/82.html#Broadcasting
which explains the more interesting case of multidimensional broadcasting.
Note that this RFC is a little dated now, in that Larry has proposed the
adverb ':' to mean "apply element-wise", so the examples in the RFC really
need a ':' added before all the operators. Other than that nothing should
need to change.

For Pyton's implementation of this concept, see:
  http://starship.python.net/~da/numtut/array.html#SEC19

See also implementations in J and APL (which is the best role model), PDL,
functional languages like Haskell, and mathematical languages like
Mathematica.





Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread John Porter

Sterin, Ilya wrote:
> Don't really know which would be more helpful, since I first need to find a
> scenerio where I would use this facility, then what result would I expect
> once the shortest list runs out.  

Let us ask the PDL folks.

In fact, I'm quite sure this has been done already.

-- 
John Porter




RE: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Sterin, Ilya

Right it can either stop as the shortest list iteration is done, or just set
the corresponding alias to undef.

Don't really know which would be more helpful, since I first need to find a
scenerio where I would use this facility, then what result would I expect
once the shortest list runs out.  Do I still need the values of the longer
list, for one reason or another, or do I want the loop aborted?

Ilya

-Original Message-
From: David L. Nicol
To: Sterin, Ilya
Cc: 'raptor '; '[EMAIL PROTECTED] '
Sent: 07/20/2001 1:44 PM
Subject: Re: array/hash manipulation [was :what's with 'with'?]

"Sterin, Ilya" wrote:
> 
> Hmmm. Didn't think about that.  That would be a nice way, that way you
can
> manipulate it's behaviour depending with how many aliases you provide.
> 
> for my $el1, $el2 ( (@foo, @bar) ) {
> print "$el\n"
>  }
> 
> $el1 and $el2 would of course be aliases, right?
> 
> But one though might be, what happens if this is written...
> 
> for my $el1, $el2 ( (@foo, @bar, @arr) ) {
> print "$el\n"
>  }
> 
> Does this bahave in the same way as the first one, but we just don't
set
> @arr elements, since the user forgot to provide a third alias, or
should
> this croak at compile time?
> 
> Ilya

Given your definition of 

for [list of variables] ([comma-listed arrays]) {...}

I'd consider anything less than a full crash and burn if the number of
variables and the number of arrays did not match to be dangerous.  If
you
want @bar and @arr combined, you could present them as 

for $fooelem, $bar_arr_elem (@foo, (@bar, @arr)) { ...

I would also expect this to stop as soon as the shortest list is out
of elements; also to take other kinds of generators besides
preconstucted
lists in there as the arrays, making the syntax

for [list of N variables] ([list of N generators]) {...}

 
-- 
   David Nicol 816.235.1187
   "Mary had a little chainsaw" -- Angus Oblong



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Sterin, Ilya

No, I don't think you are understanding it correctly.  It's not about
looping sequentially, but rather simultaneouly, for comparison purposes.

@foo = (1,2,3);
@bar = (1,2,3);
for my ($foo, $bar) (@foo, @bar)  #As the index for @foo increases, so 
  #does @bar index
{
print "OK\n" if $foo == $bar;
}

Will print...
OK
OK
OK

Ilya

-Original Message-
From: Eric Roode
To: [EMAIL PROTECTED]
Sent: 07/20/2001 11:30 AM
Subject: Re: array/hash manipulation [was :what's with 'with'?]

on Fri Jul 20, Mark REED wrote:
>I'm sorry, but I fail to see how this is a big improvement over the
>current version:
>
>while (my ($key, $val) = each %my_hash)
>{ ... }

And a workalike to

 while ( ($a,$b,$c) = (@a, @b, @c) )
or
 for my ($el1, $el2)  (@foo, @bar)
 
is very easy to code in perl 5. At the risk of sounding reactionary,
this doesn't seem like a Big Win for perl.

 --
 Eric J. Roode[EMAIL PROTECTED]
 Senior Software Engineer, Myxa Corporation



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Sterin, Ilya

It's really not an improvement, but rather a comment, since if aliases and
iterations for numerous arrays were implemented, they would of course have
to somehow behave with hashes, so this would be a bahavior that could be
implemented.

Ilya

-Original Message-
From: Mark J. Reed
To: '[EMAIL PROTECTED] '
Sent: 07/20/2001 11:21 AM
Subject: Re: array/hash manipulation [was :what's with 'with'?]

On Fri, Jul 20, 2001 at 11:17:13AM -0600, Sterin, Ilya wrote:
> But this will be flattened, so I would think
> 
> for my($key, $val)(%my_hash)
> { ... }
> 
> Would be a great convenience.  $key and $val being aliased
accordingly.
I'm sorry, but I fail to see how this is a big improvement over the
current version:

while (my ($key, $val) = each %my_hash)
{ ... }

-- 
Mark J. REED<[EMAIL PROTECTED]>



Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Eric Roode

on Fri Jul 20, Mark REED wrote:
>I'm sorry, but I fail to see how this is a big improvement over the
>current version:
>
>while (my ($key, $val) = each %my_hash)
>{ ... }

And a workalike to

 while ( ($a,$b,$c) = (@a, @b, @c) )
or
 for my ($el1, $el2)  (@foo, @bar)
 
is very easy to code in perl 5. At the risk of sounding reactionary,
this doesn't seem like a Big Win for perl.

 --
 Eric J. Roode[EMAIL PROTECTED]
 Senior Software Engineer, Myxa Corporation




Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Mark J. Reed

Well, other than the fact that the while(each) doesn't do aliasing. 
Since that would be the whole point, ignore that last message.

On Fri, Jul 20, 2001 at 01:21:57PM -0400, Mark J. Reed wrote:
> On Fri, Jul 20, 2001 at 11:17:13AM -0600, Sterin, Ilya wrote:
> > But this will be flattened, so I would think
> > 
> > for my($key, $val)(%my_hash)
> > { ... }
> > 
> > Would be a great convenience.  $key and $val being aliased accordingly.
> I'm sorry, but I fail to see how this is a big improvement over the
> current version:
> 
> while (my ($key, $val) = each %my_hash)
> { ... }
> 
> -- 
> Mark J. REED  <[EMAIL PROTECTED]>

-- 
Mark J. REED<[EMAIL PROTECTED]>



Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread raptor

ooops I forgot if the vars in for are aliesed then it will be ok for using
it like 'with' :

for my $el ( $Request->{Param} ) {
  print $el{qsParam1}
  print $el{qsParam2}

}

but then what will be $_ ... alias OR copy !?! :") I mean mostly backward
compatibility...
One other way is 'local' to make copy & 'my' alias in this particular case
?!?!?! I can't remember the current-descision about 'local'
Say :
for my $el , local $el2 (@a1, @a2) {
   print $_; #alias
   print local $_;#copy
};


Dusk till down :")
=
iVAN
[EMAIL PROTECTED]
=




Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Mark J. Reed

On Fri, Jul 20, 2001 at 11:17:13AM -0600, Sterin, Ilya wrote:
> But this will be flattened, so I would think
> 
> for my($key, $val)(%my_hash)
> { ... }
> 
> Would be a great convenience.  $key and $val being aliased accordingly.
I'm sorry, but I fail to see how this is a big improvement over the
current version:

while (my ($key, $val) = each %my_hash)
{ ... }

-- 
Mark J. REED<[EMAIL PROTECTED]>



RE: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Sterin, Ilya

My only concern is with hashes, since they come in no particular order
unless sorted, there probably would not be any use to iterate over the
values of more than one hash?  At least I can't think of any use.  But it
would be nice to iterate over one hash, like so...

for (%my_hash)
{ ... }

But this will be flattened, so I would think

for my($key, $val)(%my_hash)
{ ... }

Would be a great convenience.  $key and $val being aliased accordingly.

Ilya


-Original Message-
From: raptor
To: Sterin, Ilya; [EMAIL PROTECTED]
Sent: 07/20/2001 9:10 AM
Subject: Re: array/hash manipulation [was :what's with 'with'?]

> Hmmm. Didn't think about that.  That would be a nice way, that way you
can
> manipulate it's behaviour depending with how many aliases you provide.
>
> for my $el1, $el2 ( (@foo, @bar) ) {
> print "$el\n"
>  }
>
> $el1 and $el2 would of course be aliases, right?

]- yes ALIASING will be better, instead of copyng values into $el,$el2
scalars just one point I placed around them "(" ")", so that the
arrays
would be flattened :") ... but now as u told it will be beter they to be
aliases.. so may be this is the right one :

for my ($e1,$2,e3...,$eX) ( @a1, @a2, @a3, .. @aX) {
 .blah...
}

and later on the first iteration $el's are aliased to the zero elements
of
arrays (if the $el's are more than @a's then the latest  $el's are not
aliased/probably undef'ed/, if @a's are more then all $el's are occuped
and
on the next iteration they doesn't start to be aliesed again from the
@a1
but from the next @a's !!).
If we have Scalars  in the list, then they behave as array with one
element
(just got aliesed every time).
If we have Hashes then VALUES get aliased... if someone wants keys it
should
write explictly keys %hash (temporarily has to be created scalars may
be),
the same with each.

just one possible solution.. may be there is many things i've not seen..

And then what about this :")

for my ( $e1, @els,$el3) ( @a1, 5..10, @a2,%h1, $x .. @aX) {
 .blah...
};

:"))) There is endless ways to do it : TIEWTDI
=
iVAN
[EMAIL PROTECTED]
=




Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread raptor

> Hmmm. Didn't think about that.  That would be a nice way, that way you can
> manipulate it's behaviour depending with how many aliases you provide.
>
> for my $el1, $el2 ( (@foo, @bar) ) {
> print "$el\n"
>  }
>
> $el1 and $el2 would of course be aliases, right?

]- yes ALIASING will be better, instead of copyng values into $el,$el2
scalars just one point I placed around them "(" ")", so that the arrays
would be flattened :") ... but now as u told it will be beter they to be
aliases.. so may be this is the right one :

for my ($e1,$2,e3...,$eX) ( @a1, @a2, @a3, .. @aX) {
 .blah...
}

and later on the first iteration $el's are aliased to the zero elements of
arrays (if the $el's are more than @a's then the latest  $el's are not
aliased/probably undef'ed/, if @a's are more then all $el's are occuped and
on the next iteration they doesn't start to be aliesed again from the @a1
but from the next @a's !!).
If we have Scalars  in the list, then they behave as array with one element
(just got aliesed every time).
If we have Hashes then VALUES get aliased... if someone wants keys it should
write explictly keys %hash (temporarily has to be created scalars may be),
the same with each.

just one possible solution.. may be there is many things i've not seen..

And then what about this :")

for my ( $e1, @els,$el3) ( @a1, 5..10, @a2,%h1, $x .. @aX) {
 .blah...
};

:"))) There is endless ways to do it : TIEWTDI
=
iVAN
[EMAIL PROTECTED]
=





RE: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Sterin, Ilya

Hmmm. Didn't think about that.  That would be a nice way, that way you can
manipulate it's behaviour depending with how many aliases you provide.  

for my $el1, $el2 ( (@foo, @bar) ) {
print "$el\n"
 }

$el1 and $el2 would of course be aliases, right?

But one though might be, what happens if this is written...

for my $el1, $el2 ( (@foo, @bar, @arr) ) {
print "$el\n"
 }

Does this bahave in the same way as the first one, but we just don't set
@arr elements, since the user forgot to provide a third alias, or should
this croak at compile time?

Ilya


-Original Message-
From: raptor
To: [EMAIL PROTECTED]
Sent: 07/20/2001 3:37 AM
Subject: Re: array/hash manipulation [was :what's with 'with'?]



> So my initial code (which I modified a little...)
>
> for ( @foo, @bar ) {
>   print "$_[0] : $_[1]\n";
> }
>
> for would set each element of the @_ array to correspond to the
arguments
in
> for() , therfore $_[0] will equal to the current element of @foo and
$_[1]
> will equal to the corresponding element of @bar.  As I mentioned
before
this
> can very easily be accomplished through 0..$#foo loop, but people
disagreed
> based on that it would be a nice option, in my opinion it's useless,
but
if
> was implemented this could be a way:)

]- Yes ... and one more option :

 for my $el1, $el2 ( @foo, @bar ) {
print "$el1 : $el2\n"
 }

$el1 will get values from @foo and $el2 from @bar, but the following :

 for my $el ( @foo, @bar ) {
print "$el\n"
 }

will print :
$foo[0]
$bar[0]
$foo[1]
$bar[1]

if people like the other way they can write :

 for my $el ( (@foo, @bar) ) {
print "$el\n"
 }

will print :
$foo[0]
$foo[1]
...$foo[x]
$bar[0]
$bar[1]


is this correct , but now I'm looking at these too...
http://dev.perl.org/rfc/90.pod
http://dev.perl.org/rfc/91.pod
http://dev.perl.org/rfc/148.pod

so may be what must be the order of passing the arguments and other
stuff
should be done via these proposed functions.

PS. I was thinking of that before, what if we have something let's call
it
'transform' for transformation of any structure to other structure.. but
as
i thought it should combine in some way the features of
switch,if-else,for/foeach, do, while, array/hash-slices, assignment
etc  ps I'm talking about DWIM operator. anyway...
is it
possible to really add such "dwim" function/operator that can be
modified on
the fly so that it suit all programmers tastes and don't make real
mess...")
... ok i say it :")))
=
iVAN
[EMAIL PROTECTED]
=



Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread Jeremy Howard

"raptor" <[EMAIL PROTECTED]> wrote:
> but now I'm looking at these too...
> http://dev.perl.org/rfc/90.pod
> http://dev.perl.org/rfc/91.pod
> http://dev.perl.org/rfc/148.pod
>
> so may be what must be the order of passing the arguments and other stuff
> should be done via these proposed functions.
>
> PS. I was thinking of that before, what if we have something let's call it
> 'transform' for transformation of any structure to other structure.. but
as
> i thought it should combine in some way the features of
> switch,if-else,for/foeach, do, while, array/hash-slices, assignment
> etc  ps I'm talking about DWIM operator. anyway... is
it
> possible to really add such "dwim" function/operator that can be modified
on
> the fly so that it suit all programmers tastes and don't make real
mess...")

The generalised version of these is here:
  http://dev.perl.org/rfc/81.html

In particular, see this section:
  http://dev.perl.org/rfc/81.html#JUSTIFICATION

This RFC suggests a syntax for list comprehension, which when used as a
slice index provides flexible data structure transformation.

Another useful transformation is provided by the cartesian product operator
described here:
  http://dev.perl.org/rfc/205.html

HTH,
  Jeremy





Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread John Porter

raptor wrote:
> 
>  for my $el1, $el2 ( @foo, @bar ) {

Hopefully you mean

   for my $el1, my $el2 ( @foo, @bar ) {

or maybe 

   for [ my $el1, my $el2 ] ( @foo, @bar ) {

And yes, it's an old idea.


> PS. I was thinking of that before, what if we have something let's call it
> 'transform' for transformation of any structure to other structure.. 

This sort of thing should certainly not be in the kernel.

-- 
John Porter




Re: array/hash manipulation [was :what's with 'with'?]

2001-07-20 Thread raptor



> So my initial code (which I modified a little...)
>
> for ( @foo, @bar ) {
>   print "$_[0] : $_[1]\n";
> }
>
> for would set each element of the @_ array to correspond to the arguments
in
> for() , therfore $_[0] will equal to the current element of @foo and $_[1]
> will equal to the corresponding element of @bar.  As I mentioned before
this
> can very easily be accomplished through 0..$#foo loop, but people
disagreed
> based on that it would be a nice option, in my opinion it's useless, but
if
> was implemented this could be a way:)

]- Yes ... and one more option :

 for my $el1, $el2 ( @foo, @bar ) {
print "$el1 : $el2\n"
 }

$el1 will get values from @foo and $el2 from @bar, but the following :

 for my $el ( @foo, @bar ) {
print "$el\n"
 }

will print :
$foo[0]
$bar[0]
$foo[1]
$bar[1]

if people like the other way they can write :

 for my $el ( (@foo, @bar) ) {
print "$el\n"
 }

will print :
$foo[0]
$foo[1]
...$foo[x]
$bar[0]
$bar[1]


is this correct , but now I'm looking at these too...
http://dev.perl.org/rfc/90.pod
http://dev.perl.org/rfc/91.pod
http://dev.perl.org/rfc/148.pod

so may be what must be the order of passing the arguments and other stuff
should be done via these proposed functions.

PS. I was thinking of that before, what if we have something let's call it
'transform' for transformation of any structure to other structure.. but as
i thought it should combine in some way the features of
switch,if-else,for/foeach, do, while, array/hash-slices, assignment
etc  ps I'm talking about DWIM operator. anyway... is it
possible to really add such "dwim" function/operator that can be modified on
the fly so that it suit all programmers tastes and don't make real mess...")
... ok i say it :")))
=
iVAN
[EMAIL PROTECTED]
=