Re: Negative array subscripts

2007-02-07 Thread Jonathan Scott Duff

On 2/6/07, Smylers [EMAIL PROTECTED] wrote:


Blair Sutton writes:

 David Green wrote:

  In some ways, I like not having a [0] index at all: programmers may
  be used to counting from zero, but normal humans start with first,
  second, third, ... third last, second last,...

 My feelings are Perl 6 should stick to 0 being the index of the first
 element of a list. Otherwise we might alienate programmers from P5 and
 nearly every other language. Couldn't the first array index be
 adjusted by adding a user defined Parrot grammar definition that
 applies the transformation +1 inside [] operators instead; maybe this
 could be accessible via a Perl use pragma.

Hmmm, a pragma's a bit heavyweight for this; how about being able to set
this with a special global variable -- that sure sounds handy ...



I can't quite tell how serious you are  :-)

I can't see Perl 6 changing the default starting index of arrays to be
anything other than 0 because that meme is so pervasive  (look at where
substr() starts,  and how we now have $0, etc.). But I can see the need for
a pragma to help out the Pascal or Fortran programmers start all of their
arrays at something other than 0.  And I can see the need for a modifier so
that an individual array can start at an index other that 0.

just registering my tuppence,

-Scott
--
Jonathan Scott Duff
[EMAIL PROTECTED]


Re: Negative array subscripts

2007-02-07 Thread Rafael Garcia-Suarez
Smylers wrote in perl.perl6.language :
 Hmmm, a pragma's a bit heavyweight for this; how about being able to set
 this with a special global variable -- that sure sounds handy ...

Actually, in perl 5, $[ *is* a pragma... :)

-- 
Grepping the source is good for the soul. -- the perldebguts manpage


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

2007-02-07 Thread larry
Author: larry
Date: Wed Feb  7 11:29:13 2007
New Revision: 13573

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

Log:
Clarified one-pass parsing of heredocs, and a restriction based on that.
Changed list() comprehension to each() which came available and reads better.
Removed misleading fossil about spaces on dot methods in interpolations.


Modified: doc/trunk/design/syn/S02.pod
==
--- doc/trunk/design/syn/S02.pod(original)
+++ doc/trunk/design/syn/S02.podWed Feb  7 11:29:13 2007
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall [EMAIL PROTECTED]
   Date: 10 Aug 2004
-  Last Modified: 29 Jan 2007
+  Last Modified: 7 Feb 2007
   Number: 2
-  Version: 83
+  Version: 84
 
 This document summarizes Apocalypse 2, which covers small-scale
 lexical items and typological issues.  (These Synopses also contain
@@ -2154,8 +2154,7 @@
 print The attribute is @baz[3](1,2,3){$xyz}blurfl.attr().\n
 
 Note that the final period above is not taken as part of the expression since
-it doesn't introduce a bracketed dereferencer.  Spaces are not allowed
-between the dereferencers even when you use the dotted forms.
+it doesn't introduce a bracketed dereferencer.
 
 =item *
 
@@ -2469,7 +2468,7 @@
 
 =item *
 
-Here docs allow optional whitespace both before and after terminating
+Heredocs allow optional whitespace both before and after terminating
 delimiter.  Leading whitespace equivalent to the indentation of the
 delimiter will be removed from all preceding lines.  If a line is
 deemed to have less whitespace than the terminator, only whitespace
@@ -2480,6 +2479,37 @@
 will be assumed to have no indentation.  (That is, it's assumed to
 match at the beginning of any whitespace.)
 
+=item *
+
+There are two possible ways to parse heredocs.  One is to look ahead
+for the newline and grab the lines corresponding to the heredoc, and
+then parse the rest of the original line.  This is how Perl 5 does it.
+Unfortunately this suffers from the problem pervasive in Perl 5 of
+multi-pass parsing, which is masked somewhat because there's no way
+to hide a newline in Perl 5.  In Perl 6, however, we can use unspace
+to hide a newline, which means that an algorithm looking ahead to find
+the newline must do a full parse (with possible untoward side effects)
+in order to locate the newline.
+
+Instead, Perl 6 takes the one-pass approach, and just lazily queues
+up the heredocs it finds in a line, and waits until it sees a real
+newline to look for the text and attach it to the appropriate heredoc.
+The downside of this approach is a slight restriction--you may not use
+the actual text of the heredoc in code that must run before the line
+finishes parsing.  Mostly that just means you can't write:
+
+BEGIN { say q:to/END/ }
+Say me!
+END
+
+You must instead put the entire heredoc into the CBEGIN:
+
+BEGIN {
+say q:to/END/;
+Say me!
+END
+}
+
 =back
 
 =head1 Context
@@ -2541,10 +2571,10 @@
 
 =item *
 
-When evaluating chained operators, if a Clist() occurs anywhere in that
+When evaluating chained operators, if an Ceach() occurs anywhere in that
 chain, the chain will be transformed first into a Cgrep.  That is,
 
-for 0 = list(@x)  all(@y) {...}
+for 0 = each(@x)  all(@y) {...}
 
 becomes
 
@@ -2554,7 +2584,7 @@
 preserved in the returned list, and duplicate elements in C@x are
 preserved as well.  In particular,
 
-@result = list(@x) ~~ {...};
+@result = each(@x) ~~ {...};
 
 is equivalent to
 
@@ -2563,7 +2593,7 @@
 However, this Ilist() comprehension is strictly a syntactic transformation,
 so a list computed any other way will not triger the rewrite:
 
-@result = (@x = list(@y)) ~~ {...}; # not a comprehension
+@result = (@x = each(@y)) ~~ {...}; # not a comprehension
 
 =item *