问题
i am new to Alloy and there is an error due to which my program can't execute or show. Error iam having is
A Syntax error has occurred: You must specify a scope for "this/Name"
My Code is
module language/Family
sig Name { }
abstract sig Person {
name: one Name,
siblings: Person,
father: lone Man,
mother: lone Woman
}
sig Man extends Person {
wife: lone Woman
}
sig Woman extends Person {
husband: lone Man
}
sig Married extends Person {
}
fact {
no p: Person | p in p.^(mother + father)
wife = ~husband
}
fun grandpas[p: Person] : set Person {
let parent = mother + father + father.wife + mother.husband | p.parent.parent & Man
}
pred ownGrandpa[p: Person] {
p in grandpas[p]
}
These are my run commands
run ownGrandpa for 4 Person
run ownGrandpa for 2 Person
run ownGrandpa for 1 Person
Can Any one point out This Error for me Please.
回答1:
There are three ways to assign a scope to your model.
The first one is by assigning a scope to each signature of your model.
e.g. : run ownGrandpa for 4 Person, 3 Name
The second one is by giving a global scope that will be applied to all the signatures.
e.g. run ownGrandpa for 4
The last one is a mix of the two previous and consists of a global scope accompanied by one or several individual scope definitions.
e.g. run ownGrandpa for 5 but 4 Person.
The global scope is to be applied to all the signature for which an individual scope declaration is missing.
Thus, in your example, run ownGrandpa for 5 but 4 Person
is equivalent to run ownGrandpa for 5 Name, 4 Person
Note that providing scopes like this only gives an upper bound to the number of atoms derived from a signature.
If you want to express that any of your instance should contain exactly 4 persons (no more, no less) then you should use the keyword exactly
.
e.g. run ownGrandpa for 5 but exactly 4 Person
来源:https://stackoverflow.com/questions/30360214/specifying-a-scope-for-sig-in-alloy