top | item 42291836

(no title)

-J | 1 year ago

Alright I’ve built them into the language. Here’s the example code using what you asked for, as far as I understand at the moment: class Person { init(name, age) { this.name = name this.age = age }

    func doesNotUnderstand(method, args) {
        "Person " + this.name + " does not have " + method
    }
}

func greet(person: Person) { match person { {name: "Alice", age: 30} => "Hi Alice, you're 30." {name, age} if age > 18 => "Hi " + name + ", you're an adult." _ => "Hello there!" } }

macro log_call(func) { `(println("Calling " + ${func})) }

let alice = new Person("Alice", 30) log_call(greet(alice)) # Expands to println and calls greet

discuss

order

No comments yet.