/docs/language design

magenta is immutable where convenient, does not have null, and aims to keep code as short as possible whilst maintaining not being absolutely ridiculous

view the whole specification at codeberg

default values

assignment is done with the -> operator instead of = in most languages, this is because it fits in well with piping which is explained later

there is no "null" or "undefined" in magenta, you are encouraged to assign to variables where they are defined, but if such is not possible the variable will be assigned its default value until the writer decides to assign to them later

// regular variable assignment, type is inferred
"lorem" -> var w // string ("lorem")

// "empty" variable assignment, type has to be specified
var x string // empty string ("")
var y int    // zero (0)
var z Guy    // the struct is initialized with default values of all of its members (new Guy())

memory management

magenta is somewhat immutable, and has no references. there is no manual memory management, and it implements escape analysis as its sole garbage collection mechanism

var globalHomer Guy

string getName() {
	// initializes a new Guy with name "lisa" into new variable 'guy'
	new Guy(name "lisa") -> var guy

	// creates a copy of guy into a new variable 'otherGuy'
	guy -> var otherGuy

	"homer" ->

	// copies the values of guy over 'globalHomer''s values
	guy -> globalHomer

	"asdf" ->

	// 'otherGuy' is unaffected by the modification of guy
	return // "lisa"

	// upon end of the function, all allocated resources are cleared in bulk
	// where getName() is used the caller will not receive a reference to the name, but the actual string itself

// globalHomer has its default values | tty.println // ""

// getName is ran, returning the name of 'otherGuy'
// it also modifies the 'globalHomer' variable...
getName() | tty.println // "lisa"

// ...but the further modification of 'guy' is not propagated (as magenta has no references!!!) | tty.println // "homer"