Set a fallback deadline only if no deadline was specified.

← Control Flow · Ref: Q1222

The :=? guarded assignment operator assigns a value ONLY if the target variable is currently unset. If the variable already has a value, the assignment is skipped.

  deadline <- Date()
  fallbackDate <- 2024-12-31
  deadline :=? fallbackDate
  //deadline is now 2024-12-31 because it was unset

This is an ASSIGNMENT operator — it sets a variable.

See Q1038 for :=? with config fallback chains.

Example

defines module qa.flow.guardassign.date

  defines function

    lookupProjectDeadline()
      <- rtn <- Date()
      //Simulates: no deadline set for the project

    lookupSprintEnd()
      <- rtn <- 2024-09-30

  defines program

    GuardAssignDateDemo()
      stdout <- Stdout()

      // === DEADLINE IS UNSET — :=? assigns the fallback ===

      deadline <- Date()
      fallbackDate <- 2024-12-31
      deadline :=? fallbackDate
      stdout.println(`Deadline: ${deadline}`)

      // === DEADLINE IS ALREADY SET — :=? is skipped ===

      existingDeadline <- lookupSprintEnd()
      existingDeadline :=? fallbackDate
      stdout.println(`Existing deadline preserved: ${existingDeadline}`)

      // === FALLBACK CHAIN — first set value wins ===

      projectEnd <- Date()
      projectEnd :=? lookupProjectDeadline()
      projectEnd :=? lookupSprintEnd()
      endOfYear <- 2024-12-31
      projectEnd :=? endOfYear
      stdout.println(`Project end: ${projectEnd}`)

Common mistakes

E01073 — EK9 has no null. Use :=? to conditionally assign — it only sets the value when the variable is currently unset. See ek9 -h E01072 for details.

Incorrect:

      if deadline == null
        deadline := fallbackDate

Correct:

      deadline :=? fallbackDate
Other ways to ask this
  • How do I conditionally assign a Date only when the variable is unset?
  • A project has an optional deadline — apply a default end-of-quarter date if missing.
  • In Java I'd check if deadline == null before assigning. What does EK9 use?
  • Migrating from Kotlin where I use the elvis operator for nullable dates — what is the EK9 pattern?

Coming from another language?

Java: if (deadline == null) deadline = LocalDate.of(2024, 12, 31). Python: deadline = deadline or default_date. Kotlin: deadline = deadline ?: defaultDate. Go: if deadline.IsZero() { deadline = fallback }. EK9: deadline :=? fallbackDate — one operator, correct tri-state semantics.

Keywords: guarded, fallback, default, date, assignment, :=?, project, deadline