Implicit current-index variable, scoped inside for-loops

2006-08-28 Thread Carl Mäsak

 Hey do you know what would be cool in perl 6
 A special variable for when you do a for (@array) style loop
 it would always have the index of the array

Discussed on #perl6: it's already quite easy in Perl 6 to loop with an
explicit index:

my @array = ;
for @array.kv -> $i, $val {
 say "$i\t$val";
}

But maybe a variable that implicitly carries along the loop index
would be even snazzier?

for @array -> $val {
 say "$.\t$val";
}

(Change "$." to whatever name would actually be appropriate in this
case. "$." contains the current line number for the last filehandle
accessed in Perl 5, and that's probably why I came to think of it
here.)

Questions:

- Is the itch big enough for this? The more I look at the first piece
of code, the more I'm thinking "that's not so bad, really". (Though
opinions differed on the IRC channel.) Is there a situation I'm not
thinking of where the first piece of code would suck, and the second
piece of code would rock? Or is this a case of oversugaring?

- I feel there's a trend of moving away from line-noise variables. I'd
hate to be one to propose adding a new one to the language. Is there a
better syntax than "$."?

- How would this work with non-array data? Specifically, what happens
with next, redo etc on a filehandle, for example?

See



for the #perl6 discussion.

--
masak


[svn:perl6-synopsis] r11527 - doc/trunk/design/syn

2006-08-28 Thread audreyt
Author: audreyt
Date: Mon Aug 28 07:34:29 2006
New Revision: 11527

Modified:
   doc/trunk/design/syn/S02.pod

Log:
* S02: minor grammar and syntax nit from p6l feedbacks.

Modified: doc/trunk/design/syn/S02.pod
==
--- doc/trunk/design/syn/S02.pod(original)
+++ doc/trunk/design/syn/S02.podMon Aug 28 07:34:29 2006
@@ -1396,13 +1396,17 @@
 When used as a subscript it performs a slice equivalent to C<{'foo','bar'}>.
 Elsewhere it is equivalent to a parenthesisized list of strings:
 C<< ('foo','bar') >>.  Since parentheses are generally reserved just for
-precedence grouping, they merely autointepolate in list context.  Therefore
+precedence grouping, they merely autointerpolate in list context.  Therefore
 
-@a = 1, < 2 3 >, 4;
+@a = 1, < x y >, 2;
 
-is equivalent to
+is equivalent to:
+
+@a = 1, ('x', 'y'), 2;
+
+which is the same as:
 
-@a = 1, 2, 3, 4;
+@a = 1, 'x', 'y', 2;
 
 In scalar context, though, the implied parentheses are not removed, so
 
@@ -1410,12 +1414,12 @@
 
 is equivalent to:
 
-$a = ('a','b');
+$a = ('a', 'b');
 
 which, because the list is assigned to a scalar, is autopromoted into
 an Array object:
 
-$a = ['a','b'];
+$a = ['a', 'b'];
 
 Likewise, if bound to a scalar parameter, C<<  >> will be
 treated as a single list object, but if bound to a slurpy parameter,


Re: [svn:perl6-synopsis] r11504 - doc/trunk/design/syn

2006-08-28 Thread Markus Laire

On 8/28/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

+Elsewhere it is equivalent to a parenthesisized list of strings:
+C<< ('foo','bar') >>.  Since parentheses are generally reserved just for
+precedence grouping, they merely autointepolate in list context.  Therefore
+
+@a = 1, < 2 3 >, 4;
+
+is equivalent to
+
+@a = 1, 2, 3, 4;


Shouldn't this be
   @a = 1, '2', '3', 4;

--
Markus Laire


Re: clarifying the spec for 'ref'

2006-08-28 Thread Juerd
Richard Hainsworth skribis 2006-08-28 10:33 (+0400):
> ---
> | Class 
> A|
> |
> --   |
> || Class B   
> |   |
> |
> --   |
> --
>  

Your mail program is wrapping this in a way that renders it unusable.

Please make sure you use a monospaced font, and do not exceed the
wrapping limit (typically 72 characters).

> -
> -|  Class D  |
> | Class A   |   ||
> |
> |---|-|
> ||   
> |-|
> |  --|-  
> | |
> ---|-|-|-   
> |
>   | | |  Class 
> B |
>   | 
> --|
>   |Class C  |
>   

I'm curious what this was supposed to look like. :)


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: [svn:perl6-synopsis] r11504 - doc/trunk/design/syn

2006-08-28 Thread Smylers
[EMAIL PROTECTED] writes:

> New Revision: 11504
>doc/trunk/design/syn/S02.pod
> 
> +C<< ('foo','bar') >>.  Since parentheses are generally reserved just for
> +precedence grouping, they merely autointepolate in list context.  Therefore

Typo: "autointepolate".

Smylers


[svn:perl6-synopsis] r11509 - doc/trunk/design/syn

2006-08-28 Thread audreyt
Author: audreyt
Date: Mon Aug 28 00:11:57 2006
New Revision: 11509

Modified:
   doc/trunk/design/syn/S02.pod

Log:
* grammar nit, and clarify that it is the assign-to-scalar that Arrayify a list.

Modified: doc/trunk/design/syn/S02.pod
==
--- doc/trunk/design/syn/S02.pod(original)
+++ doc/trunk/design/syn/S02.podMon Aug 28 00:11:57 2006
@@ -1412,7 +1412,8 @@
 
 $a = ('a','b');
 
-which, because the list is in scalar context, is autopromoted an Array object:
+which, because the list is assigned to a scalar, is autopromoted into
+an Array object:
 
 $a = ['a','b'];