Skip to main content

Declaring Transforms

Transforms

A transform is a special type of function that you can use in Tangram ProTM when designing component software interfaces. They are the basis for making connections between components with mismatched ports or messages.

A transform function may be declared using the transform keyword.

note

The parameters and return type of a transform must be messages (see Message Types) or newtypes (see New Types)

Syntax

transform NAME( PARAMETERS ) -> RETURN TYPE { BODY; }

Example

Declare a transform named fahrenheitFromCelsius that takes a Celsius message struct and returns a Fahrenheit message struct:

flex
message struct Fahrenheit {
temp: float64;
}
message struct Celsius {
temp: float64;
}
transform fahrenheitFromCelsius(c : Celsius) -> Fahrenheit {
Fahrenheit {
temp = ((c.temp * 9.0) / 5.0) + 32.0;
};
}

Declare a transform named fahrenheitFromCelsius that takes a Celsius newtype and returns a Fahrenheit newtype:

flex
newtype Fahrenheit {
temp: float64;
}
newtype Celsius {
temp: float64;
}
transform fahrenheitFromCelsius(c : Celsius) -> Fahrenheit {
let f = Fahrenheit {
((c.temp * 9.0) / 5.0) + 32.0
};
Fahrenheit {
f.temp
};
}

Variables

Variables may be declared within the scope of a transform using the let keyword. See Function Variables.

Conditional Statements

Conditional statements may be included using the if, else if, and else keywords. See Function Conditional Statements.

Contextual Parameters

Coming soon

Derive

Coming soon

Coming soon

Compose

Coming soon