Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread David Cantrell
On Mon, Sep 27, 2010 at 11:15:17PM -0400, Uri Guttman wrote:

 actually the = part is even more amusing. look here:
 perl -le '$#foo = -2 ; print $#foo'
 -1
 
 you can't set the last index to  -1. which makes sense. which makes the
 original code even dumber.

$ perl -le '$[=-1; print $#foo'
-2

-- 
David Cantrell | Nth greatest programmer in the world

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread Greg London

Congrabulashuns. You just won the Evil programmer of the Year award.

;/

What's really sad is the number of people reading this and thinking 'oh. I'd  
like to win that' is a large positive number.


The award ceremony will be held behind the chemical shed. Programmer V will  
be handing out the awards.


-Original message-
From: David Cantrell da...@cantrell.org.uk
To: boston-pm@mail.pm.org
Sent: Tue, Sep 28, 2010 11:50:27 GMT+00:00
Subject: Re: [Boston.pm] $#{$Queue}

On Mon, Sep 27, 2010 at 11:15:17PM -0400, Uri Guttman wrote:


actually the = part is even more amusing. look here:
perl -le '$#foo = -2 ; print $#foo'
-1

you can't set the last index to  -1. which makes sense. which makes the
original code even dumber.


$ perl -le '$[=-1; print $#foo'
-2

--
David Cantrell | Nth greatest programmer in the world

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread David Cantrell
Greg London wrote:
 From: David Cantrell da...@cantrell.org.uk
 On Mon, Sep 27, 2010 at 11:15:17PM -0400, Uri Guttman wrote:
 actually the = part is even more amusing. look here:
 perl -le '$#foo = -2 ; print $#foo'
 -1
 you can't set the last index to  -1. which makes sense. which makes the
 original code even dumber.
 $ perl -le '$[=-1; print $#foo'
 -2
 Congrabulashuns. You just won the Evil programmer of the Year award.

Yay!

But I don't want to even think about the collision between Unspeakable
Evil like that and the Other Unspeakable Evil of negative indices on
*normal* arrays.

Cos you did all know that in this code, for example:

  $[ = 0; # :-)
  @array = qw(ant bat cat dog elephant);
  print $array[-1];
  print $array[-2];

will print 'elephant' and 'dog', right?  This is occasionally Very
Useful, although perhaps not as clear as just using $#array, $#array-1
etc.  Unfortunately it doesn't wrap around twice, so $array[-6] isn't
also 'elephant'.

$[ is scheduled for removal from perl in 5.14, I believe.  And in all
versions of perl 5 it is at least file-scoped so can't leak out of modules.

-- 
David Cantrell | semi-evolved ape-thing

Planckton: n, the smallest possible living thing

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread Gyepi SAM
On Tue, Sep 28, 2010 at 07:07:38PM -0400, Greg London wrote:
 Ive used $arr[-2] to get the second to last element of an array.
 But anyone using $[ to change the first index of an array to be
 negative should be beaten severely.

I had initially thought this too; though I imagined something
worse than a beating. However, upon further thought, I think it
can be occasionally useful to change the first index of an array.

Unfortunately, the most useful example I can come up with is from another
language.

In Lua, the equivalent of $ARGV[0] contains the script name while lower
indices reference earlier parts of the invocation. So

  lua -i script.lua 24

creates the equivalent of

  $ARGV[-2] = 'lua'
  $ARGV[-1] = '-i'
  $ARGV[0] = 'script.lua'
  $ARGV[1] = '24'


The point here being that the useful data starts at $ARGV[0] while,
perhaps less useful, data exist at earlier indices. Of course this is
a contrived example and Lua arrays are different enough from Perl arrays
to make this simple.

I think '$[' would more useful if it could be scoped to individual arrays.
Though it does seem to be of dubious utility to begin with.

-Gyepi

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread rogers-pm5
   From: Gyepi SAM gy...@praxis-sw.com
   Date: Tue, 28 Sep 2010 22:23:27 -0400

   . . .

   I think '$[' would more useful if it could be scoped to individual
   arrays.

I have used languages (PL/1 and Pascal come to mind) that allow you to
declare both upper and lower bounds to each array dimension.  But for
both languages, I have found such arrays more trouble than they are
worth.  A Pascal example I saw created a histogram of something grouped
by year (declared as array [1970..1984] of integer, or some such).
But since the bounds must be fixed at compile time, you cannot write a
practical *general* histogram generator this way.

   Of course, a large part of the problem with these languages is
compile-time binding of array dimensions, so maybe there are better use
cases.  But note that even Common Lisp, which supports multidimensional
arrays with dynamic upper bounds, still fixes all lower bounds to 0.

   Though it does seem to be of dubious utility to begin with.

   -Gyepi

As a global, it's a disaster.  I'm glad to hear it's slated to
disappear.

-- Bob

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


[Boston.pm] talks?

2010-09-28 Thread Bill Ricker
Someone recently offered to do a talk and I don't think I added them to the
list of potentials.  We need a topic  speaker or lead for the 12th.
What is on the menu is

   - Federico Dtracing Perl
   - debate inside out objects and various Class modules
   - deeper exploration of 5.12 and Modern/Enlighten Perl?
   - our standing default topic is now Config::Std workshop.
   - Your YAPC/PPW/... presentation rehearsal or reprise


-- 
Bill
n1...@arrl.net bill.n1...@gmail.com

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread Nick Patch
On Tue, Sep 28, 2010 at 11:11 PM,  rogers-...@rgrjr.dyndns.org wrote:
 I have used languages (PL/1 and Pascal come to mind) that allow you to
 declare both upper and lower bounds to each array dimension.  But for
 both languages, I have found such arrays more trouble than they are
 worth.  A Pascal example I saw created a histogram of something grouped
 by year (declared as array [1970..1984] of integer, or some such).

User-defined array indexing is included in Perl 6:
my Int @array{1970..1984};

The lower bound of the built-in indexing cannot be changed from 0 and
the built-in indexing is always available via square brackets.  The
user-defined indexing is available via curly braces.  For example,
both @array[0] and @array{1970} could be used to access the first
value.

And here's the relevant section of the spec:
http://perlcabal.org/syn/S09.html#User-defined_array_indexing

However, it is not yet implemented in Rakudo.

 But since the bounds must be fixed at compile time, you cannot write a
 practical *general* histogram generator this way.

This also appears to be the case with user-defined array indexing in Perl 6.

Nick

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread tkohl


 User-defined array indexing is included in Perl 6:
 my Int @array{1970..1984};

Huh???

An explicit type declaration in Perl??
Who ordered this?

No more scalar = catch all type?

   -T

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] $#{$Queue}

2010-09-28 Thread Nick Patch
On Wed, Sep 29, 2010 at 12:37 AM,  tk...@bu.edu wrote:
 An explicit type declaration in Perl??
 Who ordered this?

 No more scalar = catch all type?

No worries, you can just continue using untyped scalars as you always have!

my $scalar;

But you can also declare types and array sizes if you want.

Nick

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm