Issue #17004 has been updated by shyouhei (Shyouhei Urabe).


Re: other languages with similar concepts.

- Perl has `wantarray`.  In spite of its name, the intrinsic can be used to distinguish if a return value is needed or not (can tell you if the needed number of return values is zero, one, or many more).
- If we consider warnings on unused return values be a kind of it...
    - C++ since C++17 has `[[nodiscard]]` function attribute.
    - GCC provides something similar to C as well.
    - In Rust that attribute is called `#[must_use]`.
    - Swift has such warnings default on, and must explicitly annotate a function with `@discardableResult` if you allow users to ignore them.

----------------------------------------
Feature #17004: Provide a way for methods to omit their return value
https://bugs.ruby-lang.org/issues/17004#change-86400

* Author: shyouhei (Shyouhei Urabe)
* Status: Open
* Priority: Normal
----------------------------------------
In ruby, it often is the case for a method's return value to not be used by its caller.  Even when a method returns something meaningful, its caller is free to ignore it.

Why not provide a way for a method to know if its return value is needed or not?  That adds a room for methods to be optimized, by for instance skipping creation of complex return values.

The following pull request implements `RubyVM.return_value_is_used?` method, which does that: https://github.com/ruby/ruby/pull/3271



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>