let a = [
1;
2;
3;
if 3 > 2 then
4;
else
5;
6
]
Run Code Online (Sandbox Code Playgroud)
哪一个失败了"这个构造被剥夺了... ......保证这个表达式以表明它是列表的一个单独元素......",我这样做,
let a = [
1;
2;
3;
(if 3 > 2 then
4
else
5);
6
]
Run Code Online (Sandbox Code Playgroud)
导致编译器告诉我"不匹配"('".显然编译器不喜欢带有paranthesized的多行条件.为什么会这样?并且它有什么办法吗?
这是一个微不足道的案例,但在实际使用中我会有任意复杂的递归表达式(因此需要将它分割成多行),我不想打破表达式,并通过list-append和什么不能完成它.
编辑:这工作:
let a = [
1;
2;
3;
if 3 > 2 then yield(
4
)else yield(
5);
6
]
Run Code Online (Sandbox Code Playgroud)
但是比我想要的更加冗长(5个关键字和4个括号用于简单的三元运算!).寻找更清洁的东西仍在继续
您只需要在添加之后将其缩进else到左侧if(
let a = [
1;
2;
3;
(if 3 > 2 then
4
else //same column as matching if
5);
6
]
Run Code Online (Sandbox Code Playgroud)