implied looping (was: Re: type sigils redux, and new unary ^ operator)

2005-11-23 Thread Ruud H.G. van Tol
Larry Wall:

  for ^5 { say }  # 0, 1, 2, 3, 4

The 'for' can go if a list (and also an array) would imply looping, when
it is positioned next to a block:

a.   say (0..4);
b.   { say; say } (0..4);
c.   (0..4) { say; say }
d.   @{0..4} { say; say }
(etc.)

b. now produces 2 lines with 01234 (in pugs). With implied looping that
would be 10 lines, starting with two 0-lines.

-- 
Grtz, Ruud



Re: implied looping (was: Re: type sigils redux, and new unary ^ operator)

2005-11-23 Thread Michele Dondi

On Wed, 23 Nov 2005, Ruud H.G. van Tol wrote:


 for ^5 { say }  # 0, 1, 2, 3, 4


The 'for' can go if a list (and also an array) would imply looping, when
it is positioned next to a block:

a.   say (0..4);
b.   { say; say } (0..4);


I'm not really sure: while I like it for its conciseness -and in 
particular I've often desired a very short, but clear, way to say: do 
this #n times- IIUC (Perl6 new rules for blocks/closures and 
dereferencing) this is only one dot or even whitespace away from passing a 
list into an anonymous sub. Which may be confusing after all...


The problem (if any!) does not persist for the postponed block form. But 
as far as code like


^5 { do_it };

is concerned, it is even _too_ concise, and I'd prefer some additional 
syntactical indication about what's going on. For my tastes,


^5: { do_it };  # But then also 5: { do_it }; [*]

would be perfect, were not the colon already taken for a bazillion other 
uses...


OTOH if I remember correctly there should be (provision for) a Cxx 
variant that takes a closure and executes it over and over again.



[*] Or 5 - { do_it }; but I strongly suspect this would interfere with 
pointy subs.



Michele
--
I am a deeply religious nonbeliever.
This is a somewhat new kind of religion.
- Albert Einstein


Re: implied looping (was: Re: type sigils redux, and new unary ^ operator)

2005-11-23 Thread Larry Wall
On Wed, Nov 23, 2005 at 02:23:51PM +0100, Ruud H.G. van Tol wrote:
: Larry Wall:
: 
:   for ^5 { say }  # 0, 1, 2, 3, 4
: 
: The 'for' can go if a list (and also an array) would imply looping, when
: it is positioned next to a block:
: 
: a.   say (0..4);
: b.   { say; say } (0..4);
: c.   (0..4) { say; say }
: d.   @{0..4} { say; say }
: (etc.)
: 
: b. now produces 2 lines with 01234 (in pugs).

Which is wrong by the current spec, by the way.  It should be a syntax
error to have two terms in a row.  Bare parens can't be function args
unless they're abutted or use ..

: With implied looping that would be 10 lines, starting with two 0-lines.

I don't like that much deep magic without a keyword to clue the reader,
and we have plenty of keywords to work it already:

for ^5 { say }
^5.each { say }
(0..4).each == say
say for ^5;

I can see the mathematical appeal of coming up with a language in
which there is a meaning for every possible combination of tokens.
But there's an important linguistic principle here that I think has
never been adequately researched, and is probably worth a doctorate
to whoever does it.  But it's a subtle principle, so it's rarely
mentioned.  That principle is that there has to be some kind of
self-clocking aspect to a syntax, or you never realize if you've
gotten out of sync.  In other words, there have to be some sequences
in the syntax that are syntax errors, or you'll never get any syntax
errors.  That sounds like a tautalogy, but I don't mean it that way.

The self-clocking, phase-locked-loop aspect of Perl is driven by the
fact that we almost never allow two terms in a row, and also by the
fact that it's pretty easy to distinguish terms from operators most
of the time.  This is what allows Perl to be a language that does,
in fact, overload leading characters between terms and operators
rather heavily.  But if we allowed you to say $foo %bar and gave
it some meaning, you wouldn't be able to tell whether that % should
be a sigil or a modules operator.

And we also have to be careful about terms like {...} and (...) and
[...].  We've already made the exception that you can have {...} where
an operator is expected--that's exactly how the grammar recognizes
the difference between

for foo 1,2,3 {...}

and

for foo 1,2,3,{...},{...},{...} {...}

But it's easy enough to get tangled up with that exception, and if we
start making any sequence of bare brackets mean something, we'll not
get a syntax error but an unexpected successful parse, which can be
far more devastating than a syntax error.

However, in order to milk our bracketing characters for all they're
worth, as well as all the other operators, we finessed it in Perl 6
depending on the whitespace (or .) so that we can tell which
operators are intended as postfix operators and which ones are
misplaced terms.  And that's why

{say} (1)

has to be a syntax error, while

{say}(1)
{say}.(1)

are just function calls.  We really have to make that rule, or people
will be very confused a very large amount of the time.  And the worst
part of it is that they'll think it's because they're stupid, not
because the language is poorly designed.  It's a counterintuitive fact
that languages that are too efficiently coded induce inefficiencies in
communication.  We're already dancing on the brink of too efficient,
and it would be easy to fall over the edge.  Some would say we already
have...

Larry


Re: implied looping (was: Re: type sigils redux, and new unary ^ operator)

2005-11-23 Thread Juerd
Larry Wall skribis 2005-11-23  9:19 (-0800):
 ^5.each { say }

Without colon?


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