Re: [RFC brainstorm] Approximately equals operator

From: Date: Tue, 01 Apr 2025 16:13:00 +0000
Subject: Re: [RFC brainstorm] Approximately equals operator
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 01.04.2025 at 00:03, Niels Dossche wrote:

> We live in an imperfect world, and we often approximate data, but neither == nor
> === are ideal comparison operators to deal with these kinds of data.
>
> Introducing: the "approximately equal" (or "approx-equal") operator
> ~= (to immitate the maths symbol ≃).
> This combines the power of type coercion with approximating equality.
> Who cares if things are actually equal, close enough amirite?
>
> First of all, if $a == $b holds, then $a ~= $b obviously.
> The true power lies where the data is not exactly the same, but "close enough"!

IMO a step in the right direction, but it doesn't solve the problem that
the developer might not even know which equality operator to apply.
Thus, I proprose the whatever (?) equality (=) is right (->) here (!)
operator, e.g.

  $value1 ?=->! $value2

I leave the trivial implementation as exercise to the reader, while I'm
porting the even more powerful rmmadwim TCL command[1], which,
incidentially, also had been proposed on an April 1st.

[1] <https://core.tcl-lang.org/tips/doc/trunk/tip/131.md>

Christoph


Thread (17 messages)

« previous php.internals (#127011) next »