Skip to content

Variable assignment when to use = and when to use:= #29

Discussion options

You must be logged in to vote

Oftentimes, := and = are interchangeable, specifically when assigning an unused global variable.

Things can get tricky when you have comprehensive policies and you have variable names that may overlap.

Let's look at the following example:

package play

x := "hello"

a {
  x = "world"  # rule fails because 'x' already has another value assigned
  x == "world" # not evaluated
}

b {
  y = "world"  # y does not exist, introduces a new variable binding
  y == "world" # succeeds
}

c {
  x := "world" # x is a fresh variable inside of this rule, the global var named 'x' does not interfere
  x == "world" # succeeds
}

d {
  x = "hello" # Variable assignment succeeds because the new value is the …

Replies: 1 comment

Comment options

peteroneilljr
Oct 4, 2021
Collaborator Author

You must be logged in to vote
0 replies
Answer selected by peteroneilljr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment