Alloy pred声明:方括号和圆括号有区别吗?

Alloy pred declaration: is there a difference between square brackets and parentheses?

问题可能有 yes/no 答案。考虑片段:

sig A { my : lone B }
sig B { }

pred single1 [x:A]{ // defined using []
    #x.my = 0
}
pred single2 (x:A){ // defined using ()
    #x.my = 0
}

// these two runs produce the exact same results
run single1 for 3 but exactly 1 A
run single2 for 3 but exactly 1 A

check oneOfTheMostTrivialQuestionsOnWhosebug { all x: A | 
    single1[x] iff single2[x] // pred calls use [], so as expected, single2(x) would cause a syntax error
} for 3000 but exactly 1 A // assertion holds :)

single1和single2完全一样吗?

他们似乎是,但我错过了什么吗?

我认为括号最初用于谓词和函数。但是,它们被更改为有利于方括号,因为它使它看起来更相关。我依稀记得丹尼尔杰克逊在他的书中解释过这个。

也就是说,为什么要问,因为你似乎已经自己证明了这一点? :-)

当我们扩展 Alloy 4 中的语法时,我们将谓词调用更改为 []。我的回忆是我们这样做是为了让解析更容易,所以如果你有一个没有参数的谓词 P,你可以称它为 "P",如果它后面跟着一个公式就没有问题了parens "P (...)"。正如 Peter 指出的那样,这似乎也很合理,因为它类似于关系查找运算符,这对函数来说尤其有意义。我们添加了使用 [] 声明谓词和函数的功能以保持一致性,但没有理由在 decls 中阻止 () (因为那里不可能有歧义)。