简体   繁体   English

覆盖Alloy中的对象

[英]Overriding an object in Alloy

I've been trying to make my project a little bit more dynamic, so I've decided to write an add function, I got inspired from this example they have on the Alloy website : 我一直在尝试让我的项目更有活力,所以我决定编写一个add函数,我从这个例子中得到了灵感,他们在Alloy网站上有这个例子:

pred add [b, b': Book, n: Name, t: Target] {
  b'.addr = b.addr + n->t 
}

But what I want to do is override the two objects "b" and "b' " (as in I want to add to the same object) but i can't seem to find a way how to do it. 但我想要做的是覆盖两个对象“b”和“b”(就像我想要添加到同一个对象),但我似乎无法找到一种方法如何做到这一点。

If anyone has an idea I'll be thankful 如果有人有想法,我会感恩

You're not missing anything. 你没有遗漏任何东西。 The reason you cannot find a way to "add to the same object" is that you can't. 你找不到“添加到同一个对象”的方法的原因是你不能。 Alloy doesn't have mutation; 合金没有突变; you cannot change any object in a model. 您无法更改模型中的任何对象。

Applications that involve mutation are often modeled just as you model add in your example: with two parameters showing the pre-state and the post-state. 涉及变异的应用程序通常就像您在示例中add模型一样建模:两个参数显示前置状态和后置状态。 In such a model, any two Book objects b1 , b2 will show different states of the same mutable Book object in the application domain if and only if there is some n , t such that add[b1, b2, n, t] holds. 在这样的模型中,任何两个Book对象b1b2将在应用程序域中显示相同可变Book对象的不同状态,当且仅当存在一些nt使得add [b1,b2,n,t]成立时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM