A scalar, table value or instance set may be returned by class methods and domain operation activities with output parameters.
Returning a single scalar value
Here is a class method that returns a single scalar value of type Duration:
Aircraft.ETA( waypoint : Waypoint ID ) :: Duration
It might be called from within another activity like so:
current wait time = my aircraft.ETA( waypoint : /is visited next/Waypoint.ID )
Returning multiple scalar values
To return multiple scalar values you need to return a single tuple relation where the name of each output parameter is an attribute in the relation.
The method below takes as input a Tail number and returns the angle and distance to the target.
Aircraft.Trackto( target : Tail Number ) :: ( angle : Degrees, distance : Meters )
Within the method, use the
=>> return value action:
// compute using in.target input parameter to produce // assign results to data variables a and d =>> ( angle: a, distance: d ) // alternately you could do this output #1= ( angle: a, distance: d ) // create a table variable first and then return it =>> output
Now the calling method can retrieve these values like so:
track #1= /R5/Aircraft.Trackto( target : nearby aircraft.ID ) a = track.Angle d = track.Distance
This would also work:
a, d = /R5/Aircraft.Trackto( target : nearby aircraft.ID )
track #1= /R5/Aircraft.Trackto( target : nearby aircraft.ID ) nearby aircraft.(Angle, Distance) = track // assign results to attribute values
If the variable names in a class method or domain operation activity match the returned attribute names, there is no need to double them for the same reasons as input parameters. Therefore, this would also work with the above example:
=>> ( angle, distance ) // variable names match parameter names
Returning a table variable
A relation consisting of multiple tuples can be returned as a single table variable.
// Air Traffic Controller.Find places to land( guided aircraft : Tail number )::(Airport Code, Beacon) aircraft to land .= Aircraft( ID: in.guided aircraft ) =>> ( aircraft to land.Reachable airports().(Airport Code, Beacon) )