expr icon indicating copy to clipboard operation
expr copied to clipboard

Does expr support the '&' operator

Open ShengXiangXiong opened this issue 4 years ago • 3 comments

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)
}

image

ShengXiangXiong avatar Nov 09 '21 09:11 ShengXiangXiong

Nope, no bit operators.

antonmedv avatar Nov 09 '21 12:11 antonmedv

Nope, no bit operators.

Can this feature be added in the future

ShengXiangXiong avatar Nov 09 '21 12:11 ShengXiangXiong

Maybe.

antonmedv avatar Nov 09 '21 13:11 antonmedv

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 avatar Feb 23 '23 10:02 antonmedv

@antonmedv i think function is the solution. The signs | and ^ are already used for something else. It should not be used twice.

lublak avatar Sep 04 '23 08:09 lublak

Now Expr supports bit operations. See https://expr-lang.org/docs/language-definition#bitwise-functions

antonmedv avatar Jan 10 '24 20:01 antonmedv