[#85940] [Ruby trunk Bug#14578] Forking a child process inside of a mutex crashes the ruby interpreter — ben.govero@...
Issue #14578 has been reported by bengovero (Ben Govero).
3 messages
2018/03/05
[#86205] [Ruby trunk Feature#14618] Add display width method to String for CLI — aycabta@...
Issue #14618 has been reported by aycabta (aycabta .).
3 messages
2018/03/19
[#86366] Re: [ruby-cvs:70102] usa:r63008 (trunk): get rid of test error/failure on Windows introduced at r62955 — Eric Wong <normalperson@...>
usa@ruby-lang.org wrote:
3 messages
2018/03/28
[ruby-core:86315] [CommonRuby Feature#13581] Syntax sugar for method reference
From:
pvande@...
Date:
2018-03-26 21:43:32 UTC
List:
ruby-core #86315
Issue #13581 has been updated by pvande (Pieter van de Bruggen).
As a blue sky alternative, why not consider something like this:
~~~ ruby
[1, 2, 3].map(&> {Math.sqrt})
# or perhaps more simply
[1, 2, 3].map(&> Math.sqrt)
~~~
Pros:
* It's clean
* It's readable
* It reads like passing a block
* Specifically, passing a lambda as a block
* It *also* reads something like the Elixir pipe operator
Cons:
* It's only *looks* like Ruby code
* Is `x.map(&> { a.b.c.d ; Math.sqrt })` valid? (I hope not.)
* Is `x.map(&> do; Math.sqrt; end)` valid? (I hope not.)
* Is `x.map(&> { begin; rescue; end })` valid? (I hope not.)
* Is `x.map(&> { Math.sqrt if x })` valid? (I hope not.)
* Is `x.map(&> { Math.sqrt rescue nil })` valid? (I hope not.)
* It's not actually a shorthand for `Object#method`.
* The two clearest implementation paths are as a "macro", and as an "atypical evaluation context"
* The macro approach simply transforms the code into a "proper" block, and passes the argument implicitly (see below for an example)
* The other approach requires the interpreter to all non-terminal method calls, then produce a block invoking the terminal call with the yielded argument (see below for an example)
Despite the "oddness" of this particular syntax, I think the clarity of expression is very much inline with the Ruby ideals, and is therefore worth discussing.
**Macro Example**
~~~ruby
fn(&> { a.b.c.d })
# => fn() { |__x| a.b.c.d(__x) })
~~~
**Atypical Evaluation Example**
~~~ruby
fn(&> { a.b.c.d })
# => __target = a.b.c; fn() { |__x| __target.d(__x) })
~~~
----------------------------------------
Feature #13581: Syntax sugar for method reference
https://bugs.ruby-lang.org/issues/13581#change-71235
* Author: americodls (Americo Duarte)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Some another programming languages (even Java, in version 8) has a cool way to refer a method as a reference.
I wrote some examples here: https://gist.github.com/americodls/20981b2864d166eee8d231904303f24b
I miss this thing in ruby.
I would thinking if is possible some like this:
~~~
roots = [1, 4, 9].map &Math.method(:sqrt)
~~~
Could be like this:
~~~
roots = [1, 4, 9].map Math->method
~~~
What do you guys thinking about it?
--
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>