Actionscript3 是否提供列表推导式或 lambda 演算?
我正在将我在 python 中原型化的一些代码移植到 flash,虽然 actionscript 并不像我预期的那么糟糕(我听说 v3 比 v2 好很多!),但我仍然需要做一些事情看起来过于平淡/样板,例如对列表进行求和...
var a:int = 0;
for each ( var value:int in annual_saving )
{
a = a + value;
}
return a / 100;
而不是...
return reduce(lambda x,y: (x+y), self.annual_saving ) / 100
这对我来说有点太像Java了(eww Java:puke!XO###)
我只是不知道as3的酷数组求和功能吗?或者它是否理解 lambda 演算,或者列表推导式?或者提供其他一些这样简洁的符号?我是否怀疑有一种更优雅的方法可以做到这一点,或者我在这个项目的其余部分中停留在 20 世纪!?
干杯:)
罗杰。
I'm porting some code I prototyped in python over to flash and while actionscript doesn't suck quite as bad as I expected (I hear v3 is quite a lot better than v2!) there's still some stuff I'm having to do that seems overly prosaic / boilerplate e.g. summing a list...
var a:int = 0;
for each ( var value:int in annual_saving )
{
a = a + value;
}
return a / 100;
as opposed to...
return reduce(lambda x,y: (x+y), self.annual_saving ) / 100
That feels a bit too much like Java for me (eww Java: puke! X-O###)
Am I simply ignorant of as3's cool array summing function? Or does it understand lambda calculus, or do list comprehensions? or provide some other such concise notation? Am I right in suspecting there is a more elegant way of doing this or am I stuck in the 20th century for the remainder of this project!?
Cheers :)
Roger.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Actionscript 与 JS 非常相似。如果必须的话,您可以轻松地自己实现它:
您可以轻松地扩展它...语法会稍微不那么吸引人,但仍然非常简洁。
Actionscript is very similar to JS. You could easily implement it yourself if you had to:
You could easily extend this... the syntax will be somewhat less appealing, but still very concise.
它不执行列表推导式,但支持匿名函数和闭包。您还有 地图 和 filter 在 Array 类中。
It doesn't do list comprehensions, but supports anonymous functions and closures. You also have map and filter in the Array class.