Literal Expressions
Domain declares two built-in literal types, Number and String. Objects of these literal types can appear in Substance only as literal expressions:
- If a number literal (e.g.,
1.234,5,-3.14159) appears in Substance, it will be interpreted as an object of typeNumber. - If a string literal (e.g.,
"hello world") appears in Substance, it will be interpreted as an object of typeString.
Explicit declarations like these of objects with these literal types are disallowed:
String s
Number nUsing Literal Expressions as Arguments
If a predicate / function / constructor argument expects a literal type, then we need to provide it a literal expression. We illustate this using an example:
Suppose the domain schema is as follows:
type Set
predicate HasNum(Set set, Number num)
predicate HasStr(Set set, String str)Then, this is a valid substance program
Set s1, s2
HasNum(s1, 1.234)
HasNum(s1, 2)
HasStr(s1, "Hello")
HasNum(s2, 5.678)
HasNum(s2, -5.678)
HasStr(s2, "world")since numerical literals (1.234, 2, 5.678, and -5.678) have type Number and string literals ("Hello" and "world") have type String.
Literal Expressions in Indexed Statements
Within an indexed statement, if an identifier name coincides with the template variable name, Substance treats it as a numerical literal expression, like
NumberSet s
Contains(s, i) for i in [1, 10]
-- ok: expands into Contains(s, 1), Contains(s, 2), ..., Contains(s, 10)