Skip to content

Writing an attribute

Leon Starr edited this page Nov 6, 2023 · 2 revisions

The following action assigns a value to an instance’s attribute

running task.Time to completion = remaining duration

Assuming that the local class is Task with a numeric Priority attribute having a type that supports the ++ operator, the following is legal:

++Priority  // increment the priority

Assuming Commanded heading is an attribute of the local class Aircraft you could do this:

Commanded heading = ^go this way  //incoming parameter assigned to local attribute

Writing an attribute for multiple instances of the same class

You can set an attribute of multiple instances of the same class:

engines ..= /powered by/Engine
engines.Power setting = desired setting

Each instance of engines will assign the same value to its Power setting attribute. In the case of the empty set, there is no error and no values will be assigned.

Reading and writing multiple attributes of the same class

For the Rectangle class with attributes X, Y, Length and Width you can do this:

l, w = /Rectangle.(Length, Width)

The left right ordering indicated on the RHS is preserved on the LHS.

Or if you define a type called Rect Size with components Length and Width you could do this:

rect = /R6/Rectangle(ID: some rectID)
rect? {
    rsize::Rect Size = rect.(Length, Width)
    l,w = rs.(Length, Width)  //extract components
}

For this to work, the type Rect Size must provide an initialization operation that takes two values whose types that match the Length/Width types.

Looking at the class model, let’s say that Rectangle.ID is an identifier. This selection then can yield only zero or one instance. We assign the scalar variables only if the rect instance set variable is non-empty and therefore holds a single instance.

Introduction

Model semantics

Flows (as Variables)

Constants and literals

Structure of an activity

Accessing the class model

Data flow


Grammar and parsing notes

Components

Clone this wiki locally