Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion if, loop, and lexical scope
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alexey Trofimenko  
View profile  
 More options Jun 27 2004, 12:57 pm
Newsgroups: perl.perl6.language
From: la-tr...@yandex.ru (Alexey Trofimenko)
Date: Sun, 27 Jun 2004 20:57:53 +0400
Local: Sun, Jun 27 2004 12:57 pm
Subject: if, loop, and lexical scope

AFAIR, I've seen in some Apocalypse that lexical scope boundaries will be  
the same as  boundaries of block, in which lexical variable was defined.

so, my question is, what the scope of variables, defined in C<if> and  
C<loop> conditions?

in perl5:

   my $a="first\n";
   if (my $a="second\n") {print $a}
   print $a;

prints

   second
   first

if I got it right, in perl6 same program will print

   second
   second

or will emit warning about redeclaring variable in the same scope..
sad. In C<if> case it isn't so significant, but what about C<loop>?

cite from Apocalypse4:
  ...
  The continue block changes its name to NEXT and moves inside the block it
  modifies, to work like POST blocks. Among other things, this allows NEXT
  blocks to refer to lexical variables declared within the loop, provided  
the
  NEXT block is place after them. The generalized loop:
     loop (EXPR1; EXPR2; EXPR3) { ... }
  can now be defined as equivalent to:
     EXPR1;
     while EXPR2 {
         NEXT { EXPR3 }
         ...
     }
  ...

so,

   loop (my $i=1;$i<10;$i++) { ... }

will declare $i for the rest of the block, in which loop is placed, won't  
it?

I feel that I will write things like:

   {loop (my $i=1;$i<10;$i++) {
       ...
   }}

But I really hope that I missed something important, stating that theese  
curlies are not necessary.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.