What is the difference between <-, :=, and :=: in EK9?

← Getting Started · Ref: Q879

Three operators, three purposes:

  name <- "Steve"        // DECLARE: creates new variable, type inferred
  name := "Different"    // ASSIGN: changes existing variable
  other :=: name          // COPY: deep copies value from name into other

Think of it this way:
- '<-' is for BIRTH — the variable didn't exist before this line
- ':=' is for CHANGE — the variable already exists, you're updating it
- ':=:' is for CLONING — copy the contents, not the reference

There are also two conditional variants:

  config :=? "default"   // assign only if config is currently UNSET
  if guard ?= getValue()  // guard: execute block only if result is SET

Common mistake from Java/Python developers: using '<-' to reassign. This creates a NEW variable that shadows the old one. Use ':=' to change an existing variable.

See Q22 for variable declaration. See Q29 for unset variables. See Q75 for guard expressions.

Example

defines module qa.getting.started.three.operators

  defines program

    ThreeOperators()
      stdout <- Stdout()

      //DECLARE with <-
      counter <- 0
      stdout.println(`Created counter: ${counter}`)

      //ASSIGN with :=
      counter := 10
      stdout.println(`Changed counter: ${counter}`)

      //COPY with :=:
      backup <- 0
      backup :=: counter
      counter := 99
      stdout.println(`Counter now: ${counter}`)
      stdout.println(`Backup is still: ${backup}`)

      //CONDITIONAL with :=?
      serverName <- String()
      serverName :=? "localhost"
      stdout.println(`Server: ${serverName}`)
Other ways to ask this
  • EK9 has too many assignment operators — which one do I use?
  • When do I use := vs :=: vs <- in EK9?
  • Explain the arrow and colon operators in EK9

Coming from another language?

Java: single '=' for everything. Python: single '=' for everything. Rust: 'let' for declare, '=' for assign. EK9: '<-' declare, ':=' assign, ':=:' deep copy — each has distinct semantics.

Keywords: copy, operator, assign, colon, difference, variable, declare, arrow