Fuzion Logo
flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Compound Constants or Instance Initialization

Creating Pre-initialized Instances in other languages:

C++:

  Point p = Point(x,y)

C:

  struct Point p = {x, y};   // C89

  struct Point p1;
  p1 = (struct Point) {x, y};   // C99

Fuzion Approach to Pre-initialized Instances

Is there any need for this at all? As long as the fields defined within a feature are all arguments to that feature, we can just call it as in

  point (x1, x2 i32) is { }

  p1 := point x, y

If this occurs repeatedly, e.g., nested in an array

  pythagorean := [ point( 3,  4), point( 5, 12), point( 6,  8),
                   point( 7, 24), point( 8, 15), point( 9, 12),
                   point( 9, 40), point(10, 24), point(12, 16),
                   point(12, 35), point(14, 48), point(15, 20) ]

then the compiler could convert this into a constant pre-initialized array and avoid calling overhead.