4
let a = [
    1;
    2;
    3;
    if 3 > 2 then
        4;
    else
        5;
    6
]

Which fails with a "this construct is depracated ... ... Paranthesize this expression to indicate it is an individual element of the list...", which I do,

let a = [
    1;
    2;
    3;
    (if 3 > 2 then
        4
    else
        5);
    6
]

causing the compiler to tell me "unmatched '('". Obviously the compiler does not like the paranthesized multi-line conditional. Why is that? And is there any way around it?

This is a trivial case, but in the actual use I will have arbitrarily complex recursive expressions (hence needing to split it over multiple lines), and I do not want to break up the expression and do it imperitively via list-appending and what not.

EDIT: this works :

let a = [
    1;
    2;
    3;
    if 3 > 2 then yield(
        4
    )else yield(
        5);
    6
]

but is somewhat more wordy than I would prefer (5 keywords and 4 parenthesis for a simple ternary operation!). The search for something cleaner continues

1
  • In your first sample above, you have a ; before the else which is invalid.
    – user29439
    Nov 14, 2011 at 14:43

2 Answers 2

7

You just need to indent the else as it is to the left of the if after you add the (

let a = [
    1;
    2;
    3;
    (if 3 > 2 then
        4
     else //same column as matching if
        5);
6
]
0
2

Multi-line when a semicolon is not required.

let a = [
    1
    2
    3
    (if 3 > 2 then 4 else 5)
    6
]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.