d - 如何使用 Dlang 在范围块中编写多条语句?
问题描述
我想在一个范围块中编写多个语句,如下所示:
long[] W = [0L];
long[] V = [0L];
array.each!(s => // "s" has following strings "3 4"
W ~= s.split(" ")[0].to!long;
V ~= s.split(" ")[1].to!long;
);
但这会导致编译错误。有没有办法写出范围内的所有语句?
解决方案
只需使用稍长的形式函数语法:
long[] W = [0L];
long[] V = [0L];
array.each!( (s) {
W ~= s.split(" ")[0].to!long;
V ~= s.split(" ")[1].to!long;
}
);
(s) { x; y; z; }
可以在任何地方s => x
工作,除非s=>x
你需要返回值,长格式是(s) { return x; }
.
推荐阅读
- javascript - webpack 中的开发模式有什么好处?
- r - R过滤跨多列的字符串
- java - 在 Jmeter-maven-plugin 中完成测试计划执行后看到的 JMeter Java HEAP 问题
- sql - 在单个 SELECT 中获取某个组的第一项
- reactjs - 如何为 2 个受保护的路由构建 Context Api 多状态?
- ms-word - 多次连续按下 AHK 组合键可在 Word 或 PowerPoint 中进行特殊粘贴
- python - ModuleNotFoundError:使用 sys.path.append() 时没有名为 Project 的模块
- sql - 具有并行未嵌套的 Upsert 在 UPDATE 部分引发“列不存在”
- calculated-field - Amazon Quicksight 计算字段 - maxIf 或 maxOver?
- php - auth()->attempt($request->only('email','password')) - 不工作