Re: %_ - is it available for use?

2003-08-14 Thread Rafael Garcia-Suarez
david nicol wrote:
 [EMAIL PROTECTED] perl -le '$_{a}=27; package notmain; print $_{a}'
 27
 
 Gosh!
 
 Let's document it!  Would it go in perlvar or perlsyn?

It's already documented, in perlvar/Technical Note on the Syntax of Variable Names
(at the end)


Re: %_ - is it available for use?

2003-08-06 Thread Michael S. Joyce
Odd. I always though that you could do that. Maybe it was just an
assumption I made without understanding. I've used %_ in one liners to
remove duplicates and other such fun.

Michael

On Tue, 2003-08-05 at 21:36, david nicol wrote:
 On Sat, 2003-08-02 at 18:33, Michael G Schwern wrote:
 
  Representing the Backwards Compatiblity Police, I've had co-workers use
  %_ as the globalist of all global hashes.  %_ transends all packages and
  scopes and Perl does not localize it, touch it or use it as it does @_ and 
  $_.  In the particular case I'm thinking of, it was used to hold global
  arguments for function calls in a template system.  Rather insane, really.
  Lots of better ways to do it and clearly making use of an undefined
  language feature.
  
  I'm not making an argument against %_, just noting that *_ is used 
  opportunisticly and you will break a few programs.
 
 
 [EMAIL PROTECTED] perl -le '$_{a}=27; package notmain; print $_{a}'
 27
 
 Gosh!
 
 Let's document it!  Would it go in perlvar or perlsyn?
 
 The behaviour in question is a side effect of the general magic level of
 the other slots in *_, is it not?
 
 



Re: %_ - is it available for use?

2003-08-06 Thread david nicol
On Sat, 2003-08-02 at 18:33, Michael G Schwern wrote:

 Representing the Backwards Compatiblity Police, I've had co-workers use
 %_ as the globalist of all global hashes.  %_ transends all packages and
 scopes and Perl does not localize it, touch it or use it as it does @_ and 
 $_.  In the particular case I'm thinking of, it was used to hold global
 arguments for function calls in a template system.  Rather insane, really.
 Lots of better ways to do it and clearly making use of an undefined
 language feature.
 
 I'm not making an argument against %_, just noting that *_ is used 
 opportunisticly and you will break a few programs.


[EMAIL PROTECTED] perl -le '$_{a}=27; package notmain; print $_{a}'
27

Gosh!

Let's document it!  Would it go in perlvar or perlsyn?

The behaviour in question is a side effect of the general magic level of
the other slots in *_, is it not?



-- 
David Nicol /




Re: %_ - is it available for use?

2003-08-02 Thread Nick Ing-Simmons
Damian Conway [EMAIL PROTECTED] writes:

 From a Perl 6 perspective, it seems likely that C%_ will be the name 
commonly used for the slurpy hash of a subroutine. Just as C@_ will often 
be the name used for the slurpy array. See Exegesis 6 for more details.

Indeed, when it comes to object constructors (all of which implicitly have a 
slurpy hash), C%_ might well be the automatically provided name for that 
hash. See Exegesis 12 for more details. ;-)

Hence, making C%_ mean something different in core Perl 5 might possibly be 
forwards incompatible.

This wouldn't have been a core Perl 5 thing but a (module) Tk thing.
But if Perl 6 is giving it a meaning I will avoid it 
(unless a slurpy hash is what I meant - I haven't kept up the Perl6 jargon.)




Re: %_ - is it available for use?

2003-08-02 Thread Michael G Schwern
 Damian Conway [EMAIL PROTECTED] writes:
 Hence, making C%_ mean something different in core Perl 5 might possibly be 
 forwards incompatible.

Representing the Backwards Compatiblity Police, I've had co-workers use
%_ as the globalist of all global hashes.  %_ transends all packages and
scopes and Perl does not localize it, touch it or use it as it does @_ and 
$_.  In the particular case I'm thinking of, it was used to hold global
arguments for function calls in a template system.  Rather insane, really.
Lots of better ways to do it and clearly making use of an undefined
language feature.

I'm not making an argument against %_, just noting that *_ is used 
opportunisticly and you will break a few programs.


-- 
It's Crack Cocaine time!


Re: %_ - is it available for use?

2003-08-02 Thread Michael G Schwern
On Sun, Aug 03, 2003 at 01:37:16AM +0200, Abigail wrote:
 I am fond of doing
 
 local %_ = @_;
 
 as one of the first statements of a subroutine. That, or 
 
 my %args = @_;
 
 I like the latter because it uses a lexical variable, but I like the
 former because %_ fits with @_ and $_.

FWIW, local() is quite a bit slower than my().

$ perl5.8.1 local_vs_my 100
  Rate localmy
local 180180/s--  -30%
my257069/s   43%--

$ cat local_vs_my
#!/usr/bin/perl -w

use Benchmark 'cmpthese';

cmpthese( shift || -3, {
local   = sub { local %_ = @_; },
my  = sub { my %args = @_; },
});


-- 
Welcome to the Office Of Naval Contemplation


Re: %_ - is it available for use?

2003-08-02 Thread Larry Wall
On Sat, Aug 02, 2003 at 04:33:19PM -0700, Michael G Schwern wrote:
: I'm not making an argument against %_, just noting that *_ is used 
: opportunisticly and you will break a few programs.

Not necessarily.  If Perl 6 were to use %_ as parameter name, it
would be lexically scoped, and hide any package %_ only in that scope.

Larry


Re: %_ - is it available for use?

2003-08-02 Thread Michael G Schwern
On Sat, Aug 02, 2003 at 08:16:19PM -0700, Larry Wall wrote:
 On Sat, Aug 02, 2003 at 04:33:19PM -0700, Michael G Schwern wrote:
 : I'm not making an argument against %_, just noting that *_ is used 
 : opportunisticly and you will break a few programs.
 
 Not necessarily.  If Perl 6 were to use %_ as parameter name, it
 would be lexically scoped, and hide any package %_ only in that scope.

Sorry, p5p-cross talk, I was referring only to Perl 5.


-- 
Any sufficiently encapsulated hack is no longer a hack.


%_ - is it available for use?

2003-08-01 Thread Nick Ing-Simmons

We have been discussing how to pass data to Tk callbacks.
In particular Entry widget validation routines.
There are a number of items that they _might_ be interested in 
but a typical routine would only use a few.
Currently it passes them all as positional parameters.

One idea that occured to me/us is to have a localized hash 
for this purpose (which might be tied/magical).

One choice of name for this is %_ - which fits neatly with @_ for 
positional args and $_ as current thing.

Also *_ glob already exists to have its GvHV entry (ab-)used.

What does p5p think of this use ?

Basically @_ says how you been called $_ is what you are 
working on, and this idea gives %_ the meaning of why.
(Caller gives the who ;-) )



Re: %_ - is it available for use?

2003-08-01 Thread Damian Conway
Nick Ing-Simmons wrote:

We have been discussing how to pass data to Tk callbacks.
In particular Entry widget validation routines.
There are a number of items that they _might_ be interested in 
but a typical routine would only use a few.
Currently it passes them all as positional parameters.

One idea that occured to me/us is to have a localized hash 
for this purpose (which might be tied/magical).

One choice of name for this is %_ - which fits neatly with @_ for 
positional args and $_ as current thing.

Also *_ glob already exists to have its GvHV entry (ab-)used.

What does p5p think of this use ?

Basically @_ says how you been called $_ is what you are 
working on, and this idea gives %_ the meaning of why.
(Caller gives the who ;-) )
From a Perl 6 perspective, it seems likely that C%_ will be the name 
commonly used for the slurpy hash of a subroutine. Just as C@_ will often 
be the name used for the slurpy array. See Exegesis 6 for more details.

Indeed, when it comes to object constructors (all of which implicitly have a 
slurpy hash), C%_ might well be the automatically provided name for that 
hash. See Exegesis 12 for more details. ;-)

Hence, making C%_ mean something different in core Perl 5 might possibly be 
forwards incompatible.

Damian