Re: continuation markers for long literals (was Re: r29931 - docs/Perl6/Spec)

2010-03-04 Thread Darren Duncan

Larry Wall wrote:

Dealing with antediluvian displays sounds like a good spot for that
ancient technology, the preprocessor,

: I also figured that this would be a fairly simple thing to do.

Well, it will be simple, once we have macros; in fact, textual macros
can be regarded simply as scoped preprocessors, with all the rights,
privileges, and responsibilities pertaining thereto.  I think macros
will provide enough language support for this sort of "hard things
should be possible" escape hatch.  And remember you can always override
the grammar if you have special reasons for doing so.  That's what
Perl 6 is all about.  It's not about foreseeing every possible twinge
of misgiving that anyone may come to feel in the next 100 years...

Sure, we're trying to create a gigantic sweet spot in Perl 6, but
Willy Wonka knows you can't have the whole world, and if you could,
you can't have it now.  :)


FYI,

As a follow-up, this Perl 6 discussion has inspired me to apply some of these 
ideas to my Muldis D language (PTMD_STD dialect), so then there should be an 
earlier example of the concept I proposed.


The feature that I went and specced out today, and named "unspace" after its 
Perl 6 inspiration, basically is a token consisting of a pair of backslashes 
separated by whitespace.  Currently this token can be placed in the middle of 
either a numeric or a stringy literal (including quoted formats of identifiers), 
and in the latter case *inside* the quotes.


Examples:

  $bar := 7;55084\ \4222\ \7677  # an integer expressed in octal #

  $some_pi := 3.141592653589793238462643383279\
\5028841971693993751058209749445923078164\
\0628620899862803482534211706798214808651\
\3282306647093844609550582231725359408128

  $a_rat := 48111745028410270193\
\8521105559 / 64462294895493038196\
\442881097566593344612847564823

  $a_string := 'hello this world\
\ how are you today'

  $a_string := 'hello this world'
~ ' how are you today'

Those, except the last, are direct translations of the pseudo-Perl-6 I gave 
earlier in the thread.


Note that since Muldis D's use of backslashes differs in some ways from how Perl 
6 uses them (backslashes are only otherwise used for spelling escaped 
characters), the above syntax doesn't conflict with anything there.


One detail unlike Perl 6's unspace is that I put a backslash at both ends of the 
stuff to ignore, so when used for the above purpose the code isn't end-weighted 
and a human can parse what's going on faster.  Also, my version of unspace is 
simpler in that you don't put any comments in it.


Now if naming my concept "unspace" may confuse people, as it is partially like 
that of Perl 6 but partly not, I could name it something else, but that name 
seemed the best for now, because it is all about letting a programmer put some 
whitespace in their code which the parser would then treat as if it wasn't there 
at all.


-- Darren Duncan


r29937 - docs/Perl6/Spec

2010-03-04 Thread pugs-commits
Author: lwall
Date: 2010-03-05 01:03:51 +0100 (Fri, 05 Mar 2010)
New Revision: 29937

Modified:
   docs/Perl6/Spec/S09-data.pod
Log:
[S09] kill masak++'s @array[%100_000] in favor of a mapping closure
(The fact that % vars can't use _ is a different bug.)


Modified: docs/Perl6/Spec/S09-data.pod
===
--- docs/Perl6/Spec/S09-data.pod2010-03-04 16:17:41 UTC (rev 29936)
+++ docs/Perl6/Spec/S09-data.pod2010-03-05 00:03:51 UTC (rev 29937)
@@ -13,8 +13,8 @@
 
 Created: 13 Sep 2004
 
-Last Modified: 26 Feb 2010
-Version: 43
+Last Modified: 4 Mar 2010
+Version: 44
 
 =head1 Overview
 
@@ -244,18 +244,29 @@
 There is no autotruncation on the left end.  It's not that
 hard to write C<0>, and standard indexes always start there.
 
-As a special form, numeric subscripts may be declared as cyclical
-using an initial C<%>:
+As a special form, subscript declarations may add a C<:map> modifier
+supplying a closure, indicating that all index values are to be mapped
+through that closure.  For example, a subscript may be declared as cyclical:
 
-my @seasons[%4];
+my @seasons[4:map(*%4)];
 
 In this case, all numeric values are taken modulo 4, and no range truncation 
can
 ever happen.  If you say
 
 @seasons[-4..7] = 'a' .. 'l';
 
-then each element is written three times and the array ends up with 
C<['i','j','k','l']>.
+then each element is written three times and the array ends up with
+C<['i','j','k','l']>.  The mapping function is allowed to return
+fractional values; the index will be the C of that value.
+(It is still illegal to use a numeric index less that 0.)  One could
+map indexes logarithmically, for instance, as long as the numbers
+aren't so small they produce negative indices.
 
+Another use might be to map positive numbers to even slots and negative
+numbers to odd slots, so you get indices that are symmetric around 0
+(though Perl is not going to track the max-used even and odd slots
+for you when the data isn't symmetric).
+
 =head1 Typed arrays
 
 The type of value stored in each element of the array (normally C for 
unspecified type)