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

I think we mostly agree.

I read up the WP pages on statement and expression and it becomes clear that it's far easier to make a distinction in languages like C.

But Perl took also a lot from Lisp, where everything is an expression returning a value.

Quote: "In languages that mix imperative and functional styles, such as the Lisp family, the distinction between expressions and statements is not made: even expressions executed in sequential contexts solely for their side effects and whose return values are not used are considered 'expressions'"

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

And it's also a statement, because

Update

OTOH does A and B (= do { if (A) {B} } ) have the side-effect of flow-control, because it's short-circuiting.

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

Replies are listed 'Best First'.
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

    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.

      > 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.