wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.93k stars 555 forks source link

add unary + operator #1170

Open tr8dr opened 1 year ago

tr8dr commented 1 year ago

Added a unary '+' operator (+variable) to provide symmetry with the unary '-' operator (-variable). These operators are supported by most languages, so makes sense to include. Although unary '+' is effectively a NOP, it provides clarity in coding situations where want to contrast with the negation, where one may have code applying + and - to some magnitude.

In scripting often have symmetric rules, such as:

static rule_type1(alpha, beta, threshold1, threshold2) {
    return (alpha > -threshold1) && (beta < +threshold2)
}
static rule_type2(alpha, beta, threshold1, threshold2) {
    return (alpha < +threshold1) && (beta > -threshold2)
}

Having + and - magnitude clarifies the rules for us.

mhermier commented 1 year ago

Duplicate of #986

ruby0x1 commented 1 year ago

Thanks for the PR though @tr8dr , we always appreciate time spent