Re: [nice2haveit]: transpose function

2001-07-25 Thread Jeremy Howard

David L. Nicol [EMAIL PROTECTED] wrote:
 Yes, exactly.  I would like to have a transpose operator, which
 will work on a list of hash refs, so this:
 
 $solids = [1..7];
 $stripes = [9..15];
 foreach (transpose($solids,$stripes));
 print the $_-[0] ball is the same color as the $_-[1]\n;

RFC 272 proposes a transpose function:
  http://dev.perl.org/rfc/272.html

Also see the proposal for merge():
  http://dev.perl.org/rfc/90.html





Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-20 Thread 'John Porter '

David L. Nicol wrote:
 No, that does not work:

Right; I misunderstood what was wanted.

-- 
John Porter




RE: aliasing - was:[nice2haveit]

2001-07-19 Thread Sterin, Ilya

Stuart Rocks wrote:
 
  CWith would also make the [variable, alias, whatever]
 default, but not replace the $_:
 
 $_ = monkey ;
 $foo = coward;
 with ($foo){
 print;
 print $_;
 }
 
 would output monkey coward. 

okay, coward is default but $_ has not been replaced, so would not 
the code example print coward monkey

Then how would you write I am not a coward

with ($foo)
{
  print I am not a;  ##What do I use here or do I have to issue a 
   ##separate print like...
  print;
}

Ilya




Re: aliasing - was:[nice2haveit]

2001-07-19 Thread Stuart Rocks

 Then how would you write I am not a coward

 with ($foo)
 {
   print I am not a;  ##What do I use here or do I have to issue a
##separate print like...
   print;
 }

 Ilya

Well in Perl5, for the print to use default value it's just 'print;'. The
same applies for alot (all?) of Perl5 functions. The default value is always
(as far as I know) $_ or @_ depending on the context.

Both the following would work:

with($foo){
   print I am not a $foo\n;
  # or:
   print I am not a ;
   print;
}

The idea for this style of CWith, came because I don't see why the default
has to always be $_. Often the amount of code required would be able to be
dramatically reduced if 'default value'  was userdefinable for blocks with
the With command.


(All opinions in this post are not representative of Monkey Coward)





what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Garrett Goebel

From: Stuart Rocks [mailto:[EMAIL PROTECTED]]
 
 Both the following would work:
 
 with($foo){
print I am not a $foo\n;
   # or:
print I am not a ;
print;
 }

Okay... I've been mostly ignoring this thread. But can someone reiterate the
difference between the above and

for($foo){
   print I am not a $foo\n;
  # or:
   print I am not a ;
   print;
}

???



Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Mark Koopman



Garrett Goebel wrote:

 From: Stuart Rocks [mailto:[EMAIL PROTECTED]]
 
Both the following would work:

with($foo){
   print I am not a $foo\n;
  # or:
   print I am not a ;
   print;
}

 
 Okay... I've been mostly ignoring this thread. But can someone reiterate the
 difference between the above and
 
 for($foo){
print I am not a $foo\n;
   # or:
print I am not a ;
print;
 }
 
 ???
 
 


pure syntax.  does anyone else question making aliases like 'with' from 'for'?
a 'with' alias could open the door on purely confusing code like this:

with( my $i; $i  10; $i++ ){  ... }

instead of having an standard 'with' that only works on objects like this:

with( MyObject-new() ) {
  .setIt(blah);
  ...
}





-- 
   -mark koopman

  WebSideStory  10182  Telesis Court
  San Diego CA  92121  858-546-1182 ext 318




RE: aliasing - was:[nice2haveit]

2001-07-19 Thread Sterin, Ilya

But I thought this was related to more than just with(), so if we have

foreach (1..10)
{
print;  

### But if you are trying to use it in a string

print This is number $_ of 10\n;

### Would now have to be printed as

print This is number ;
print;
print  of 10\n;

### Which is three extra statement.  

}

I still believe that although not defining a variable source will use the
temp variable there is still a need for an explicit scalar like $_.
Unless there is something I am missing from this discussion.

Ilya

-Original Message-
From: Stuart Rocks
To: [EMAIL PROTECTED]
Sent: 07/19/2001 11:31 AM
Subject: Re: aliasing - was:[nice2haveit]

 Then how would you write I am not a coward

 with ($foo)
 {
   print I am not a;  ##What do I use here or do I have to issue a
##separate print like...
   print;
 }

 Ilya

Well in Perl5, for the print to use default value it's just 'print;'.
The
same applies for alot (all?) of Perl5 functions. The default value is
always
(as far as I know) $_ or @_ depending on the context.

Both the following would work:

with($foo){
   print I am not a $foo\n;
  # or:
   print I am not a ;
   print;
}

The idea for this style of CWith, came because I don't see why the
default
has to always be $_. Often the amount of code required would be able to
be
dramatically reduced if 'default value'  was userdefinable for blocks
with
the With command.


(All opinions in this post are not representative of Monkey Coward)




RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Sterin, Ilya

Well if you look at the proposed...

$_ = monkey ; 
 $foo = coward; 
 with ($foo){ 
 print; 
 print $_; 
}

Would print coward monkey, which will give you unexpected results if you
are used to having the same output for both, coward coward.
But I guess the above would not replace $_ which would be very inconvenient
if you had to output it with a whole bunch of other stuff.  Like I am not a
coward which can be easily done with print I am not a $_; will now have
to be written in two separate lines, and possibly more if there is more to
follow.

Ilya

-Original Message-
From: Garrett Goebel
To: 'Stuart Rocks'; [EMAIL PROTECTED]
Sent: 07/19/2001 12:34 PM
Subject: what's with 'with'?  (was: [aliasing - was:[nice2haveit]])

From: Stuart Rocks [mailto:[EMAIL PROTECTED]]
 
 Both the following would work:
 
 with($foo){
print I am not a $foo\n;
   # or:
print I am not a ;
print;
 }

Okay... I've been mostly ignoring this thread. But can someone reiterate
the
difference between the above and

for($foo){
   print I am not a $foo\n;
  # or:
   print I am not a ;
   print;
}

???



RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Sterin, Ilya

I question this too, since as you mentioned with, in my experience works
nicely to reference and object like
with(object)
{
.foo();
.bar();

}

Ilya

-Original Message-
From: Mark Koopman
To: [EMAIL PROTECTED]
Sent: 07/19/2001 12:42 PM
Subject: Re: what's with 'with'?  (was: [aliasing - was:[nice2haveit]])



Garrett Goebel wrote:

 From: Stuart Rocks [mailto:[EMAIL PROTECTED]]
 
Both the following would work:

with($foo){
   print I am not a $foo\n;
  # or:
   print I am not a ;
   print;
}

 
 Okay... I've been mostly ignoring this thread. But can someone
reiterate the
 difference between the above and
 
 for($foo){
print I am not a $foo\n;
   # or:
print I am not a ;
print;
 }
 
 ???
 
 


pure syntax.  does anyone else question making aliases like 'with' from
'for'?
a 'with' alias could open the door on purely confusing code like this:

with( my $i; $i  10; $i++ ){  ... }

instead of having an standard 'with' that only works on objects like
this:

with( MyObject-new() ) {
  .setIt(blah);
  ...
}





-- 
   -mark koopman

  WebSideStory  10182  Telesis Court
  San Diego CA  92121  858-546-1182 ext 318



Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread John Porter

I believe what is really wanted is for for to be able to iterate
over lists of arrays or hashes:

for my @i ( @foo, @bar ) { ...

for my %i ( %foo, %bar ) { ...

with real aliasing occuring.

If @_ and %_ are the default iterator variables, then imagine:

for ( @argset1, @argset2 ) {
quux;

But I'm not convinced of the utility of this over using
scalar references.

-- 
John Porter




Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Stuart Rocks

 Like I am not a
 coward which can be easily done with print I am not a $_; will now have
 to be written in two separate lines, and possibly more if there is more to
 follow.

 Ilya

Um, of course the original way is still possible!





Re: aliasing - was:[nice2haveit]

2001-07-19 Thread John Porter

Sterin, Ilya wrote:
 But I thought this was related to more than just with(), so if we have
 
 ### Would now have to be printed as
 
 print This is number ;
 print;
 print  of 10\n;
 
 I still believe that although not defining a variable source will use the
 temp variable there is still a need for an explicit scalar like $_.
 Unless there is something I am missing from this discussion.

No.  with() must be consistent with other perl constructs.
If implemented, it will use $_.  Plain and simple.

-- 
John Porter




RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Sterin, Ilya

Well then maybe $_ can be a reference to a multidimensional array or hash,
and temp vars can be access like this.

for ( @foo, @bar ) {
print $_-[0] : $_-[1]\n;
}

As for hashes it might hold the key, also in an multidimensional array.

Ilya

-Original Message-
From: John Porter
To: [EMAIL PROTECTED]
Sent: 07/19/2001 12:59 PM
Subject: Re: what's with 'with'?  (was: [aliasing - was:[nice2haveit]])

I believe what is really wanted is for for to be able to iterate
over lists of arrays or hashes:

for my @i ( @foo, @bar ) { ...

for my %i ( %foo, %bar ) { ...

with real aliasing occuring.

If @_ and %_ are the default iterator variables, then imagine:

for ( @argset1, @argset2 ) {
quux;

But I'm not convinced of the utility of this over using
scalar references.

-- 
John Porter



RE: aliasing - was:[nice2haveit]

2001-07-19 Thread Sterin, Ilya

Agree.  I think that with() should only be used with object references only,
and $_ should be set accordingly.

Ilya 

-Original Message-
From: John Porter
To: [EMAIL PROTECTED]
Sent: 07/19/2001 1:01 PM
Subject: Re: aliasing - was:[nice2haveit]

Sterin, Ilya wrote:
 But I thought this was related to more than just with(), so if we have
 
 ### Would now have to be printed as
 
 print This is number ;
 print;
 print  of 10\n;
 
 I still believe that although not defining a variable source will use
the
 temp variable there is still a need for an explicit scalar like $_.
 Unless there is something I am missing from this discussion.

No.  with() must be consistent with other perl constructs.
If implemented, it will use $_.  Plain and simple.

-- 
John Porter



Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Stuart Rocks

 But can someone reiterate the
 difference between the above and

 for($foo){
print I am not a $foo\n;
   # or:
print I am not a ;
print;
 }

Try this under the current for system, cause it's unclear what will happen
for those new to Perl:

  $foo=monkey;  $_= coward;
  for($foo){
print;
$_ =  hero;
  }
  print;

What is printed is monkey coward, rather than monkey hero. In addition,
$foo is now  hero.

I suppose there isn't a huge difference. Either way, all this talk has
probably taken longer than it would take to write the thing.





Re: aliasing - was:[nice2haveit]

2001-07-19 Thread John Porter

Bart Lateur wrote:
 So, in this case, a with synonym for for would work.
 
 But this only works for scalars. You can't have a %foo alias to
 %Some::Other::hash this way, or a @bar alias to @Some::Other::array.

Sounds like what we really want is a form of for which can iterate
over a list of hashes or arrays:

for my @a ( @foo, @bar ) { ...

for my %h ( %foo, %bar ) { ...

-- 
John Porter



RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Sterin, Ilya

Why would you want it to print Monkey Hero, I would expect $_ to be
localized, rather than global, which could prove more convenient.

Ilya

-Original Message-
From: Stuart Rocks
To: [EMAIL PROTECTED]
Sent: 07/19/2001 1:13 PM
Subject: Re: what's with 'with'?  (was: [aliasing - was:[nice2haveit]])

 But can someone reiterate the
 difference between the above and

 for($foo){
print I am not a $foo\n;
   # or:
print I am not a ;
print;
 }

Try this under the current for system, cause it's unclear what will
happen
for those new to Perl:

  $foo=monkey;  $_= coward;
  for($foo){
print;
$_ =  hero;
  }
  print;

What is printed is monkey coward, rather than monkey hero. In
addition,
$foo is now  hero.

I suppose there isn't a huge difference. Either way, all this talk has
probably taken longer than it would take to write the thing.




Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread 'John Porter '

Sterin, Ilya wrote:
 Well then maybe $_ can be a reference to a multidimensional array or hash,
 and temp vars can be access like this.
 
 for ( @foo, @bar ) {
   print $_-[0] : $_-[1]\n;
 }

That's bizarre and unnecessary.  We can already do this:

  for ( \@foo, \@bar ) {
print $_-[0] : $_-[1]\n;
  }

-- 
John Porter




RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Sterin, Ilya

@foo = (foo1, foo2);
@bar = (bar1, bar2);

 for ( \@foo, \@bar ) { 
print $_-[0] : $_-[1]\n; 
  } 

will output

foo1 : foo2
bar1 : bar2

I was thinking more of iterating through them at the same time, which would
sort of like compare them.  I believe this was the initial topic of this
thread (I believe, that was about two days ago, my mind might be going blank
though).

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:)

Ilya


-Original Message-
From: 'John Porter '
To: [EMAIL PROTECTED]
Sent: 07/19/2001 1:46 PM
Subject: Re: what's with 'with'?  (was: [aliasing - was:[nice2haveit]])

Sterin, Ilya wrote:
 Well then maybe $_ can be a reference to a multidimensional array or
hash,
 and temp vars can be access like this.
 
 for ( @foo, @bar ) {
   print $_-[0] : $_-[1]\n;
 }

That's bizarre and unnecessary.  We can already do this:

  for ( \@foo, \@bar ) {
print $_-[0] : $_-[1]\n;
  }

-- 
John Porter



Re: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

2001-07-19 Thread Stuart Rocks

 Why would you want it to print Monkey Hero, I would expect $_ to be
 localized, rather than global, which could prove more convenient.

No, it's still localized.

But the With would mean that $_ in a way becomes a normal variable like $foo
was, and the $foo is now the 'default variable'.





Re: aliasing - was:[nice2haveit]

2001-07-19 Thread Me

 Sounds like what we really want is a form of for which can iterate
 over a list of hashes or arrays:
 
 for my @a ( @foo, @bar ) { ...
 
 for my %h ( %foo, %bar ) { ...

Yes.

Isn't the underlying issue in the above how perl6 handles manipulation
and aliasing of multi-dimensional arrays into derived sub-structures?

In other words, isn't there a more general problem of how to provide
MD access and what to do with the currently one dimensional operations
like:

for (@foo) {

when @foo is multi-dimensional?

Jeremy Howard wrote RFCs that I think relate to this and pointed
me to J (APL cleaned up) as a powerful source of related ideas.
I think the specific issue above relates to a combination of
merge/unmerge and other proposed features.




Re: aliasing - was:[nice2haveit]

2001-07-18 Thread John Porter

Jeremy Howard wrote:
   with $XL-{Application}-{ActiveSheet} {
 -cells(1,1) = Title
 -language() = English
   }
 
 Does such a thing exist already?

A WTDI exists already:

for ( $XL-{Application}-{ActiveSheet} ) {
  $_-cells(1,1) = Title;
  $_-language() = English;
}

(presuming lvalue-methods, of course...)

-- 
John Porter




Re: aliasing - was:[nice2haveit]

2001-07-18 Thread Bart Lateur

On Wed, 18 Jul 2001 09:00:25 -0400, John Porter wrote:

 Does such a thing exist already?

A WTDI exists already:

for ( $XL-{Application}-{ActiveSheet} ) {
  $_-cells(1,1) = Title;
  $_-language() = English;
}

(presuming lvalue-methods, of course...)

So, in this case, a with synonym for for would work.

But this only works for scalars. You can't have a %foo alias to
%Some::Other::hash this way, or a @bar alias to @Some::Other::array.

-- 
Bart.



Re: aliasing - was:[nice2haveit]

2001-07-18 Thread jh_lists

Bart Lateur wrote:
 On Wed, 18 Jul 2001 09:00:25 -0400, John Porter wrote:
 for ( $XL-{Application}-{ActiveSheet} ) {
   $_-cells(1,1) = Title;
   $_-language() = English;
 }
 
 (presuming lvalue-methods, of course...)
 
 So, in this case, a with synonym for for would work.
 
Particularly if '$_' was implied... So with Perl 6's '.' replacing '-',
and 'with' aliasing 'for':

   with ( $XL.{Application}.{ActiveSheet} ) {
 .cells(1,1) = Title;
 .language() = English;
   }

Heh. That is nice and compact... although it's getting hard to tell it
apart from VB ;-)

-- 
  Jeremy Howard
  [EMAIL PROTECTED]



Re: aliasing - was:[nice2haveit]

2001-07-18 Thread raptor

 Does such a thing exist already?

A WTDI exists already:

for ( $XL-{Application}-{ActiveSheet} ) {
  $_-cells(1,1) = Title;
  $_-language() = English;
}

(presuming lvalue-methods, of course...)

So, in this case, a with synonym for for would work.

]- OR 

   with alias for;
   with ( $XL-{Application}-{ActiveSheet} ) {
  $_-cells(1,1) = Title;
  $_-language() = English;
}


:)

=
iVAN
[EMAIL PROTECTED]
=




one more nice2haveit

2001-07-18 Thread raptor

hi,

As I was programming i got again to one thing i alwas needed to have...
especialy when write something fast or debug some result... words comes
about for/foreach and accessing the current-index of the array I'm working
with  i.e.

say I have two arrays @a and @b and want to print them (also say they are
connected in some way so I want to see them both). In case of one array I
write :

print $_\n for @a;

fast, simple, goodbut in my case I have to write something like this :

for ($i = 0; $i  scalar @a; $i++) {
 print $a[$i] : $b[$i]\n
};

I've go tired of typing :), but if I had current index-iterator ( say under
$i just as example) at hand the way I have $_ i can just type :

print $_ : $b[$i]\n for @a;
OR
print $a[$i] : $b[$i]\n for @a;

isn't that cute :) ... the same count for list in $i I just get current
position in the list. (we can also use pos in some way!!!)

print $_ : $a[$i] : $b[$i]\n for (qw(val1 val2 val3));

I need it very often.:)
don't bother if the lenght of both arrays are different when u use it, u
know what u are doing...

=
iVAN
[EMAIL PROTECTED]
=






Re: aliasing - was:[nice2haveit]

2001-07-18 Thread Stuart Rocks

  So, in this case, a with synonym for for would work.
 
 Particularly if '$_' was implied... So with Perl 6's '.' replacing '-',
 and 'with' aliasing 'for':

with ( $XL.{Application}.{ActiveSheet} ) {
  .cells(1,1) = Title;
  .language() = English;
}

This is my idea for it; .zebra could always be the 'default variables'
attribute 'zebra'.  The With could also make the [variable, alias, whatever]
default, but not replace the $_:

$_ = monkey ;
$foo = coward;
with ($foo){
print;
print $_;
}

would output monkey coward. If this was univeral and heirachial, then

$foo.bar.quux = chainsaw;
with ($foo){
with (.bar){
print .quux;
}
}

I see a problem with . being the old way of sticking strings together
though.

(All opinions expressed in this post are probably wrong.)





Re: aliasing - was:[nice2haveit]

2001-07-18 Thread Stuart Rocks

  So, in this case, a with synonym for for would work.
 
 Particularly if '$_' was implied... So with Perl 6's '.' replacing '-',
 and 'with' aliasing 'for':

with ( $XL.{Application}.{ActiveSheet} ) {
  .cells(1,1) = Title;
  .language() = English;
}

This is my idea for it; .zebra could always be the 'default variables'
attribute 'zebra'.  The With could also make the [variable, alias, whatever]
default, but not replace the $_:

$_ = monkey ;
$foo = coward;
with ($foo){
print;
print $_;
}

would output monkey coward. If this was universal and heirachial, then

$foo.bar.quux = chainsaw;
with ($foo){
with (.bar){
print .quux;
}
}

Be cool if this could be overloaded (correct word?) to work for functions,
too.

with (print()){
foo;
monkey;
}

I see a problem with . being the old way of sticking strings together
though.

(All opinions expressed in this post are probably wrong. Trying to figure
how to post this thing, the newsgroup bit didn't work.)



RE: one more nice2haveit

2001-07-18 Thread Sterin, Ilya

How about 

print $a[$_]:$b[$_] for 0..$#a;

or in the p6 case...

print @a[$_]:@b[$_] for 0..$#a;

Ilya


-Original Message-
From: raptor
To: [EMAIL PROTECTED]
Sent: 07/18/2001 12:14 PM
Subject: one more nice2haveit

hi,

As I was programming i got again to one thing i alwas needed to have...
especialy when write something fast or debug some result... words comes
about for/foreach and accessing the current-index of the array I'm
working
with  i.e.

say I have two arrays @a and @b and want to print them (also say they
are
connected in some way so I want to see them both). In case of one array
I
write :

print $_\n for @a;

fast, simple, goodbut in my case I have to write something like this
:

for ($i = 0; $i  scalar @a; $i++) {
 print $a[$i] : $b[$i]\n
};

I've go tired of typing :), but if I had current index-iterator ( say
under
$i just as example) at hand the way I have $_ i can just type :

print $_ : $b[$i]\n for @a;
OR
print $a[$i] : $b[$i]\n for @a;

isn't that cute :) ... the same count for list in $i I just get current
position in the list. (we can also use pos in some way!!!)

print $_ : $a[$i] : $b[$i]\n for (qw(val1 val2 val3));

I need it very often.:)
don't bother if the lenght of both arrays are different when u use
it, u
know what u are doing...

=
iVAN
[EMAIL PROTECTED]
=





Re: one more nice2haveit

2001-07-18 Thread jh_lists

 I've go tired of typing :), but if I had current index-iterator ( say under
 $i just as example) at hand the way I have $_ i can just type :
 
 print $_ : $b[$i]\n for @a;
 OR
 print $a[$i] : $b[$i]\n for @a;
 
For a general solution to this see Buddha Buck's RFC on iterators:
  http://dev.perl.org/rfc/207.html

-- 
  Jeremy Howard
  [EMAIL PROTECTED]



Re: nice2haveit

2001-07-17 Thread Mark Morgan

Raptor [EMAIL PROTECTED] wrote:
 I mean something like this :

 instead of :
 #$Request-{Params}
 local *myhash = \%{$$Request{Params}};

 my %myhash alias %{$$Request{Params}};#see - it is my (now as far as I know
 u can't have it 'my')

You don't need a typeglob there; you can do the following, which does work
with 'my':

my %myhash = %{$Request-{Params}};

or 

my $hashref = $Request-{Params}; # neater, and I personally prefer
  # working with 
hashrefs

Less typing, and it's already in there. :)

Take care,
Mark.



Re: nice2haveit

2001-07-17 Thread Dan Sugalski

At 05:10 AM 7/17/2001 +, Mark Morgan wrote:
Raptor [EMAIL PROTECTED] wrote:
  I mean something like this :

  instead of :
  #$Request-{Params}
  local *myhash = \%{$$Request{Params}};

  my %myhash alias %{$$Request{Params}};#see - it is my (now as far as I know
  u can't have it 'my')

You don't need a typeglob there; you can do the following, which does work
with 'my':

my %myhash = %{$Request-{Params}};

Originally he wanted an alias, and that won't do it. You'll flatten and 
unflatten, and changes to %myhash won't be reflected in the original.

Dan

--it's like this---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
  teddy bears get drunk




Re: aliasing - was:[nice2haveit]

2001-07-17 Thread raptor

   I mean something like this :
 
   instead of :
   #$Request-{Params}
   local *myhash = \%{$$Request{Params}};
 
   my %myhash alias %{$$Request{Params}};#see - it is my (now as far as I
know
   u can't have it 'my')
 
 You don't need a typeglob there; you can do the following, which does
work
 with 'my':
 
 my %myhash = %{$Request-{Params}};

 Originally he wanted an alias, and that won't do it. You'll flatten and
 unflatten, and changes to %myhash won't be reflected in the original.

]- that's right ... and it is not very good if the HASH is big ... and what
to say if it is tied to DBM, even slower
the idea of aliasing is to preserve the fast access and on the other side to
shorden the accessor(i.e the way to access the structure) and make code
clearer.(mostly u can choose a name that has better meaning in your context)

Also if we talk about object methods it many times good to have many methods
do the same thing.. say (just examples, don't blame me just throwing what
comes in my mind):

get alias Obj::getAttribute
set alias Obj::setAttribute
setAttr alias Obj::setAttribute

oldObj::myOldBrokenMethod alias Obj::myBrandNewMethod ; #backward
compatibility

mypop alias pop;#core func aliasing

$flag alias
$My::Very::Hairy::Object::Which::Is::Very::Hard::To::Access::flag

:)
=
iVAN
[EMAIL PROTECTED]
=





Re: aliasing - was:[nice2haveit]

2001-07-17 Thread Jeremy Howard

raptor [EMAIL PROTECTED] wrote:
...
 the idea of aliasing is to preserve the fast access and on the other side
to
 shorden the accessor(i.e the way to access the structure) and make code
 clearer.(mostly u can choose a name that has better meaning in your
context)

This reminds me... another way to to shorten the accessor discussed in the
RFC process was something like Delphi  VB's 'with' syntax:
VB
  with Application.ActiveSheet
.cells(1,1) = Title
.language = English
  end with
  Application.ActiveSheet.cells(2,1) = Slow way
/VB

I can't remember if this actually found its way into an RFC--anyone have a
reference? I could envisage this prototyped in P5 with a source filter to
deal with a syntax like this:
Pseudo-Perl
  with $XL-{Application}-{ActiveSheet} {
-cells(1,1) = Title
-language() = English
  }
/Pseudo-Perl

Does such a thing exist already?





Re: nice2haveit

2001-07-16 Thread John Porter

Uri Guttman wrote:
 one related point is that this symbol table will be accessible via
 caller() so you could access/install lexical symbols in a parent block
 on the call stack. scary!

Quite.  Does anyone have a pointer to tchrist's rant on Tcl's upvar?

-- 
John Porter




Re: nice2haveit

2001-07-16 Thread Dan Sugalski

At 03:37 PM 7/16/2001 -0500, David L. Nicol wrote:
Uri Guttman wrote:

  one related point is that this symbol table will be accessible via
  caller() so you could access/install lexical symbols in a parent block
  on the call stack. scary!

We must demand that the feature come with a way to seal the current
context from manipulation, even possibly a way to block accesses.

Demand away, but you're not likely to get it.

Dan

--it's like this---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
  teddy bears get drunk




Re: nice2haveit

2001-07-16 Thread Paul Johnson

On Mon, Jul 16, 2001 at 03:37:41PM -0500, David L. Nicol wrote:
 Uri Guttman wrote:
 
  one related point is that this symbol table will be accessible via
  caller() so you could access/install lexical symbols in a parent block
  on the call stack. scary!
  
  uri
 
 We must demand that the feature come with a way to seal the current
 context from manipulation, even possibly a way to block accesses.

Doesn't sound very Perlish to me.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net



Re: nice2haveit

2001-07-14 Thread Bart Lateur

On Fri, 13 Jul 2001 20:55:07 +1000 (EST), Damian Conway wrote:

Would you like to clarify what you mean here.
Are you talking about typeglob assignments?
Perl 6 will have:

   $Foo::{'$bar'} = \$baz; # Alias $Foo::bar to $baz

Are we back to globals only? What about lexical aliases? Something
like:

my \%foo = \%bar;

(Now %foo is an alias to %bar.)

-- 
Bart.



Re: nice2haveit

2001-07-14 Thread Uri Guttman

 BL == Bart Lateur [EMAIL PROTECTED] writes:

  BL On Fri, 13 Jul 2001 20:55:07 +1000 (EST), Damian Conway wrote:
   Would you like to clarify what you mean here.
   Are you talking about typeglob assignments?
   Perl 6 will have:
   
   $Foo::{'$bar'} = \$baz;# Alias $Foo::bar to $baz

  BL Are we back to globals only? What about lexical aliases? Something
  BL like:

  BL   my \%foo = \%bar;

  BL (Now %foo is an alias to %bar.)

what damian has been showing as a possible/probably solution is a
lexical scoped symbol table called %MY::. it would be available inside
any block scope and allow you to alias things just like the above:

 $MY::{'$bar'} = \$baz; # Alias lexical $bar to $baz

now $bar is lexical and aliased to $baz

i like the concept but i worry about the overhead of setting up %MY. i
assume it will only be created if it is referred to in the block. there
may be other optimizations.

one related point is that this symbol table will be accessible via
caller() so you could access/install lexical symbols in a parent block
on the call stack. scary!

uri

-- 
Uri Guttman  -  [EMAIL PROTECTED]  --  http://www.sysarch.com
SYStems ARCHitecture and Stem Development -- http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html



Re: nice2haveit

2001-07-14 Thread Brent Royal-Gordon

  $Foo::{'$bar'} = \$baz; # Alias $Foo::bar to $baz
 
 Are we back to globals only? What about lexical aliases? Something
 like:
 
   my \%foo = \%bar;

I've always wondered why the backslash operator wasn't lvaluable.  (IIRC, C++'s  
operator is semi-lvaluable.)  IM(V)HO this is a good idea--it certainly makes more 
sense than $Foo::{'$bar'} = \$baz.  Or wait, was that supposed to be %Foo::{'$bar'}?  
:^) )
-- 

___
Get your free email from http://webmail.earthlink.net




nice2haveit

2001-07-13 Thread raptor

hi,

Two things i think is good to have it :

1. ALIAS keyword.
 - first reason is 'cause many people don't know that this is possible.. at
least any newscommer and it will help not to forgot that it exist :).
 - Code become more readable.
 - can be Overloaded
 - the syntax for aliasing can become reicher :)

2. Hash-reg-ex-slice

%hash{/\d*/}
instead of :
grep {/\d*/} keys %hash

%hash{/\d*/} = ();
%hash{/\d*/} = @list;# pump the @list values into %hash values (keys stay
the same)

- espesialy usefull with DBM

3. For this I'm not totaly sure, but it comes to my mind many modules
uses notation like this to pass params i.e.

someFunc ( -param1 = 'blah', param2 = 'xxx' .)

Why not have %_ in our case we have the following elements :

%_{'-param1'} = 'blah'
%_{'param2'} = 'xxx'

If in object/class contrext (can this be checked in some way) first element
goes to :

%_{self}

note : all references goes directly i.e. :  my %_ = map { $_ unless ref }
@_;
Also there is no need the HASH to be generated until we use it for the first
time, for speedup !?! is this possible.
I think if it is not hard for implementation it is nice shortcut.

 =
iVAN
[EMAIL PROTECTED]
=





Re: nice2haveit

2001-07-13 Thread Damian Conway

Two things i think is good to have it :

1. ALIAS keyword.
 - first reason is 'cause many people don't know that this is possible.. at
least any newscommer and it will help not to forgot that it exist :).
 - Code become more readable.
 - can be Overloaded
 - the syntax for aliasing can become reicher :)

Would you like to clarify what you mean here.
Are you talking about typeglob assignments?
Perl 6 will have:

$Foo::{'$bar'} = \$baz; # Alias $Foo::bar to $baz


3. For this I'm not totaly sure, but it comes to my mind many modules
uses notation like this to pass params i.e.

someFunc ( -param1 = 'blah', param2 = 'xxx' .)

Why not have %_ in our case we have the following elements :

http://dev.perl.org/rfc/128.html#Named_arguments

Damian



Re: nice2haveit

2001-07-13 Thread raptor

 Two things i think is good to have it :

 1. ALIAS keyword.
  - first reason is 'cause many people don't know that this is
possible.. at
 least any newscommer and it will help not to forgot that it exist
:).
  - Code become more readable.
  - can be Overloaded
  - the syntax for aliasing can become reicher :)

 Would you like to clarify what you mean here.
 Are you talking about typeglob assignments?
 Perl 6 will have:

 $Foo::{'$bar'} = \$baz; # Alias $Foo::bar to $baz
]-  Can I see more examples of typeglob assignment somewhere ? link ?

I mean something like this :

instead of :
#$Request-{Params}
local *myhash = \%{$$Request{Params}};

my %myhash alias %{$$Request{Params}};#see - it is my (now as far as I know
u can't have it 'my')

=
iVAN
[EMAIL PROTECTED]
=








RE: nice2haveit

2001-07-13 Thread Sterin, Ilya

 

-Original Message-
From: raptor
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: 7/13/01 10:19 AM
Subject: Re: nice2haveit

 Two things i think is good to have it :

 1. ALIAS keyword.
  - first reason is 'cause many people don't know that this is
possible.. at
 least any newscommer and it will help not to forgot that it exist
:).
  - Code become more readable.
  - can be Overloaded
  - the syntax for aliasing can become reicher :)

 Would you like to clarify what you mean here.
 Are you talking about typeglob assignments?
 Perl 6 will have:

 $Foo::{'$bar'} = \$baz; # Alias $Foo::bar to $baz
]-  Can I see more examples of typeglob assignment somewhere ? link ?

I mean something like this :

instead of :
#$Request-{Params}
local *myhash = \%{$$Request{Params}};

Wouldn't that do the same as 

my $myhash = ($request{Params});

I know that is actually copying value, but I believe the above does too?

Ilya


my %myhash alias %{$$Request{Params}};#see - it is my (now as far as I
know
u can't have it 'my')

=
iVAN
[EMAIL PROTECTED]
=







Re: nice2haveit

2001-07-13 Thread Dan Sugalski

At 09:24 PM 7/13/2001 +0300, raptor wrote:
in the case of :
  local *myhash = \%{$Request-{Params}};
u do this :

print $myhash{abc};

so it is first clearer and second I hope much faster 

Clearer maybe, faster probably not appreciably.

Regardless, the lexical 'symbol table' will be available to perl programs. 
How is up in the air, but I've heard proposals that the virtual package MY 
will refer to it.

We'll see, once Larry formalizes (or squashes) the idea.

Dan

--it's like this---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
  teddy bears get drunk




RE: nice2haveit

2001-07-13 Thread Sterin, Ilya

Yes but can't the same be accomplished with...

my $myhash = (%{$Request-{Params}});
print $myhash{abc};

Though again it copies the structure, I don't see how dereferencing can be
unclear?

Ilya

-Original Message-
From: raptor
To: [EMAIL PROTECTED]; Sterin, Ilya
Sent: 7/13/01 12:24 PM
Subject: Re: nice2haveit

the structure is something like this :

$Request = { 
Params =   { 
 abc = 1, 
 ddd = 2 
}
}

the idea is that U don't dereference i.e. :

 my $myhash = ($Request-{Params});   
if u want to use it U have to do this :

print $$myhash{abc}; #or if u preffer  print $myhash-{abc}

in the case of :
 local *myhash = \%{$Request-{Params}};
u do this :

print $myhash{abc};

so it is first clearer and second I hope much faster 

=
iVAN
[EMAIL PROTECTED]
=



Re: nice2haveit

2001-07-13 Thread raptor

 Yes but can't the same be accomplished with...

 my $myhash = (%{$Request-{Params}});
 print $myhash{abc};

 Though again it copies the structure, I don't see how dereferencing can be
 unclear?

]- if u have someting like this anything u can remove in some way is worth
it:))

$tables{$$self{rel}{$k}{table}}[0][VALS]
or this :
$$params{$$self{rel}{$k}{names}[$t].$j}

especialy if U have a couple of this :) in 3-4 rows of code...

=
iVAN
[EMAIL PROTECTED]
=