0

How to use String in Alloy?

What kind of function or operators for String are supported in Alloy?

I searched questions here and find String is a keyword in Alloy. But I cannot find any reference about how to use String in Alloy. Could you give one? If not, is possible to give a brief about String in Alloy?

wxlfrank
  • 39
  • 3

1 Answers1

2

You can actually use strings in Alloy, but only as literals to specify constant values (i.e., no string operations are supported, and Alloy does not implement a string solver). That said, the main use of strings is Alloy is to assign constant string literals to some fields for the sole purpose of making the generated instances more readable when visualized. Here is a simple example

sig Person {
  name: String,
  email: String
}
one sig P1 extends Person {} {
  name = "Joe"
  email = "joe@email.com"
}
run {
  some p: Person | p.name != "Joe"
}
Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
Aleksandar Milicevic
  • 3,837
  • 1
  • 13
  • 17
  • 2
    Note that the set of String atoms present in a generated instance is the set of literal (expressed between quotes) assigned to a field as illustrated in the example above. Using the String signature thus implies that somewhere in your alloy code you introduce yourself the set of literal you want to work with (as shown above). – Loïc Gammaitoni Nov 16 '14 at 19:40
  • It doesn't work /at least on Alloy 4.2/ unless P1 extends Person. – Attila Karoly Jun 19 '16 at 16:33
  • fixed the extends – Peter Kriens Nov 02 '17 at 12:55