Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^5: Perl oddities ("if" w/o parens)

by lidden (Deacon)
on Mar 01, 2005 at 23:50 UTC ( #435653=note: print w/ replies, xml ) Need Help??

in reply to Re^4: Perl oddities ("if" w/o parens)
in thread Perl oddities

He said:

I'm not saying that perl6 in general (or making parens optional in + specific) is a bad idea.
so I think hi got it.

I think it is great to get rid of the ()'s. I am still not sure if i like the new scoping rules though.
if my ($i) = / ^ (f+) / { # Do stuff } say $i; # $i still defined.
Good, Bad, Ugly... ?

Comment on Re^5: Perl oddities ("if" w/o parens)
Select or Download Code
Re^6: Perl oddities ("if" w/o parens)
by TimToady (Parson) on Mar 02, 2005 at 00:50 UTC
    The scoping rules are much simpler now. And because blocks are closures, you can pass parameters to them, which are scoped to the block. So you could write your statement like this:
    if /^ (f+) / -> *$i { # Do stuff }
    where the * on the parameter list treats the pattern match result as binding to a list value, so the search result acts like a list value and binds $1 to $i. And arguably it's more readable because it puts the first thing that happens, the pattern match, out front. The parameter binding only happens if the pattern match succeeds.

    Or look at it another way. Suppose you run into a new control construct:

    frob my $x = bar() {...}
    Tell me quick whether $x is local to that block? In the Perl 5 world, you don't know for sure, because the scoping rules are arbitrary, and change between builtins and user-defined control verbs. In the Perl 6 world you know it isn't local, because the my isn't inside the block. Period. On the other hand, if you see
    frob bar() -> $x {...}
    then you absolutely know that $x is local because it's explicitly being passed as a parameter.

    I think people who initially perceive this as Bad or Ugly will eventually come around to seeing it as Kinda Pretty.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://435653]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-08-30 15:26 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (293 votes), past polls