kyleect / locks

A toy language branched from Lox to learn language implementation and tooling. Forked from loxcraft
https://kyleect.github.io/locks/#/docs
MIT License
0 stars 0 forks source link

Single expression function/method bodies #119

Closed kyleect closed 9 months ago

kyleect commented 9 months ago

Functions

fn sum(a, b) = a + b;

fn divide(a, b) = a / b;

fn both(a, b) = identity(divide(sum(a, b), b));

fn identity(value) = value;

print sum(10, 10); // out: 20
print sum(10, -3); // out: 7

print both(10, 5); // out: 3

Methods

class Box {
  let value;

  fn init(value) {
    this.value = value;
  }

  fn get() = this.value;
}

let box = Box("Hello");

print box.get(); // out: Hello

box.value = "World";

print box.get(); // out: World