-
Notifications
You must be signed in to change notification settings - Fork 0
Special values
Each domain may require certain special values like 32 degF, pi, 0.0 and so forth. You don’t necessarily want to devote specification attributes to these values since they don’t really describe your modeled subject matter. But if the values are not specific to your subject matter, they must be specific to something! You could argue, for example, that 32 degF is specific to the temperature data type. Pi is a mathematical constant. While pi is an irrational number, in mathematics, it is always rounded down in the computer world to some rational value. Zero is a special integer which may be implemented in a variety of implementation types (double, unsigned, etc).
In all of these cases we can make use of a special operation called a “selector” defined on the appropriate type.
A type defines a set of values that can be assigned and a selector chooses one such value for that type.
Let’s say that we want to select the number 2 from the system defined data type Integer. We could then define a selector operation named “2” invoked like this:
x = Integer[2]
Scrall requires the square brackets to indicate a selector operation is being invoked.
Here’s the trick, though. You have to go in and define that 2 selector for the relevant data type before it will work. So you can't just assume that you can ask for any integer value.
You can define a selector to take a symbolic value like this:
pi = Rational[pi]
For the temperature example:
t = Temperature[freezing h2o].DegF()
Here we have a selector combined with a conversion operation. The selector is always parenthesized while the conversion operation is accessed via dot notation.
For zero, it depends on your data type:
d = Duration[immediate].Seconds() // gives you zero seconds
If no value is supplied between the square braces or if they are omitted, the default initial value defined for the type will be assigned. Given that it is zero for the base types Rational and Integer, you can do this:
rzero = Rational
izero = Integer
This trick also works if you want the current time:
now = Date.HMS() // current time is the default initial value
The HMS operation is defined on the Date scalar and is applied to the default current time value. There is no need for a selector since we are assuming we get the default initial value, but we do specify the conversion operation to get the date in the desired format.
The same principle works with non-numeric values. Let’s say that you want to create all new instances of Folder with the string “Untitled”. Define that value as the initial default of the Folder Name type and you would do this:
newFolder name = Folder Name
Copyright 2020, 2021, 2022, 2023, 2025 © Leon Starr under MIT Open Source License
- Why they are problematic
- Instance attribute creation values
- Boolean values
- Special values
- Enumerated values
- Action block
- Statement
- Single line action
- Multiple dependent actions on a single line
- An action spread across multiple lines
- A conditional group of single line actions
- Comments
- Finding instances
- Attribute access
- Creation and deletion
- Subclass migration
- Creating a table from a class
- Creating a table with a definition
- Converting a table into a class
- Set operations on tables
- Set comparisons on tables
- Join
- Rename
- Extend
- Aggregation
- Rank
- Image
- Input values
- Signatures and name doubling
- Output values
- Execution order
- Sequential execution
- Conditional execution
- Signals
- Scrall has no for_each action
- Iteration