What does default ? report for a partially-initialised record?
← Operators and Expressions · Ref: Q1088
A partially-initialised object is UNSET under default ?:
partial <- ContactInfo("Alice") if not partial? stdout.println("not fully set")
With 1 of 3 fields set, default ? returns false - it uses ALL-field (flattened-aggregate) semantics, so a single unset field collapses the whole object. Write 'override operator ?' if a partially-filled object should count as set.
See Q1087 for basic isSet. See Q1089 for custom override operator ?.
Example
defines module qa.operators.checkpartialset defines class ContactInfo name <- String() email <- String() phone <- String() ContactInfo() -> name as String this.name :=: name //email and phone remain unset default operator defines program CheckPartialSetDemo() stdout <- Stdout() //Only name is set — email and phone remain unset partial <- ContactInfo("Alice") stdout.println(`Contact: ${partial}`) //default ? uses ALL-field semantics: only 1 of 3 is set, so this is FALSE stdout.println(`Is set?: ${partial?}`) //Compare with fully unset object blank <- ContactInfo() stdout.println(`Empty set?: ${blank?}`)
Common mistakes
E01073 — 'null' does not exist in EK9 — check an object's overall set-status with the '?' operator (partial?) instead of comparing to null. See ek9 -h E01073 for details.
Incorrect:
${partial <> null}
Correct:
${partial?}
Other ways to ask this
- I have a contact with only a name filled in — is it still set?
- In Java I'd check each field for null separately. Show the EK9 ALL-field semantics
- Given an object with 1 of 3 fields set, confirm the default operator ? result
- Test whether a partially-initialised object counts as set in EK9
Coming from another language?
Java: check each field != null individually. Python: hasattr or getattr checks. EK9: default ? requires EVERY field to be set; override ? for custom logic such as partial-tolerant checks.
Keywords: isSet, ?, individual, check, partial, unset, field