Skip to main content

Constants

·103 words·1 min
Documentation - This article is part of a series.
Part 5: This Article

Constants
#

Constants are immutable values that are defined at compile time. They are useful for defining compile time parameters, such as the size of an array.

const A = 5;
println(A);
Output:
5

You can use constants in type definitions as well.

const A = 5;
type FiveLong<T> = [T * A];

let a: FiveLong<Int> = [1, 2, 3, 4, 5];
println(a);
Output:
[1, 2, 3, 4, 5]

For now, constants are limited to very simple expressions, but we plan to expand this in the future. Ideally, users should be able to run arbitrary Sage code at compile time to define constants.

Documentation - This article is part of a series.
Part 5: This Article