Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: use has it's own scope?

by sundialsvc4 (Abbot)
on Aug 08, 2017 at 14:51 UTC ( [id://1196994]=note: print w/replies, xml ) Need Help??


in reply to Re^2: use has it's own scope?
in thread use has it's own scope?

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^4: use has it's own scope?
by chromatic (Archbishop) on Aug 08, 2017 at 15:27 UTC
    Even though it is correct

    It is not correct. Your examples prove that you're wrong.

    strict's error message is that strict doesn't understand the LIST arguments. Perl understands them just fine. The set error message is that Perl didn't find a set.pm module. Perl understood the LIST arguments just fine.

    Please stop posting nonsense. You're wasting time and hurting people who don't know enough to ignore your ignorance.

    Update: I reread this and realized the nonsense went even deeper.

    The intended declaration of $y did not succeed

    Indeed it did. That's why strict complains about the unrecognized tag '666'.

    There is probably a “hole” in the BNF grammar within the interpreter.

    Utter nonsense, which proves you didn't bother to look at the grammar at all.

    First of all, there's no "BNF grammar" in the interpreter. There's a parser and a lexer which you could, if you were enterprising enough, potentially represent in Backus-Naur Form, but it's not expressed as such anywhere within the Perl source code, and there is no singular representation of grammar within the Perl source.

    Second of all, you're expressing surprise that assignment is an expression. In other words, by your logic, the fact that $x = $y = $z works is an unanticipated accident of implementation that should be fixed. Similarly, (my $x = $y) =~ s/\A\s+|\s+\Z//g; should not work, in your incorrect interpretation of Perl.

    Arguably, you could be complaining that lexical declaration should not be allowed in expressions, which is still a silly point given the en-passant assignment and substitution technique of the previous snippet, but witness:

    sub main { foo(my $x = 1); say $x; return 0; } sub foo { say ++$_[0] . ' in foo'; }

    ... or:

    sub main { bar(my $x); say $x; return 0; } sub bar { $_[0] = 'assigned in bar'; }

    Should you write code like that? I think we all know the answer—but let's not delude ourselves into pretending that this is some unintentional side effect of implementation. Assignment-as-expression semantics, along with compile time variable declaration, are well established in Perl. Misunderstand them at your own peril.

      Oh, man. When chromatic slaps you down, you know you're past due for some serious introspection.

        Oh, man. When chromatic slaps you down, you know you're past due for some serious introspection.

        obvious self deception is obvious

      Simpler examples of declaration inside of an expression:

      open(my $fh, ...)
      ( my $x = $y ) =~ s/.../.../;
Re^4: use has it's own scope?
by Anonymous Monk on Aug 08, 2017 at 15:21 UTC
    If you had actually read the original post, you might have noticed that the OP did, in fact, create a module called set.pm. The syntax use set my $y =666; is actually valid, but it's also useless because $y goes out of scope immediately. Arguably it should be disallowed, but nobody cares.
      Arguably it should be disallowed

      Why? LIST here is the standard argument passing mechanism. Making an exception for a my expression in an argument list or making an exception for expressions in import lists would be complicated and break symmetry of syntax, semantics, and implementation.

      This is the piece that sundial's missing. It's a confusing combination of existing Perl behavior because it's uncommon and relatively useless, but it's valid syntax because of the way Perl works.

        Actually, I agree with you -- I didn't say I would be the one to make that argument ;-)

        Maybe I should have suggested that it could arguably be a warning. Perl warns on all kinds of things that are valid but "potentially confusing," and there seems to be a fair amount of back-and-forth about what those things are.

Re^4: use has it's own scope?
by Anonymous Monk on Aug 08, 2017 at 14:59 UTC
    Frankly my dear, you're full of it. Stop posting crap.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found