Project

General

Profile

Actions

Feature #16898

open

Modify the syntax of -> lambda expressions in ruby3

Added by jackmaple (maple jack) over 4 years ago. Updated over 4 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:98406]

Description

Hello ruby team.
Can we modify the syntax of lambda expressions in ruby3?
The current definition of lambda expression was added in ruby1.9, but this syntax looks too tedious.

lambda {|x| x + 1}   #This looks elegant.
#but...In lambda expression body, when there is only one line of statement
-> x {x + 1}    #Can the braces be removed?
-> x do x + 1 end  #As above, can the do ... end block be removed?

So are we going to abandon some historical issues? To modify -> lambda syntax?
It looks like this:

x -> x + 1
(x,y) -> x + y
x -> y -> x + y
x -> {
   x + 1
   x + 2
}

I think do..end or braces are only needed when there are multiple lines of code,lambda expression if there is only one statement should not need parentheses or do ... end block.
Thanks.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0