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 - own or inherited - collapses the whole object. An unset object has no $ text either, so interpolating it (`${partial}`) prints nothing at all - test with ? first. Write 'override operator ?' if a partially-filled object should count as set.
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") //Interpolating the whole object prints nothing: $ of an unset object is unset //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
- Check if all fields in a record have been set.
- Test whether an object is fully initialised using ?
- Determine if a record has any unset fields
- In Java I'd check each field for null. How do I check if an EK9 object is set?
- I need to verify that a config object has all required values before using it
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: fields, initialised, partial, check, validate, record, set, field, ?, isSet, unset, operator, individual