KeliLanguage / compiler

The compiler for Keli
https://keli-language.gitbook.io/doc/specification/
Apache License 2.0
171 stars 1 forks source link

Guard statements #39

Open wongjiahau opened 5 years ago

wongjiahau commented 5 years ago

This proposal is a breaking change.

The previous if keyword needs to be changed to case, and else need to be changed to default.

Why?

Consider we wants to create the following function:

(this Int).compare(that Int) = 
    this.==(that).
        case(true):
            (0)
        case(false):
            (this.>(that).
                case(true):
                    (1)
                case(false):
                    (1.negate))

That is tedious, so we should do like this instead:

(this Int).compare(that Int) = 
    this.
        if(.==(that)):
            (0)
        if(.>(that)):
            (1)
        else:
            (1.negate)

Is much more cleaner, however, needs more revision on this.