Is the ? operator prefix or suffix in EK9?
← Operators and Expressions · Ref: Q936
The ? operator is always SUFFIX in EK9. Write name? not ?name.
SUFFIX SYNTAX
if userName? stdout.println(userName)
The ? comes after the variable, like Rust's .is_some() or Swift's optional unwrapping.
WHY SUFFIX
Suffix reads naturally as a question: 'is userName set?' The ? asks a question about the thing to its left. Prefix ? would be ambiguous with other operators.
USAGE CONTEXTS
variable? // Is this variable set? list? // Is this list set? (always true for created lists) result? // Is this result set? if connection? // Guard: only enter if connection is set
COMBINING WITH NOT
if not userName? stdout.println("No user name")
The pattern 'not variable?' reads as 'not (variable is set)'.
See Q877 for isSet details. See Q898 for more ? examples. See Q29 for tri-state.
Example
defines module qa.operators.issetsuffix defines program IsSetSuffixDemo() stdout <- Stdout() //Unset variable — ? returns false greeting <- String() if not greeting? stdout.println("Variable is unset") //Guarded assignment with suffix check greeting :=? "Hello" if greeting? stdout.println(greeting) //Works on any type score <- Integer() if not score? stdout.println("Score is not yet set") score :=? 42 if score? stdout.println(`Score is set: ${score}`)
Other ways to ask this
- Where does the ? go — before or after the variable name?
- How do I write an isSet check correctly in EK9?
- Is it ?name or name? in EK9?
Coming from another language?
EK9 uses value? as a suffix — append ? after the variable name to check if it is set. Returns Boolean, no parentheses needed.
Keywords: question, operator, set, suffix, mark, position, check, isset