Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to override functions to parse string/float/bool #68

Open
lafriks opened this issue Oct 21, 2021 · 1 comment
Open

Add option to override functions to parse string/float/bool #68

lafriks opened this issue Oct 21, 2021 · 1 comment

Comments

@lafriks
Copy link
Contributor

lafriks commented Oct 21, 2021

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 or 1+'1' resulting into 2

@generikvault
Copy link
Collaborator

generikvault commented Oct 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants