Replies: 2 comments 5 replies
-
as far as Perl doesn't have representation for void, and common pattern is such method should anyway evaluate as undef in scalar context and empty list in list context, inability to |
Beta Was this translation helpful? Give feedback.
-
VOID can be CONTEXT_MAYBE_VOID and CONTEXT_MUSTBE_VOID, as it is a condition on the calling-context. In void context, the thing is free to return any value, as it will just be ignored. Also consider CONTEXT_LIST and CONTEXT_SCALAR. See wantarray(). Also be aware that if there is a die() or an exit() (or POSIX::_exit, or exec(), etc.) involved, a sub ends without returning a useful value. |
Beta Was this translation helpful? Give feedback.
-
When typing out example code, I often find myself typing this:
I hate typing and explaining the
& !VOID
because it's usually not the point of the example, so sometimes I skip that. But that makes me uncomfortable because any time I have a return type, I pretty much assume that it needs to be used in some way, or else the return type doesn't make sense. In fact, for most of my code, this is the case, with the exception of chained mutators (see below).I was thinking what does make sense is for any
returns
to assume& !VOID
by default. Instead, if you wish to allow it to be called in void context, you express that:From the above, with Corinna syntax,
set_value
can be a chained mutator, but it's ok to to call it standalone, in void context.Beta Was this translation helpful? Give feedback.
All reactions