#5 Polymorphic operators, only prefix notation supported :-(

Let us look at the following:

; currently alpha stage, trying to improve it, it is attached
do %polymorphic.r

complex: make object! [
    type: 'complex!
    re: im: 0
]

polymorphic [minus a b]
register 'minus [complex! complex!] [] [
    make complex [re: a/re - b/re im: a/im - b/im]
]

mold minus make complex [re: 1 im: 0] make complex [re: 0.5 im:
0.5]

== {
make object! [
    type: complex!
    re: 0.5
    im: -0.5
]}

mold minus 1 make complex [re: im: 0,5]
Polymorphic error, signature not found!

register 'minus [integer! complex!] [] [
    make complex [
        re: a/re - b/re
        im: a/im - b/im
    ]
]

mold minus 1 make complex [re: im: 0,5]
== {
make object! [
    type: complex!
    re: 0.5
    im: -0.5
]}

What do you think?

polymorphic.r

Reply via email to