Skip to content

Intrinsic Procedure __less_than__

IsaacShelton edited this page Mar 21, 2022 · 1 revision

'__less_than__' function

The __less_than__ function can be defined to allow additional types to be used with the less-than < operator.

func __less_than__(a $A, b $B) bool {

}

where $A and $B are any valid types

Usage Example

import basics

func main {
    a Letter = letter('a'ub)
    b Letter = letter('b'ub)
    
    printf("%S < %S  =>  %b\n", toString(a), toString(b), a < b)
}

struct Letter (char_code ubyte)

func letter(char_code ubyte) Letter {
    l POD Letter
    l.char_code = char_code
    return l
}

func __less_than__(lhs, rhs Letter) bool {
    return lhs.char_code < rhs.char_code
}

func toString(letter Letter) String {
    return string(&letter.char_code, 1)
}
a < b  =>  true
Clone this wiki locally