teal-language / tl

The compiler for Teal, a typed dialect of Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: if local syntax

ggoraa opened this issue · comments

Basically something that Swift has for safely unwrapping nil values. An example of such syntax in Swift:

let value: String? = nil

if let value {
    // value is now of type String, not String?
    // if value is nil, this block won't even be executed
    print(value)
}

if let otherName = value {
    // Basically the same thing, just the name of the variable being changed
}

This syntax is basically syntax sugar for this:

if value != nil {
    print(value!) // The ! is force unwrapping, as in crash if there is a nil
}

It can look in Teal like this:

if local value then 
    print(value)
end

I don't get why teal would need special syntax for this?

Right now, teal doesn't have a T? type so it doesn't help with that, and in lua the only falsy types are nil and false so 99% of the time it is ok to just do if value then.

Oh, wow, I didn't know about such syntax in Lua
I will close it then