Skip to content
Splizard edited this page Sep 28, 2017 · 5 revisions

Methods in i

The i programming language has a very different method style then other languages.
Methods in i behave similarly to function overloading.

There are a set of builtin methods which can be overloaded depending on what type is passed.
The methods in i are very powerful, they allow for custom casting, standardised use and consistency.

For example:

text()     --> ""
text("hi") --> "hi"
text(22)   --> "22"

Methods can be created for custom types too:

type Custom {}
method text(Custom) "" {
    return "custom"
}

Calling text(Custom()) will return "custom".

Multiple Arguments.

For methods with arguments, they are supported with the following syntax:

method Custom.print(""s) {
    print(s)
}

Custom().print("hello feature")

MetaMethods

i has a few meta methods which extend the functionality of your type.

New

New Methods are used to initialise things in your type, it's good practise to include a new method if your type has any Custom type members.

type Weight { value }
method new(Weight) {
    value = 50
}

print(new(Weight).value) --> 50

Run (Not Implemented)

type Runnable {}
method run(Runnable) {
    print("running runnable!")
}

var r = Runnable()
r() --> "running runnable"
Clone this wiki locally