develooper Front page | perl.perl6.language | Postings from January 2002

Re: Apoc4: The loop keyword

Thread Previous | Thread Next
From:
rjcox
Date:
January 26, 2002 09:44
Subject:
Re: Apoc4: The loop keyword
Message ID:
memo.20020126174408.1372B@rjcox.compulink.co.uk
In article <20020125114035.A23668@cbi.tamucc.edu>, duff@cbi.tamucc.edu 
(Jonathan Scott Duff) wrote:
> On Fri, Jan 25, 2002 at 11:57:25AM +0100, Bart Lateur wrote:
> > On Mon, 21 Jan 2002 15:43:07 -0500, Damian Conway wrote:
> > 
> > >What we're cleaning up is the ickiness of having things declared 
> > outside
> > >the braces be lexical to the braces. *That's* hard to explain to 
> > beginners.
> > 
> > But it's handy. And that was, until now, what mattered with Perl.
> 
> No, handiness still matters with Perl. It's just that the balance has
> tipped a wee bit towards the consistency/regularity/simplicity/whatever
> side of the scale. 
> 
> Besides no one has commented on Steve Fink's (I think it was him) idea
> to store the result of the most recently executed conditional in $?. I
> kinda like that idea myself. It makes mnemonic sense.
> 
> But then I'm sure that someone will come out of the woodwork and say
> "What about if ((my $a = foo()) && ($b < 4)) ?" or something.  To
> which I'd say "Fooey!"  I personally don't think that an extra set of
> curlies are too high a price for getting rid of weird scoping rules.
> But that's just me.


As someone how comes from the C++ world, I'm really glad that C99 saw 
sense and added

if (int i = x()) {
    // i in scope here
    ...
}

// i not in scope here

and therefore was really disappointed that Larry wants to take it out of 
Perl. The argument about consistency ("only variables declared in a block 
go out of scope at the end of that block") is valid, but of course Perl6 
will not always be following that rule anyway.

The exception is function declarations, named parameters will be declared 
outside the statement block that forms the body of the function; yet will 
be scoped to that block.

For example, I really don't think that &closure and @fileList are expected 
to have file scope (for want of a better term), after declaring a function 
such as:

sub attempt_closure_after_successful_candidate_file_open
        (&closure, @fileList) {
    #...
}

(From about half way through Apoc4).


If we already have one case where the rule is actually "only variables 
declared in a block or in its 'controlling statement' go out of scope at 
the end of that block", so why not make that the general rule and allow 
code such as

while (defined(my $line = $file.readline())) {
    # ...
}

not to interfere with code elsewhere in the block that may use a variable 
called $line (it certainly makes maintenance easier to add a variable with 
out extraneous braces but to have a tightly contained scope).



-- 
rjcox@cix.co.uk

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About