Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^18: printing unitialized value of the 'do BLOCK' (EXPRESSION vs TERM vs STATEMENT)

by ikegami (Patriarch)
on Dec 28, 2019 at 13:57 UTC ( [id://11110696]=note: print w/replies, xml ) Need Help??


in reply to Re^17: printing unitialized value of the 'do BLOCK' (EXPRESSION vs TERM vs STATEMENT)
in thread printing unitialized value of the 'do BLOCK'

So Perl's if is an expression, especially when executed in a scalar or list context due to a surrounding do.

No.

Again, the condition of an if statement is defined to be an expression, so

if ( ... ) { ... }

isn't an expression because

if ( if ( ... ) { ... } ) { }

isn't valid.

Furthermore, if any statement is an expression because any statement can be found at the end of the block of a do BLOCK, then the paragraph that's been quoted saying that the returned value is only defined for expressions wouldn't make sense.

Your usage of the terms clearly differs from the documentation's.

Replies are listed 'Best First'.
Re^19: printing unitialized value of the 'do BLOCK' (EXPRESSION vs TERM vs STATEMENT)
by LanX (Saint) on Dec 28, 2019 at 17:20 UTC
    > Your usage of the terms clearly differs from the documentation's.

    Depending on the definition you take

    I'd say according to perlglossary it must be parsable without surrounding do {}

  • expression

    Anything you can legally say in a spot where a value is required. Typically composed of literals, variables, operators, functions, and subroutine calls, not necessarily in that order.

  • But according to WP expression, the defining characteristic is returning a value

    An expression in a programming language is a combination of one or more constants, variables, operators, and functions that the programming language interprets (according to its particular rules of precedence and of association) and computes to produce ("to return", in a stateful environment) another value.

    I'd compromise on "statement which can be used like an expression to produce values".

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Depending on the definition you take

      Yes. I clearly said it doesn't make sense for your definition.

      I'd compromise on "statement which can be used like an expression to produce values".

      I presume you are saying this is what an if statement is. It's not. You can't count on it returning anything according to the documentation, and a provided example demonstrated this.

        > You can't count on it returning anything according to the documentation, and a provided example demonstrated this.

        The only examples I remember seeing demonstrate syntax errors, when if isn't used in a statement spot.

        Do you have an example where if doesn't return a value as last statement inside inside a do, eval or sub {BLOCK} or similar?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-18 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found