I come from Go. How does EK9 assignment differ from Go's := and =?

← Getting Started · Ref: Q1042

Go and EK9 both separate declaration from assignment, but they use OPPOSITE symbols.

Go: := declares (creates) = assigns (updates)
EK9: <- declares (creates) := assigns (updates)

Go's := is EK9's <-
Go's = is EK9's :=

Examples:

  Go:  name := "Alice"        EK9: name <- "Alice"
  Go:  name = "Bob"           EK9: name := "Bob"
  Go:  count := 0             EK9: count <- 0
  Go:  count = count + 1      EK9: count := count + 1

The key difference: in Go, := can also reassign in multi-return contexts. In EK9, <- ONLY creates. It never reassigns. The separation is absolute.

Another difference: EK9 has :=? (guarded assignment) which Go does not have. It only assigns if the target is currently unset.

Example

defines module qa.gettingstarted.goassigntrap

  defines program

    GoTrapDemo()
      stdout <- Stdout()

      // Go: name := "Alice"  →  EK9: name <- "Alice"
      name <- "Alice"
      stdout.println(name)

      // Go: name = "Bob"  →  EK9: name := "Bob"
      name := "Bob"
      stdout.println(name)

      // Go: count := 0  →  EK9: count <- 0
      count <- 0
      count := count + 1
      stdout.println(`Count: ${count}`)

Common mistakes

E50001 — Go developers: your := habit means 'declare' but in EK9, := means 'update'. Swap to <- for declarations.

Incorrect:

      count := 0

Correct:

      count <- 0
Other ways to ask this
  • As a Go developer, what are the EK9 equivalents of := and =?
  • Go uses := to declare. What does EK9 use?
  • Map Go's short variable declaration to EK9 syntax

Coming from another language?

Go := declares, EK9 <- declares. Go = assigns, EK9 := assigns. The symbols are swapped. EK9 also adds :=? for conditional assignment which Go lacks.

Keywords: golang, declare, assign, short, go, migrate, variable