expr
expr copied to clipboard
Does expr support the '&' operator
val := `1 & 1`
complie, err := expr.Compile(val)
r, err := expr.Run(complie,env)
if err!=nil {
fmt.Printf("%+v", err)
}
if v, ok := r.(int); ok {
fmt.Printf("%+v", v)
}

Nope, no bit operators.
Nope, no bit operators.
Can this feature be added in the future
Maybe.
I'm thinking to add bit ops with such functions:
- shl(int, int) – signed shift left
- shr(int, int) – signed shift right
- ushr(int, int) – unsigned shift right
- band(int, int) – bitwise AND
- bor(int, int) – bitwise OR
- xor(int) – bitwise XOR
- inv(int) – bitwise inversion
@antonmedv i think function is the solution.
The signs | and ^ are already used for something else.
It should not be used twice.
Now Expr supports bit operations. See https://expr-lang.org/docs/language-definition#bitwise-functions