I'm following Andrea Ferretti's tutorial and am trying to define + for my own type.
My tuple is:
TUPLE: myBox a ;
If I create my own generic word
GENERIC: my+ ( a b -- c )
M: myBox my+ a>> swap a>> swap + myBox boa ;
then I can use it to add to add the contents of two myBoxes together
6 myBox boa 7 myBox boa my+
which outputs
--- Data stack:
T{ myBox f 13 }
However, if try to define + itself for myBox with:
M: myBox + a>> swap a>> swap + myBox boa ;
then, when I try to use it:
6 myBox boa 7 myBox boa +
I get the error:
No suitable arithmetic method
"left" T{ myBox f 6 }
"right" T{ myBox f 7 }
"generic" +
If I go to the help page for + I even see my definition listed amongst the others (ie bignum, complex, fixnum, float, and ratio).
How can I define the generic word + for my own tuple?