-
Notifications
You must be signed in to change notification settings - Fork 0
Scrall has no for_each action
Scrall’s basis on data flow and relational semantics eliminates the need for an explicit “for each” action.
In the following example, all Dogs past a certain age are classified as ‘old’ by setting a status attribute.
Dog( Born < ^date).Status = _old
Consider this action language from the Elevator case study. Here a Bank Level instance (Floor in a Bank) is responding to an up/down floor call button by selecting the most suitable Cabin to respond to the call. Here is what it might look like in xtUML’s (BridgePoint) OAL (object action language):
shortest_delay = 0.0; // seconds
first_cabin = true;
param.OUT_Shaft = "";
// Select one of the cabins with the shortest delay
select many bank_Cabins related by my_Bank->Shaft{R1}->Cabin{R2};
for each this_Cabin in bank_Cabins
select one its_Shaft related by this_Cabin->Shaft{R2};
if (its_Shaft.In_service)
cab_delay = this_Cabin.Estimate_travel_delay(
Floor:my_Floor.Name, Calling_dir:param.Dir
);
if ((cab_delay < shortest_delay) or (first_cabin))
shortest_delay = cab_delay;
param.OUT_Shaft = its_Shaft.ID;
end if;
end if; // in service
first_cabin = false;
end for;
if (param.OUT_Shaft != "")
return true;
else
return false;
end if; // OUT_Shaft will be "" only if all Shafts are out of service
In Scrall, you could replace all that with two lines:
inservice cabins ..= /Bank/Shaft( In service )/R2/Cabin
=>> inservice cabins(1, ^-Estimate travel delay(
Floor: /Floor.Name, Calling dir: in.Dir).Shaft
The first line selects all Cabin instances whose Shaft is inservice.
The second line invokes the Estimated travel delay method of each selected Cabin instance and chooses one with the least delay reporting its Shaft attribute value (which happens to be a referential attribute to a Shaft ID. Done!
In fact, the whole thing could have been done with one line, but at some point you violate the principle of making the activity easy to read. In that vein, the two line solution could easily be expanded to three with the introduction of an additional variable (best cabin) to make it easier for humans to parse.
But the OAL solution returns an ID value because it is not possible output instance references. In Scrall, we would probably just return the selected Cabin instance references which, could be more than one since two Cabins might have the same estimated delay.
=>> /Bank/Shaft( In service )/R2/Cabin(
^-Estimate travel delay( Floor : /Floor.Name, Calling dir: ^dir )
)
Now the calling action can be:
servicing shaft .= Choose shaft( 1, ^dir )
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