Repository navigation
Records
Records are the Minima equivalent to structs in C, however they do support sub-procedures and object-messaging. Unlike many other object-oriented programming languages, Minima does not support subtype polymorphism.
A record can be declared using the record keyword succeeded by an identifier.
record myrecord {
rem put your code here
}
However it should be noted that all records need an initializer (Minima's equivalent of a constructor) to initialize a new record object of the said type.
record person {
name
age
email
phone
address
}
Simply type the identifier inside a records body. You can access it by placing the properties identifier after a . token (ie object.property, object.subobject.property).
To include augments with a call on a record's sub-procedure, simply include the ( and ) tokens with your arguments encapsulated as you normally would. The above example would run the procedure is_old on michael with a limit of 40.
record person {
name
age
proc init(name, age) {
set this.name to name
set this.age to age
}
}
An initializer is the first function called when a request to create a record from a certain record-prototype is invoked. Its very-much akin a constructor, though ultimately Minima initializers can also be invoked through a normal record sub-procedure call.
To define an initializer, define a sub-procedure using the identifier init. This procedure is called whenever the new keyword is invoked. In this case, new person("name", 14) would have to be invoked to invoke the initializer. Note that the initializer cannot return a value - unless you want to override the result of new do not include any returns in your initializer. See the section, declaring a procedure, for more information regarding self-access.
record person {
name
age
proc init(name, age) {
set this.name to name
set this.age to age
}
proc print {
extern print("Name:", this.name, " Age:", this.age)
}
proc is_old (limit) {
if this.age > limit {
extern print("You're ancient")
}
else {
extern print("Still young")
}
}
}
To define a sub-procedure for a record, declare a procedure using the proc keyword, as you normally would, but ensure that the procedure declaration is encapsulated within the said records body. See the section, record sub-procedure calls, for more information regarding invoking record sub-procedures.
To do self-referencing (getting the callee object of the said records type), use the this keyword. this is actually an reference to the calling object.
extern print(myrec.property.anotherproperty)
Simply use the . notation to access a record's property.
It should be noted that you can only call a sub-procedure on a record if the sub-procedure is part of the said record's prototype.
set michael to new person("Michael", 15)
goproc print as michael
To call a record's sub-procedure , type the as keyword followed by the record-value to invoke a sub-procedure method. The above example would call person's sub-procedure print on the person object michael.
goproc is_old as michael(40)
The above example calls the sub-procedure is_old on michael. It would produce an output of "still young" as michael is not an ancient 40 years old.