plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
plum-examples/methods.plum
| b7071c9 | 1 | import std/Str |
| 73b5e55 | 2 | import std/Bool |
| ca5fd6f | 3 | import std/Number |
| b7071c9 | 4 | |
| 5f2f962 | 5 | enum Cat = |
| 5f2f962 | 6 | | Cat(name: Str, age: Int) |
| 0e1801a | 7 | |
| 805d96d | 8 | fun getAge(self) -> Int = |
| 805d96d | 9 | self.age |
| 0e1801a | 10 | |
| 805d96d | 11 | fun birthday(self) -> Int = |
| 805d96d | 12 | self.age + 1 |
| 0e1801a | 13 | |
| 5f2f962 | 14 | enum Wrapper = |
| 5f2f962 | 15 | | Wrapper(inner: Cat, tag: Int) |
| 0e1801a | 16 | |
| 805d96d | 17 | fun innerAge(self) -> Int = |
| 805d96d | 18 | self.inner.age |
| 0e1801a | 19 | |
| 0fe3528 | 20 | fun makeCat() -> Cat = |
| 0e1801a | 21 | Cat(name: "Whiskers", age: 3) |
| 0e1801a | 22 | |
| 0fe3528 | 23 | fun main() -> Int = |
| a271f34 | 24 | c := makeCat() |
| a271f34 | 25 | a := c.getAge() |
| a271f34 | 26 | b := c.birthday() |
| a271f34 | 27 | w := Wrapper(inner: c, tag: 1) |
| 0e1801a | 28 | a + b + w.innerAge() |
| a271f34 | 29 | |
| a271f34 | 30 | test "methods example computes correctly" |
| a9a0147 | 31 | assert main() == 10 |