Traffy.UnityPython icon indicating copy to clipboard operation
Traffy.UnityPython copied to clipboard

PEP 0207

Open thautwarm opened this issue 3 years ago • 2 comments

https://www.python.org/dev/peps/pep-0207/

But still we want to skip tedious tasks when implementing the whole system.

Plan: learn from CPython impl: builtin classes use __cmp__, and __eq__, __lt__ stuffs are generated.

thautwarm avatar Feb 21 '22 07:02 thautwarm

Enhancement: The follow code illustrates a most efficient interface for structural ordering. We can provide a builtin abstract class, which asks the user to provide __eq__ and one of __fast_le__(other: _T , x: ref[bool]) and __fast_le__(other: _T , x: ref[bool]), for fast structural ordering..

public interface IFastOrder<T>
{
    public bool __le__(T other, ref bool isEqual);
    public bool __ge__(T other, ref bool isEqual);
}

thautwarm avatar Feb 21 '22 16:02 thautwarm

Done, but so far comparisons must return boolean or a type error is thrown. This is because in Unity broadcast comparisons are not widely used. Returning bool is faster.

thautwarm avatar Feb 22 '22 01:02 thautwarm