Newsgroups: perl.perl6.language Path: g2news1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.perl.org Return-Path: Mailing-List: contact perl6-language-h...@perl.org; run by ezmlm Delivered-To: mailing list perl6-langu...@perl.org Received: (qmail 19834 invoked from network); 27 Jun 2004 21:16:15 -0000 Received: from x1.develooper.com (63.251.223.170) by onion.develooper.com with SMTP; 27 Jun 2004 21:16:15 -0000 Received: (qmail 27685 invoked by uid 225); 27 Jun 2004 21:16:15 -0000 Delivered-To: perl6-langu...@perl.org Received: (qmail 27678 invoked by alias); 27 Jun 2004 21:16:14 -0000 X-Spam-Status: No, hits=-4.9 required=8.0 tests=BAYES_00 X-Spam-Check-By: la.mx.develooper.com Received: from Unknown (HELO babylonia.flatirons.org) (161.97.199.99) by la.mx.develooper.com (qpsmtpd/0.27.1) with ESMTP; Sun, 27 Jun 2004 14:16:13 -0700 Received: from babylonia.flatirons.org (localhost.localdomain [127.0.0.1]) by babylonia.flatirons.org (8.12.10/8.12.10) with ESMTP id i5RLGBAl003257; Sun, 27 Jun 2004 15:16:11 -0600 Received: (from fibonaci@localhost) by babylonia.flatirons.org (8.12.10/8.12.10/Submit) id i5RLGBxp003255; Sun, 27 Jun 2004 15:16:11 -0600 Date: Sun, 27 Jun 2004 15:16:11 -0600 To: Alexey Trofimenko Cc: perl6-langu...@perl.org Subject: Re: if, loop, and lexical scope Message-ID: <20040627211611.GB3013@babylonia.flatirons.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-Virus-Scanned: clamd / ClamAV version 0.72, clamav-milter version 0.72 on localhost X-Virus-Status: Clean X-Spam-Rating: onion.develooper.com 1.6.2 0/1000/N Approved: n...@nntp.perl.org From: l...@luqui.org (Luke Palmer) Alexey Trofimenko writes: > 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. Yep. Except in the case of routine parameters, but that's nothing new. > > so, my question is, what the scope of variables, defined in C and > C 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 Precisely. > [...] > 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? Yep. > I feel that I will write things like: > > {loop (my $i=1;$i<10;$i++) { > ... > }} No you won't, for a couple reasons. First, you'd instead be writing: for 1..9 -> $i { ... } It's quite surprising how very many cases where you'd need loop can be done with the new for. Since $i is a sub parameter, it's only scoped to the block of the loop. But anyway, if you still want to be old school about it, then you'll end up not caring about the scope of your $i. Really you won't. And you'll be happy that it was kept around for you once you decide you want to know the value of $i for which the loop terminated. Luke > But I really hope that I missed something important, stating that theese > curlies are not necessary.