Bart Lateur wrote:
> 
> My idea is that if anybody sets $[ to 1 in a script, all accesses to
> array in that script would use 1 as the index of the very first item:
> $ary[1]. But if you pass this array (for example, a reference to it) to
> a function in a module that doesn't set $[, it would access the same
> first item through index 0: $ary[0] or $ref->[0].
> 
> And vice versa (swap "module" and "script").

This seems to make sense. But I'm pretty sure this is how it works
already:

   package Bob;
   sub do_print {
      my @a = @_;
      print $a[0];
   }

   package main;
   $[ = 1;
   $array[1] = "Hello\n";

   Bob::do_print(@array);   # prints "Hello\n"

And Camel says:

   Assignment to $[ is now treated as a compiler directive, and cannot
   influence the behavior of any other file. Its use is discouraged.

I'm really surprised by this RFC, to be honest, considering that the
overall reaction to $[ is Don't Do That. I've always thought axing $[
was a no-brainer.

One interesting thing to contemplate is how this might change
higher-order function notation. If you set $[ = 1, you'd surely want ^0
to be changed to ^1 then? And if you set $[ = 2, would you want $1 to
become $2 ?

The :base(1) attribute seems interesting, but not viable. In particular,
then you'd have to check each individual array to see what its base was
set to to know how to handle it.

-Nate

Reply via email to