KINDS
Structure
6 min
a structure is a mutable datatype that contains a collection of named fields this is very similiar to a poco class in c# the fields of a structure can be other structures, records, and services a structure is a type you can declare a new instance of it and such can have local defined constructors docid 8cur6rtdh4zhi8fdh6vho declaration to declare a new structure define a top level construct using the keyword structure followed by the desired identifier the name must be unique within the corresponding namespace docid gwa7zz7fnle1mvm4rbhn a structure contains any number of named fields docid\ sz10ih owphmjgswgtavc they are mutable and the structure's fields can be assigned new values at runtime they can also be initialized to initial values shift //physically located in structures structure anotherstructure { int pa; this(int pa) { pa = pa; } } structure examplestructure { string foo; string bar = "why hello there"; anotherstructure baz; anotherstructure baz2 = new anotherstructure(5);//constructors are supported anotherstructure baz3 = new anotherstructure(); anotherstructure baz4 = new anotherstructure { pa = 3 };//initializer syntax is supported } remarks shift structures have nothing to do with c#'s structs they are pass by reference and live on the heap there are no properties in shift, with no getter and setters for behavior all structures have a system supplied 0 parameter constructor if not defined by the user c# only supplies this if the user supplies no constructors supplying a constructor does not block this in shift c# binding in general any c# class without behavior will be bound to a structure in shift c# structs that have mutability will be also bound as a structure c# equivalent all fields in a shift structure are equivilant to a property in c# using system; namespace exampleapp structures { public class anotherstructure { public int pa { get; set; } = new int(); public anotherstructure(int pa) { pa = pa; } } public class examplestructure() { public string foo { get; set; } = string empty; public string bar { get; set; } = "why hello there"; public anotherstructure baz { get; set; } = new anotherstructure(); public anotherstructure baz2 { get; set; } = new anotherstructure(5); public anotherstructure baz3 { get; set; } = new anotherstructure(); public anotherstructure baz4 { get; set; } = new anotherstructure { pa = 3 }; } } most of the interesting implications of a structure come from how types and constructors work in shift take this c# class class bar { public int honk { get; set; } = 7; } class foo { //all fields are private are unusuable //the lack of the constructor basically makes this class pretty useless without //reflection cleverness; which is its own can of worms int a { get; set; }// is a structure that defaults to 0 string b { get; set; }// is a class that defaults to null bar c { get; set; }// is a class that defaults to null anotherstructure d { get; set; }// is a class that defaults to null } now compare to a similiar datatype in shift structure bar { int honk = 7; } structure foo { int a;// 0 string b;// "" bar c;// new bar() anotherstructure d;// new anotherstructure } //all fields are accessible through an instance of the structure check out the field article for a deeper dive on their declaration and behavior usage all of a structure's fields can be accessed when you have an instance of a type structures are a mutable datatype so their fields can be assigned a new value at runtime var foo = new examplestructure(); console writeline(foo);// value\<examplestructure,t\ foo> console writeline(foo bar);// "why hello there" foo bar = "some new value"; console writeline(foo bar);// "some new value"
