You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
我觉得没有必要单独为迭代器设计一个特殊语法。首先不能迭代器和index混用,其次如果要求有返回值(如map函数那样收集一个列表)还需要引入
yield
,最后它可以用lambda表达式取代。目前可以设计的lambda表达式大致有两种形式:
(x)->{return x}
简写x->x
{x->x}
list("number",{x->x+1})
等价于list("number"){x->x+1}
,在函数单参数为lambda表达式时可以写作list {x->x+1}
。此外,因为分隔界限为{}
,所以当lambda表达式没有参数或者单参数(用it代替)可以省略箭头部分,例如list("number"){it+1}
。->
分隔似乎不太明显?如{f:(Int)->Int,x->f(x)}
。目前来说,希望设计成
(x){return x}
。这样可以和函数的定义相统一,但是不能被当作尾lambda用。但是如果配合上单参数不加括号的函数调用,可以实现foreach (x){return x}
这样的结构。因此for-in表达式可以写成:
另外我还有在函数统一调用下的设想:
Beta Was this translation helpful? Give feedback.
All reactions