The ALTernative Language
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Complex numbers

In this example we implement a complex number type and a user-defined ‘function’ that can add two complex numbers. We encode the complex number type to be a sequence of exactly two numbers.

Then we define the nested struct add that maps two consecutive complex numbers to calculate their sum.

Notice that function calls are emulated in ALT by using indexing on structs. But it is good to emphasize however, that functions don’t really exist in ALT, at least not in the traditional way.

You could also argue that ALT structs are functions as they map domain values (keys) to range values.