in reply to Re^4: How to enforce void context in Reply?
in thread How to enforce void context in Reply?

But doesn't just calling  foo() in void context
    foo();
enforce void context upon the invocation of foo()? What need for anything else?

Is it ever possible to get a value directly returned from a subroutine invoked in void context, whether "enforced" or "natural" (as in the example above)? (Of course, it's always possible to indirectly return values from subroutines invoked in void context.)


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^6: How to enforce void context in Reply?
by Anonymous Monk on May 19, 2015 at 14:55 UTC
    What need for anything else?

    True, but it can still happen by accident that a sub is executed in non-void context when the programmer wanted it in void context, as shown above in sub calls_it_1. Also docdurdee mentioned a REPL, so my guess would be that the REPL puts every line entered at the prompt into some non-void context.

      All the more reason to avoid implicit return statements.

      sub Sa { foo(); # implicit return: foo() called in Sa() invocation context +. } sub Sb { return foo(); # explicit return: foo() called in Sb() invocation +context. } sub Sc { foo(); # foo() called in void context. no question. return; }
      IMHO, the Sa() form should always be avoided.

      And also IMH (but very emphatic!) O, one should certainly avoid weird "implicit return of 1" statements which are no more than maintainence pitfalls.


      Give a man a fish:  <%-(-(-(-<

        IMHO, the Sa() form should always be avoided.

        Why? I can't think of a single problem that solves.

        :) I missed it too but Reply is reply - read, eval, print, loop, yay!

        1; is shorter than return;