Does A4 still support conditional expressions? Section 3.5.1 of the alloy book (Software Abstractions) mentions conditional expressions, where you can write "if C then E1 else E2" (where E1 and E2 are expressions not formula). That book is for Alloy 3, which is very similar (but not identical) to the syntax of Alloy 4. Can you still do that in Alloy 4? When I type it in, I do not get syntax highlighting on the words "if" and "then" and I get compilation errors on the word "if". The compiler also doesn't seem to like it if I write "C => E1". Is there another syntax for it?
Neither of these versions compiles:
fun Nclose [N: Int, r: univ -> univ] : univ -> univ {
if (N=1) then r //complains that "if" is not a valid token
}
fun Nclose [N: Int, r: univ -> univ] : univ -> univ {
(N=1) => r //complains that r is not a formula
}
I just figured it out -- it can be done. Conditional expressions have to have an "else" clause. A working version of my function would be this:
fun Nclose [N: Int, r: univ -> univ] : univ -> univ {
(N=1) => r else ~r
}
The compilation error is misleading -- the problem is that there is no else clause, not that there is any problem with having an expression as the result of a conditional.
fun Nclose [N: Int, r: univ -> univ] : univ -> univ {
(N=1) => r else ~r
}
The compilation error is misleading -- the problem is that there is no else clause, not that there is any problem with having an expression as the result of a conditional.