Strict (non-coercing) expressions

Claude Pache claude.pache at gmail.com
Mon Apr 17 15:33:29 UTC 2017


> Le 13 avr. 2017 à 08:39, T.J. Crowder <tj.crowder at farsightsoftware.com> a écrit :
> 
> In the thread on [strict relational operators][1], felix [suggested][2] an expression mode affecting all operators:
> 
> > Maybe every operator can have a non-coercing variant?
> >
> > One possible syntax is to have a modifier on operators
> >
> >    x = a (<) b (+) c (&&) (!)d;
> >
> >    if (x (!=) y) ...
> >
> >
> > Another possible syntax is to have a modifier on expressions
> >
> >    x = #(a < b + c && !d)
> >
> >    if #(x != y) ...
> 
> I though the idea deserved its own thread. It's much broader in scope than strict relational operators, and not exclusive with them.
> 

I think that, in general, “implicit coercion” is not the real issue, although it makes things worse in some cases. The real issue is “ambivalent meaning”.

For example, `+` is so problematic in JS because it has two contradictory meanings: addition and concatenation.

On the other hand, `<` is less problematic, because there is much rarely a situation where it is ambiguous (for a human).

Another example:

```js
var a = new Date
var b = new Date(a)
a <= b // true
a < b // false
a == b // probably not what you mean
```

In this case, “stricter” is not helpful in the “equality” test. What would have helped, is comparison operators with non-ambivalent meanings.  E.g., Perl has `==` for numerical comparison, `eq` for string comparison, and, since v6, `eqv` for structural comparison, `===` for identity comparison, `=:=` for...

—Claude



More information about the es-discuss mailing list