Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^5: If you believe in Lists in Scalar Context, Clap your Hands

by ig (Vicar)
on Oct 29, 2008 at 18:47 UTC ( #720291=note: print w/replies, xml ) Need Help??

in reply to Re^4: If you believe in Lists in Scalar Context, Clap your Hands
in thread If you believe in Lists in Scalar Context, Clap your Hands

I don't mean to be argumentative, but I am as yet unconvinced that the rules I gave are unworkable in practice.

To begin on a positive/agreeable note... you say:

What looks like a list to a casual reader is often not the list that Perl sees

I agree completely. And this problem is exacerbated by the lack of a clear definition of what is a LIST in the Perl documentation.

Many people might say that 1, 2, 3 is a list...

The rule I gave is a rule for evaluating a LIST in scalar context. It is not a rule for determining what part of a statement is a LIST or what the elements of the LIST are.

Other rules are required to determine what is a LIST and your example illustrates some of the complexity of doing so. It does not convince me that the rule I gave is unworkable in practice.

While some statements are difficult to parse, others are simple. The use of optional parentheses can simplify the task which otherwise, as you point out, requires an intimate knowledge of precedence and other rules.

The fact that some statements are difficult to parse does not mean that there is no such thing as a LIST in scalar context.

...they get optimized away...

The rule I gave was a rule describing the semantics of Perl, not the algorithms of perl. That perl can and does use optimized algorithms for executing Perl programs is a good thing as long as it remains consistent with the syntax and semantics of Perl. I don't agree that an optimization in perl for some particular case makes the rule I gave unworkable in practice.

(Besides that, this proves that the general rule "A list in scalar context evaluates to its final element" is wrong, too.)

I don't understand how it proves this. Can you explain further?

The value of any expression evaluated in void context is discarded. This does not invalidate a rule defining what the value of the expression is. That perl is optimized to skip steps that have no side effects when evaluating an expression in void context does not, in my opinion, have any bearing on what the value of a LIST in scalar context is.

I am talking about the semantics of Perl and you seem to be talking about the operation of perl. It is natural then that we should have different opinions about what is or isn't and what happens.

Update: fixed a typo in the last sentence

  • Comment on Re^5: If you believe in Lists in Scalar Context, Clap your Hands

Replies are listed 'Best First'.
Re^6: If you believe in Lists in Scalar Context, Clap your Hands
by chromatic (Archbishop) on Oct 29, 2008 at 19:28 UTC
    I am talking about the semantics of Perl and you seem to be talking about the operation of perl.

    Where do you think the semantics of Perl come from? The holy writ of magic candy-flavored flying unicorns? (However more maintainable that might be, there are actual and deterministic algorithms behind those semantics, which is sort of exactly precisely what people expect from a programming language.)

    Feel free to argue with you think the semantics of Perl should be. Unless they match the documented and tested and empirically verifiable behavior of multiple versions of Perl, they're wrong, and you're wasting your time.

    However much someone used to Python might think that parentheses make a list of constant expressions into a list in Perl, they don't. They merely group the expressions to disambiguate intended precedence. Perl's semantics aren't a matter of anyone's fiat, unless you want to anthropomorphize the code.

      I am increasingly inclined to agree with you, that Perl is not a language in its own right but merely a description of what some perl program does.

      Even so, abstractions can facilitate use and understanding. Perl and perl should be consistent, but to the extent that Perl is an abstraction rather than the full source code, it comes from people trying to understand and explain perl rather than from perl itself.

      In addition to facilitating understanding and use, elaboration of simple and unsurprising abstractions can help to identify ways in which perl and Perl might be improved. What it could and possibly should be is not what it is, but that doesn't mean discussing these possibilities is a waste of time. Without such discussion, there would be little basis for deciding what do do in the next release.

      This particular Meditation may never inform or motivate an improvement in perl, but some do. Or are the developers of perl so remote from PerlMonks that nothing here makes any difference to what they do?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://720291]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-06-21 01:29 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.