Re: junctions as indicies

2005-04-18 Thread Luke Palmer
David Christensen writes:
 I'm looking in S09, and reading about junctions.  It seems to me that 
 if we have a junction $j which we use to index into an array or a hash, 
 it should DWIM and return a junction of the corresponding values.
 
 @ar=[1..10];
 %hash=(a=1,b=4,c=7);
 
 $j=1|2|3;
 $k=a|c;
 
 $u = @ar[$j];   # 2|3|4
 $v = %hash{$k}; # 1|7
 
 Does this make sense to others?

Well, if we replaced @ar[$j] with, say,  @ar.get($j), what you're
proposing happens automatically.  So I think that it's the right thing
to do.

Luke


Re: junctions as indicies

2005-04-18 Thread Paul Hodges

--- David Christensen [EMAIL PROTECTED] wrote:
 I'm looking in S09, and reading about junctions.  It seems to me
 that if we have a junction $j which we use to index into an array
 or a hash, it should DWIM and return a junction of the corresponding
 values.
 
 @ar=[1..10];
 %hash=(a=1,b=4,c=7);
 
 $j=1|2|3;
 $k=a|c;
 
 $u = @ar[$j];   # 2|3|4
 $v = %hash{$k}; # 1|7
 
 Does this make sense to others?
 
 David

Maybe, but I don't like returning junctures in those cases unless you
*explicitly* ask for it. I'd rather the default be the arbitrary lists
returned, or whatever fits the context. How about

 @ar=[a..z];
 %hash=(a=1,b=4,c=7);

 $j=1|2|3;
 $k=a|c;

 @u  = @ar[$j];# (b..d)
 %u  = @ar[$j].kv; # (1='b',2='c',3='d')
 $u  = @ar[$j];# \(b..d)
 $ju = juncture @ar[$j];   # 'b'|'c'|'d'

 @v  = %hash{$k};  # (1,7)
 %v  = %hash{$k}.kv;   # (a=1,c=7) 
 $v  = %hash{$k};  # \(1,7)
 $jv = juncture %hash{$k}; # 1|7

Am I way off base here?

 



__ 
Do you Yahoo!? 
Plan great trips with Yahoo! Travel: Now over 17,000 guides!
http://travel.yahoo.com/p-travelguide


Re: junctions as indicies

2005-04-18 Thread Luke Palmer
Paul Hodges writes:
 Maybe, but I don't like returning junctures in those cases unless you
 *explicitly* ask for it. I'd rather the default be the arbitrary lists
 returned, or whatever fits the context. How about
 
  @ar=[a..z];
  %hash=(a=1,b=4,c=7);
 
  $j=1|2|3;

   @j = (1,2,3);

  $k=a|c;

   @k = a c;

  @u  = @ar[$j];# (b..d)

   @u  = @[EMAIL PROTECTED];

etc.

Perl can indeed slice using ordinary lists.  Another problem with using
junctions for this is that they're unordered, and you're expecting
ordered results back.

Luke


Re: junctions as indicies

2005-04-18 Thread Rod Adams
Paul Hodges wrote:
--- David Christensen [EMAIL PROTECTED] wrote:
 

I'm looking in S09, and reading about junctions.  It seems to me
that if we have a junction $j which we use to index into an array
or a hash, it should DWIM and return a junction of the corresponding
values.
@ar=[1..10];
%hash=(a=1,b=4,c=7);
$j=1|2|3;
$k=a|c;
$u = @ar[$j];   # 2|3|4
$v = %hash{$k}; # 1|7
Does this make sense to others?
David
   

Maybe, but I don't like returning junctures in those cases unless you
*explicitly* ask for it. I'd rather the default be the arbitrary lists
returned, or whatever fits the context. How about
@ar=[a..z];
%hash=(a=1,b=4,c=7);
$j=1|2|3;
$k=a|c;
@u  = @ar[$j];# (b..d)
%u  = @ar[$j].kv; # (1='b',2='c',3='d')
$u  = @ar[$j];# \(b..d)
$ju = juncture @ar[$j];   # 'b'|'c'|'d'
@v  = %hash{$k};  # (1,7)
%v  = %hash{$k}.kv;   # (a=1,c=7) 
$v  = %hash{$k};  # \(1,7)
$jv = juncture %hash{$k}; # 1|7

Am I way off base here?
 

What would you propose
   @v[all(any(4,5),one(1,2,3),none(7,8,9))]
return?
-- Rod Adams