Re: Negative array subscripts
Jonathan Scott Duff writes: > 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 was being completely serious in my attempt to remind folk of C<$[> in Perl 5, how much it is despised, and that it is a mistake that Perl 6 won't be repeating. > ... 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. Those sort of crutches in programming languages (let's help folk who know some other language -- meaning they end up programming in some hybrid of the two languages) often turn out to be a mistake. Think of Pascal programmers #define-ing begin and end as { and } in C, or WordBasic being 'localized' into French, or C in Perl 5. Part of this is cos they are mostly unnecessary: there are so many fundamental and much deeper differences between Pascal and Perl that any Pascal programmer who's managed to learn about and cope with all the weird and wonderful things that Perl offers isn't going to struggle with the relatively superficial difference in array subscripts. > And I can see the need for a modifier so that an individual array can > start at an index other that 0. Isn't that something shaped arrays can already do? Smylers
[svn:perl6-synopsis] r13585 - doc/trunk/design/syn
Author: larry Date: Tue Feb 13 23:07:00 2007 New Revision: 13585 Modified: doc/trunk/design/syn/S02.pod Log: Got rid of quote declarator. Just use a macro. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podTue Feb 13 23:07:00 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 11 Feb 2007 + Last Modified: 13 Feb 2007 Number: 2 - Version: 86 + Version: 87 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1958,67 +1958,20 @@ :trans Parse as transliteration :code Quasiquoting -Ordinarily the colon is required on adverbs, but the C declarator -allows you to combine any of the existing adverbial forms above -without an intervening colon: +You may omit the first colon by joining an initial 'Q', 'q', or 'qq' with +a single short form adverb, which produces forms like: -quote qw; # declare a P5-esque qw// meaning q:w -quote Qc; # Q:c//, interpolate only closures +qw /a b c/; # P5-esque qw// meaning q:w +Qc '...{$x}...';# Q:c//, interpolate only closures +qqx/$cmd @args/ # equivalent to P5's qx// -Actually, those two are already assumed, because you get all of the -forms that use a single character modifier predeclared for free. (Note -this means that C doesn't intepolate.) +(Note that C doesn't intepolate.) -If you want to abbreviate further, you may also give an explicit -definition as either a string or quasiquote: +If you want to abbreviate further, just define a macro: -quote qx = 'qq:x'; # equivalent to P5's qx// -quote qTO = 'qq:x:w:to';# qq:x:w:to// -quote circumfix:<❰ ❱> = q:code{ .quoteharder }; # or some such... - -In particular, all these forms disable the lookahead for an adverbial argument, -as if there were a space after the keyword. So although - -q:s($foo) - -will misinterpret C<$foo> as the C<:s> argument, - -qs(stuff) - -has the advantage of misinterpreting it as the argument to the C -function instead. C<:)> - -But parens are special that way. (Even C is assumed to be a -function call rather than a quote.) Other bracketing characters are -special only if they can be mistaken for adverbial arguments, so - -qs[stuff] - -is fine, and means - -q:s /stuff/ - -while - -q:s[stuff] - -also happens to work because quote adverbs only allow the paren form of -bracketed adverbs. - -If this is all too much of a hardship, you can define your own quote -adverbs and operators as standard macros. The main difference is that, -unlike - -quote qs = 'q:s'; - -declaring something like - -macro qs { 'q:s' } - -does I disable the subsequent search for a parenthesized argument -to C<:n>. To get the equivalent, you need to add a space: - -macro qs { 'q:s ' } +macro qx { 'qq:x ' } # equivalent to P5's qx// +macro qTO { 'qq:x:w:to ' }# qq:x:w:to// +macro circumfix:<❰ ❱> ($expr) { q:code{ $expr.quoteharder } } All the uppercase adverbs are reserved for user-defined quotes. All Unicode delimiters above Latin-1 are reserved for user-defined quotes.
[svn:perl6-synopsis] r13586 - doc/trunk/design/syn
Author: larry Date: Tue Feb 13 23:22:05 2007 New Revision: 13586 Modified: doc/trunk/design/syn/S02.pod Log: typos changed :to be the short form for :heredoc Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podTue Feb 13 23:22:05 2007 @@ -1952,20 +1952,20 @@ :f :function Interpolate & calls :c :closureInterpolate {...} expressions :b :backslash Interpolate \n, \t, etc. (implies :q at least) -:to Parse result as heredoc terminator +:to :heredocParse result as heredoc terminator :regex Parse as regex :subst Parse as substitution :trans Parse as transliteration :code Quasiquoting -You may omit the first colon by joining an initial 'Q', 'q', or 'qq' with +You may omit the first colon by joining an initial C, C, or C with a single short form adverb, which produces forms like: qw /a b c/; # P5-esque qw// meaning q:w Qc '...{$x}...';# Q:c//, interpolate only closures qqx/$cmd @args/ # equivalent to P5's qx// -(Note that C doesn't intepolate.) +(Note that C doesn't interpolate.) If you want to abbreviate further, just define a macro: