Open lafriks opened 2 years ago
Hello lafriks,
that's partially correct. The conversion is done by the Boolean Float operators. When you use only interface operators gval will not cast.
gval.InfixOperator("+", f func(a, b string) (interface{}, error){
numA, okA := a.(float64)
if !okA{
return nil, yourError
}
...
return numA+numB, nil
}
When Go 1.18 is released I will do some experiments with generics that could lead to have a feature like this directly integrated into the language but I can't make any promises on this front.
Currently when defining language there is no way to override how float/string/bool are handled and to override behavior for example to be more strict for operations not to allow autocasting for example
false || 1
will result in 1 being treated as boolean true or1+'1'
resulting into2