Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-19 Thread Lars Henrik Mathiesen

 Date: Thu, 18 Apr 2002 23:44:26 +0200
 From: Paul Johnson [EMAIL PROTECTED]
 
 On Thu, Apr 18, 2002 at 07:56:06PM -, Lars Henrik Mathiesen wrote:
  I would like to write
  
for my $key ( $hash{foo}-keys ) { print $hash{bar}-{$key} }
 
 This, or something similar was hashed out on p5p, h, about 4 years
 ago, give or take four years ;-)  Actually, I think it might have been
 when Chip was Pumpking, which would have made it about five years ago.

I'm not surprised that other people suggested it... and I'm sure that
there are good arguments against as well.

Hmmm... I just realized that it's possible to get almost the same
thing by misusing bless:

package hash;
sub bless { bless shift }
sub keys { keys %{+shift} }
sub values { values %{+shift} }
sub hash { %{+shift} }

package main;

my $href = hash::bless { foo = 1, bar = 2 };

print join ', ', $href-keys;
print join ', ', $href-values;
print join ', ', $href-hash;

Tempting --- now if only I could create a method named % or @ ... I'm
not sure how many optimizations this loses relative to the %{ $href }
construction, though.

Lars Mathiesen (U of Copenhagen CS Dep) [EMAIL PROTECTED] (Humour NOT marked)



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-19 Thread abigail

On Fri, Apr 19, 2002 at 01:35:10PM -, Lars Henrik Mathiesen wrote:
  Date: Thu, 18 Apr 2002 23:44:26 +0200
  From: Paul Johnson [EMAIL PROTECTED]
  
  On Thu, Apr 18, 2002 at 07:56:06PM -, Lars Henrik Mathiesen wrote:
   I would like to write
   
 for my $key ( $hash{foo}-keys ) { print $hash{bar}-{$key} }
  
  This, or something similar was hashed out on p5p, h, about 4 years
  ago, give or take four years ;-)  Actually, I think it might have been
  when Chip was Pumpking, which would have made it about five years ago.
 
 I'm not surprised that other people suggested it... and I'm sure that
 there are good arguments against as well.
 
 Hmmm... I just realized that it's possible to get almost the same
 thing by misusing bless:
 
 package hash;
 sub bless { bless shift }
 sub keys { keys %{+shift} }
 sub values { values %{+shift} }
 sub hash { %{+shift} }
 
 package main;
 
 my $href = hash::bless { foo = 1, bar = 2 };
 
 print join ', ', $href-keys;
 print join ', ', $href-values;
 print join ', ', $href-hash;
 
 Tempting --- now if only I could create a method named % or @ ... I'm
 not sure how many optimizations this loses relative to the %{ $href }
 construction, though.


Creating methods with names '%', '@' or whatever isn't the problem.
The problem is calling them.

#!/usr/bin/perl -w

use strict;
package hash;
sub bless { bless shift }

{
no strict 'refs';
*{'hash::@'} = sub {keys %{+shift}};
*{'hash::*'} = sub {values %{+shift}};
*{'hash::%'} = sub {%{+shift}}
}

package main;

my $href = hash::bless { foo = 1, bar = 2 };

$\ = \n;
$, = , ;

print $href - $_ foreach qw /@ * %/;
__END__


Running this gives:

foo, bar
1, 2
foo, 1, bar, 2


But '$href - %' and also '$href - %' are syntax errors. You
can put a variable on the right side of an arrow, but not a
literal string.



Abigail



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-19 Thread Ton Hospel

In article [EMAIL PROTECTED],
Bart Lateur [EMAIL PROTECTED] writes:
 On Thu, 18 Apr 2002 12:42:17 -0500, c. church wrote:
 
$hash{foo}{bar}{baz} is extrmely descriptive.  I
like it.  I can look in once place and see exactly what I need.
 
 Yeah... but what I don't like, is that if I have an array (or list):
 
   @follow = ('foo', 'bar', 'baz');
 
 that I can't have a simple expression with \%hash and @follow which will
 look up the above expression or me. All I can do, is create a loop that
 follows each ref:
 
   my $ref = \%hash;
   foreach (@follow) {
   $ref = $ref-{$_};
   }
 
 and in the end, $ref will contain the value I want. Er, it will contain
 a *copy* of the value, I can't modify the original hash element using
 it.
 
 Complicated, or what?
 
Loop like this:
my $here = \\%hash;
$here = \${$here}-{$_} for @follow;
# Now you can really access that spot (even if it didn't exist before)
$$here = $value;




RE: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-18 Thread Ala Qumsieh


c. church writes:

 If that's bad, just use something nearly as bad once, i.e.:
 
 my $hRef = \%{ $hash{foo}{bar} };

$hash{foo}{bar} is already a hashref. You don't need to dereference it just
to reference it back:

my $href = $hash{foo}{bar};

Having said that, I don't believe that there should be any one rule
governing the depth of your hashes. Different people think differently, and
therefore might choose different data structures. Whatever makes you feel
more comfortable. This is Perl we're talking about.

--Ala



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-18 Thread Lars Henrik Mathiesen


[EMAIL PROTECTED] (c. church) writes:
- Original Message -
From: [EMAIL PROTECTED]

 I agree. C$hash{foo}{bar}{baz} is horribly ugly. Your solution
 is a redesign. My solution is to use whitespace. The latter is
 far easier than the former.

Personally, I disagree - $hash{foo}{bar}{baz} is extrmely descriptive.  I
like it.  I can look in once place and see exactly what I need.

If that's bad, just use something nearly as bad once, i.e.:

my $hRef = \%{ $hash{foo}{bar} };

my $blah  = $hRef-{baz};

Ummm, why not just

  my $hRef = $hash{foo}{bar};
  my $blah  = $hRef-{baz};

? \%{ $x } just gives you back $x, if it is in fact a hash ref. If it
isn't, you've only moved the error by one line.

Btw, I really like the infix operator.  It's pretty, it fills my code with
all sorts of warmness of knowing exactly what it means. =)

What I've sometimes wished for is some way of dereffing to a hash or
array using - or some related postfix thing. So instead of

  my $aref = $hash{foo};
  for my $key ( keys %$aref ) { print $hash{bar}-{$key} }

or 

  for my $key ( keys %{ $hash{foo} } ) { print $hash{bar}-{$key} }

I would like to write

  for my $key ( $hash{foo}-keys ) { print $hash{bar}-{$key} }

or even

  for my $key ( keys $hash{foo}-% ) { print $hash{bar}-{$key} }

... I'd find these easier to make sense of, though I've got a sneaking
suspicion that I'm in a small minority there. But of course they'd be
fun, because I could inflict them on unsuspecting readers of my code.

Lars Mathiesen (U of Copenhagen CS Dep) [EMAIL PROTECTED] (Humour NOT marked)



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-18 Thread Steffen Mueller

Lars Henrik Mathiesen [EMAIL PROTECTED] schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

[...]

| What I've sometimes wished for is some way of dereffing to a hash or
| array using - or some related postfix thing. So instead of
|
|   my $aref = $hash{foo};
|   for my $key ( keys %$aref ) { print $hash{bar}-{$key} }
|
| or
|
|   for my $key ( keys %{ $hash{foo} } ) { print $hash{bar}-{$key} }
|
| I would like to write
|
|   for my $key ( $hash{foo}-keys ) { print $hash{bar}-{$key} }
|
| or even
|
|   for my $key ( keys $hash{foo}-% ) { print $hash{bar}-{$key} }

I think I vaguely remember from one of Damian's talks that all built-ins in
Perl 6 will in fact be indirect object syntax. So you could actually do
%hash-keys.

I don't know about the dereferencing issue, though. DWIM?

Please, correct me if I horribly misunderstood an important aspect of that
talk. It might well be the fact as it was one of the 8 o'clock in the
morning speeches during which I hadn't had my daily caffeine injection yet.
And I was still wrapping my mind around SelfGol and enjoying the Australian
accent. (Which - opposing my German/American/British accent - has a pleasant
ring to it.)

Steffen
--
$_=qq#tsee  gmx.net#;s#e#s#g;s#[^\s\w]#c#;s#s#ust#g;s#t#J#e;s#nus#ker#
;chop;$c='  ';$c='12319';@c=split/(..)/,'8234130006710523';@d=split3
,$c;chop;'  at  ';s#(t)ustust#$1\0ano$1;.#;y#.; #ehr#;@_=$_;shift@c,substr
$_[0],$_,1,chr(ord(substr$_[0],$_)-shift@c)for$d[0]..$d[1];print$_[0]\n;





Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-18 Thread Paul Johnson

On Thu, Apr 18, 2002 at 07:56:06PM -, Lars Henrik Mathiesen wrote:

 What I've sometimes wished for is some way of dereffing to a hash or
 array using - or some related postfix thing. So instead of
 
   my $aref = $hash{foo};
   for my $key ( keys %$aref ) { print $hash{bar}-{$key} }
 
 or 
 
   for my $key ( keys %{ $hash{foo} } ) { print $hash{bar}-{$key} }
 
 I would like to write
 
   for my $key ( $hash{foo}-keys ) { print $hash{bar}-{$key} }
 
 or even
 
   for my $key ( keys $hash{foo}-% ) { print $hash{bar}-{$key} }
 
 ... I'd find these easier to make sense of, though I've got a sneaking
 suspicion that I'm in a small minority there. But of course they'd be
 fun, because I could inflict them on unsuspecting readers of my code.

This, or something similar was hashed out on p5p, h, about 4 years
ago, give or take four years ;-)  Actually, I think it might have been
when Chip was Pumpking, which would have made it about five years ago.

You could search the archives.  I would have done had I been able to
think of something sensible to search for.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread Abhijit Menon-Sen

At 2002-04-16 20:16:17, [EMAIL PROTECTED] wrote:

 And no, saying perl5 will still be around isn't doing us much good.
 There won't be new development of perl5, or bug fixes.

There will. It'll just be slower than it is now.

- ams



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread Jonathan E. Paton

  And no, saying perl5 will still be around isn't doing us much good.
  There won't be new development of perl5, or bug fixes.
 
  Other languages will remain being developed and bugfixed. If perl6 is
  going to happen (I hope it won't), I'll be shopping for a new language.
  perl6 will just be one of the candidates.
 
  When the developmet/bug fixing of perl5 discontinues, what will happen if
  someone insists to continue the path. Perhaps with forking?
 
 Then the development/bug fixing of perl5 will not have
 discontinued. Perl5 development will only stop if people stop
 developing (tautology alert). Unless I'm greatly mistaken, Larry's not
 going to stop people who want to do that.

As I understand (as opposed to know first hand) these things:

Perl 5 will probably have a co-existant lifespan with Perl 6 for about 2-3
years.  It takes time for businesses to adopt new languages/versions for
their mission critical stuff.

One guy on [EMAIL PROTECTED] was running a 5.004 system, which he couldn't
upgrade without (multiple) committee approval.  He wanted to backinstall
OO based modules, which was a bit of a problem.

Also, a company I worked for last summer still used Perl 4 - as it was
packaged with a commerical program they used (ClearCase, Rational's SCM
tool).  In my experience with Perl, I'd say it is a stable language
despite it's complexity... and most bugs can be worked around.

Fretting over syntax changes is hardly worth it, provided it isn't a
significant departure from what we know and love.  Perl 5 threading
and scalability are significant issues.  If you use 20 modules in
your application, you have to wait for 20 modules to be parsed,
compiled, optimised and then run.

One of my hopes for Perl 6 is that Larry will squeeze PHP's
marketshare.  Why?  Most ISPs run Perl code under CGI, hence you are
forced to use PHP which is built-in to apache on most ISP systems.
If Perl 6 allows compilation to bytecode with optimisations, then
you might find mod_parrot installed on many more ISP systems.

Why mention this?  Well, the only way to add dynamic content to a
website would be for me to learn another, less flexible language -
I'd rather stick to something m/^Perl(?:5|6)$/, even if I have to
make a few changes to how I'd use it.

Perl 6 will happen, Larry's job at O'Rielly depends on him writing
and selling books :)  Changing the rules makes it easier to sell
more.  Most of Perl's syntax is the product of Larry's imagination,
either we like it or lump it.  I like Perl 5 thus far, and don't
think Larry is about change Perl 6 into COBOL/ADA/Befunge/Pascal
or whatever.

I think this thread should be moved to [EMAIL PROTECTED],
since it's kinda not fun.

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread David Wheeler

On 4/17/02 9:11 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] claimed:

 I find it amazing that someone can make a statement like 99% of the
 time, people leave whitespace of the aggregate and the index, just
 based on personal experience.
 
 Based on the code *I* have written in the past 20 years, more than
 99% of the time people do use whitespace between the aggregate and
 the index. ;-)

Must be a European thing. ;-)

 Seeing $hash{foo}{bar}{baz} all over,justmakeswewanttoignoreallwhitescape.
 Butthatissohardtoread.

Personally, I find C$hash{foo}{bar}{baz} a lot easier to read than
justmakeswewanttoignoreallwhitescape. The braces break it up nicely.
However, once I start to see code like that, I start to think it's time for
a redesign. I don't much care for seeing a hash access go more than two
layers deep.

 Using ()'s doesn't mean the parser suddenly understands %hash {key}
 is an indexing operator, so that's not going to solve much. :-(

That's true. But the trade-off is significant and, IME, totally worthwhile.
Braces with whitespace in front of them are now always closures. This adds a
great deal of power and flexibility to the design. But if some people just
are lamenting the loss of the whitespace in hash accesses because that's the
standard that C set long ago, the, to quote Larry,

If you want to program in C, program in C. It's a nice language. I use it
occasionally... :-)

--Larry Wall in [EMAIL PROTECTED]

Regards,

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread Bill -Sx- Jones

On 4/16/02 5:06 PM, Ton Hospel [EMAIL PROTECTED] wrote:

 It's very well possible that I'll stubbornly keep using perl5 if perl6
 comes out.
 

Maybe my (mis)understanding from Larry is that Perl 6 will provide a jumping
off platform into better language non-specific things that we may not see at
this time, but things that will become apparent as we start actually using
the new version.

Like being able to write XS in other languages for integration into Perl.

I for one don't understand Larry half the time, but I believe that is part
of him being a genius.

Hell, how long did 'People' moan and groan about Perl 4?  (I don't know, I
wasn't aware of Perl until Perl 5 was already out...)

Cheers :)
_Sx
  ('-Sx- IUDICIUM
  //\   Have Computer -
  v_/_Will Hack...





Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread Jonathan E. Paton

  It's very well possible that I'll stubbornly keep using perl5 if perl6
  comes out.
  
 
 Maybe my (mis)understanding from Larry is that Perl 6 will provide a jumping
 off platform into better language non-specific things that we may not see at
 this time, but things that will become apparent as we start actually using
 the new version.
 
 Like being able to write XS in other languages for integration into Perl.

Haven't you heard?  XS is getting dumped, that is one of the primary reasons for
developing Perl 6.

http://dev.perl.org/rfc/270.pod

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread abigail

On Wed, Apr 17, 2002 at 10:23:42AM -0700, David Wheeler wrote:
 On 4/17/02 9:11 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] claimed:
 
  I find it amazing that someone can make a statement like 99% of the
  time, people leave whitespace of the aggregate and the index, just
  based on personal experience.
  
  Based on the code *I* have written in the past 20 years, more than
  99% of the time people do use whitespace between the aggregate and
  the index. ;-)
 
 Must be a European thing. ;-)
 
  Seeing $hash{foo}{bar}{baz} all over,justmakeswewanttoignoreallwhitescape.
  Butthatissohardtoread.
 
 Personally, I find C$hash{foo}{bar}{baz} a lot easier to read than
 justmakeswewanttoignoreallwhitescape. The braces break it up nicely.
 However, once I start to see code like that, I start to think it's time for
 a redesign. I don't much care for seeing a hash access go more than two
 layers deep.

I agree. C$hash{foo}{bar}{baz} is horribly ugly. Your solution
is a redesign. My solution is to use whitespace. The latter is
far easier than the former.

  Using ()'s doesn't mean the parser suddenly understands %hash {key}
  is an indexing operator, so that's not going to solve much. :-(
 
 That's true. But the trade-off is significant and, IME, totally worthwhile.
 Braces with whitespace in front of them are now always closures. This adds a
 great deal of power and flexibility to the design.

I think the gain is just the option of not having to write () in if.
If () was still mandatory, there would be no ambiguity when a block
is a hash index and when it cannot be - which means it has to be a
closure.

But if some people just
 are lamenting the loss of the whitespace in hash accesses because that's the
 standard that C set long ago, the, to quote Larry,

It's not just C. It's also any language than I've programmed in.
It's also a rather significant break from 14 years of perl.



Abigail



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread David Wheeler

On 4/17/02 12:53 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] claimed:

 I think the gain is just the option of not having to write () in if.
 If () was still mandatory, there would be no ambiguity when a block
 is a hash index and when it cannot be - which means it has to be a
 closure.

Well, that was a side-effect of Larry not wanting an extra unnatural
delimiter -- e.g., parentheses -- for switch statements. He feels, as a
linguist, that it reads better. I agree that it's subjective, though, and
some will mourn the affect that the loss of parentheses has on hash
subscripting. I, however, will not.

 It's not just C. It's also any language than I've programmed in.
 It's also a rather significant break from 14 years of perl.

I agree that it's a break, but maybe because I almost never use whitespace
for hash subscripting, it doesn't seem like a big deal to me. And I'm happy
to leave out the parentheses. But again, it's subjective.

Regards,

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-17 Thread Piers Cawley

[EMAIL PROTECTED] writes:

 On Wed, Apr 17, 2002 at 10:23:42AM -0700, David Wheeler wrote:
 On 4/17/02 9:11 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] claimed:
 
  I find it amazing that someone can make a statement like 99% of
  the time, people leave whitespace of the aggregate and the
  index, just based on personal experience.
  
  Based on the code *I* have written in the past 20 years, more
  than 99% of the time people do use whitespace between the
  aggregate and the index. ;-)
 
 Must be a European thing. ;-)
 
  Seeing $hash{foo}{bar}{baz} all
  over,justmakeswewanttoignoreallwhitescape.
  Butthatissohardtoread.
 
 Personally, I find C$hash{foo}{bar}{baz} a lot easier to read
 than justmakeswewanttoignoreallwhitescape. The braces break it up
 nicely.  However, once I start to see code like that, I start to
 think it's time for a redesign. I don't much care for seeing a hash
 access go more than two layers deep.

 I agree. C$hash{foo}{bar}{baz} is horribly ugly. Your solution
 is a redesign. My solution is to use whitespace. The latter is
 far easier than the former.

You still can. Just use the '.'

$hash{foo}{bar}{baz} # Before, ugly.

# After. Less ugly.
$hash{foo}
.{bar}
.{baz}

There's still a design issue, if you're doing this as a way of
accessing a 3 dimensional structure then Perl6 is probably going to be
offering syntax along the lines of C$hash{foo ; bar ; baz}, allowing
for more complex slicing (but at the moment that's just tealeaf
reading on my part).

Personally I like the fact that if you add space you need to add
something to disambiguate, but then, I'd likely rewrite the ugly
version into 

$hash{foo}
   -{bar}
   -{baz}

in Perl 5. 

-- 
Piers

   It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite.
 -- Jane Austen?




Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-16 Thread David Wheeler

On 4/16/02 7:43 AM, Griffith, Shaun [EMAIL PROTECTED] claimed:

 So I take it readability is deprecated?
 
 For instance:
 
 $some_nested_hash{very_long_descriptive_key}{another_key}...{last_key}
 
 can no longer be broken into multiple lines, like this?
 
 $some_nested_hash{very_long_descriptive_key}
  {another_key}
  ...
  {last_key}
 
 Or does it depend on whether {some_key} looks like a statement block or
 not?

IIUC, the no whitespace rule only applies before control structure blocks,
such as if {} and while {}, because you need the space before the opening
brace. In other spaces, it's not necessary. So while you'll need to do this:

  %some_nested_hash{very_long_descriptive_key}
 {another_key}
 ...
 {last_key} = 'foo';

You'll have to do this for control blocks:

if %some_nested_hash{very_long_descriptive_key}{another_key}...{last_key} {
# do stuff
}

But if you really want to improve legibility, and you find you have a lot of
this sort of thing in your code, I suggest you make a shortcut:

  my %scut = %some_nested_hash{very_long_descriptive_key}{another_key}{one};

  if %scut.{last_key} { # Perl 6 hashref syntax.
  # do stuff
  }

Regards,

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-16 Thread Stephen Turner

On Tue, 16 Apr 2002, David Wheeler wrote:

 So while you'll need to do this:
 
   %some_nested_hash{very_long_descriptive_key}
  {another_key}
  ...
  {last_key} = 'foo';
 
 You'll have to do this for control blocks:
 
 if %some_nested_hash{very_long_descriptive_key}{another_key}...{last_key} {
 # do stuff
 }
 


Ugh, ugh, ugh, that's even worse.

Am I the only person who gets more scared of Perl 6 the more he hears about
it?

Still waiting for the regexp apocalypse with a mixture of hope and fear...

-- 
Stephen Turner, Cambridge, UKhttp://homepage.ntlworld.com/adelie/stephen/
This is Henman's 8th Wimbledon, and he's only lost 7 matches. BBC, 2/Jul/01




Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-16 Thread abigail

On Tue, Apr 16, 2002 at 09:03:14AM -0700, David Wheeler wrote:
 On 4/16/02 7:43 AM, Griffith, Shaun [EMAIL PROTECTED] claimed:
 
  So I take it readability is deprecated?
  
  For instance:
  
  $some_nested_hash{very_long_descriptive_key}{another_key}...{last_key}
  
  can no longer be broken into multiple lines, like this?
  
  $some_nested_hash{very_long_descriptive_key}
   {another_key}
   ...
   {last_key}
  
  Or does it depend on whether {some_key} looks like a statement block or
  not?
 
 IIUC, the no whitespace rule only applies before control structure blocks,
 such as if {} and while {}, because you need the space before the opening
 brace.

Eh, no. You got it backwards. It's not that you need a space before
a control block, it is that If you put a space before a {, it *IS*
a control block.

It's the space that determines what follows is a control block.

In other spaces, it's not necessary.

It's not that it isn't necessary. It's forbidden. Unlike in C, awk, 
Java, Pascal, or even in the language of the whitespace, Python. Any
language I can remember programming in in the last 2 decades allows
optional whitespace between the aggregate and the index, without
parsing things differently.

In other spaces, it's not necessary. So while you'll need to do this:
 
   %some_nested_hash{very_long_descriptive_key}
  {another_key}
  ...
  {last_key} = 'foo';

That's a syntax error. You've some stuff in void context, and then
you're assigning something to a block. 

 You'll have to do this for control blocks:

The problem is, because the ()'s are dropped, the parser cannot know
where the control block starts, hence the new rule any opening brace
following whitespace will be a block.

 if %some_nested_hash{very_long_descriptive_key}{another_key}...{last_key} {
 # do stuff
 }
 
 But if you really want to improve legibility, and you find you have a lot of
 this sort of thing in your code, I suggest you make a shortcut:
 
   my %scut = %some_nested_hash{very_long_descriptive_key}{another_key}{one};
 
   if %scut.{last_key} { # Perl 6 hashref syntax.
   # do stuff
   }


Having to *add* code isn't actually making a shortcut, is it? ;-)



Abigail



RE: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-16 Thread Ala Qumsieh


Stephen Turner writes:
 Am I the only person who gets more scared of Perl 6 the more 
 he hears about
 it?

No you're not. I'm sure many people, myself included, share the same mixed
feelings towards Perl 6. I don't even feel comfortable calling it Perl
anymore.

 Still waiting for the regexp apocalypse with a mixture of 
 hope and fear...

Somehow, hearing Damian shout You will love the new syntax at the last
YAPC, wasn't enough. I still feel some animosity towards Perl 6; like its
gonna take over Perl 5 completely. A feeling not very different from that I
have towards Python!

--Ala



Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-16 Thread Piers Cawley

Griffith, Shaun [EMAIL PROTECTED] writes:

 Abigail wrote:
 What am I missing?


What you are missing is the new white space rule:

\s+{ }

shall be always be a block. Hence the difference between
%hash {foo} and %hash{foo}.

 So I take it readability is deprecated?

 For instance:

   $some_nested_hash{very_long_descriptive_key}{another_key}...{last_key}

 can no longer be broken into multiple lines, like this?

   $some_nested_hash{very_long_descriptive_key}
{another_key}
...
{last_key}

I *think* you can't do that as written. However, you can disambiguate
with 

   %some_nested_hash{very_long_descriptive_key}
   .{another_key}
...
   .{last_key}

The '.' operator is optional in cases where there's no ambiguity, when
you have intervening spaces things start to get ambiguous, so use an
explicit '.'

-- 
Piers

   It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite.
 -- Jane Austen?




Re: Whitespace and Blocks (was RE: Fisher-Yates shuffle)

2002-04-16 Thread Ton Hospel

In article Pine.LNX.3.96.1020416171808.1438C-10@gentoo,
Stephen Turner [EMAIL PROTECTED] writes:
 
 Am I the only person who gets more scared of Perl 6 the more he hears about
 it?
 
Nope. What I've heard about it 'till now I don't particularly like.
It's very well possible that I'll stubbornly keep using perl5 if perl6
comes out.