Operators and Expressions
← All categories
- Q238: What operators does EK9 support and why is the set fixed?
- Q239: How do comparison and ordering operators work in EK9?
- Q240: How do arithmetic and mathematical operators work in EK9?
- Q241: What are mutation operators and how do they differ from pure operators?
- Q242: How do conversion and introspection operators work in EK9?
- Q243: How do coalescing operators handle unset values in EK9?
- Q244: How do boolean and bitwise operators work in EK9?
- Q245: How do I implement all the operators my custom type needs?
- Q780: Why can't I use ++ or -- in an expression in EK9?
- Q839: Why must the promote operator #^ return a different type than the class?
- Q864: Why must the negate operator ~ return the same type as its class?
- Q877: What does the '?' operator do in EK9 and what does 'default operator ?' mean?
- Q887: Why must the $$ operator always return JSON in EK9?
- Q897: What do the $ and #? operators mean in EK9?
- Q898: What does the ? operator mean in EK9?
- Q899: What are the coalescing operators in EK9?
- Q905: What happens when I use mutating operators in EK9?
- Q908: What does the $ operator actually do in EK9?
- Q909: How does $ work inside backtick strings in EK9?
- Q910: How do I implement the $ operator on a custom class in EK9?
- Q911: What does the #? operator mean in EK9?
- Q912: What does the #^ operator mean in EK9?
- Q913: How does $ work on different types in EK9?
- Q914: Does # mean comment in EK9 like Python?
- Q918: Is $ string interpolation or safe access in EK9?
- Q919: What is the complete # operator family in EK9?
- Q936: Is the ? operator prefix or suffix in EK9?
- Q937: Why does EK9 reject non-Boolean values in if conditions?
- Q939: What do <? and >? mean in EK9 — are they null coalescing?
- Q940: Can I use ++ in an assignment like y <- x++ in EK9?
- Q941: Why can't I assign the result of a void function in EK9?
- Q949: What are the rules for using 'default operator' in EK9?
- Q963: How does the <? coalescing minimum operator work in EK9?
- Q964: How does the >? coalescing maximum operator work in EK9?
- Q966: What does the #? hashcode operator do in EK9?
- Q967: Does EK9 have ++ and -- operators? What are the rules?
- Q969: What does the #^ promote operator do in EK9?
- Q981: How do I check if a variable has a value in EK9?
- Q982: How do ? and guard expressions work together in EK9?
- Q994: How do I convert a value to a String in EK9?
- Q995: How do I make my own class work with the $ operator in EK9?
- Q996: Show me ++ and -- being used in a real EK9 program.
- Q1003: What method does each EK9 operator call internally?
- Q1047: How do I use the #? hashcode operator on a record?
- Q1048: How do I use the #^ promote operator on a class?
- Q1049: How do I implement comparison operators on a record for sorting?
- Q1050: How do the coalescing operators <?, >?, <=?, >=? work on a custom class?
- Q1051: Can a trait define comparison and hashcode operators in EK9?
- Q1052: Define #^ on a record to promote it to String for display purposes.
- Q1053: Implement #? manually on a class that combines multiple fields.
- Q1055: Should I write #? and $ manually or use default operator?
- Q1056: Is the $ operator the same as string interpolation in EK9?
- Q1057: Does ++ return a value in EK9? Can I write x <- y++?
- Q1058: What is the difference between :=: :^: and :~: in EK9?
- Q1059: Do the ?? and ?: operators check for null in EK9?
- Q1067: What is the difference between < and <? in EK9?
- Q1075: Copy all fields from one record to another.
- Q1076: Copy a record that has some fields unset to another record.
- Q1077: Merge only the set fields from one record into another.
- Q1078: Replace all content in a List with another List.
- Q1079: Duplicate an endpoint config, then apply a partial timeout update to it.
- Q1080: Copy a child class including parent fields.
- Q1081: Merge two lists together using :~: operator.
- Q1082: Compare two Product records by price.
- Q1083: Check if two Config records have identical values.
- Q1084: Guard a comparison result when one sensor reading might be unset.
- Q1085: Sort a list of Employee records by salary.
- Q1086: Find the cheapest product in a list.
- Q1087: Check if all fields in a record have been set.
- Q1088: Check which fields are set in a partially-initialised record.
- Q1089: Write a custom override operator ? for a class with validation logic.
- Q1090: Define a PaymentRequest that is only 'set' when all three fields are present.
- Q1091: Provide a fallback display name when the user name is unset.
- Q1092: Get the smaller of two prices, even if one might be unset.
- Q1093: Chain multiple fallback values to find the first one that is set.
- Q1094: Convert a Customer record to both display string and JSON format.
- Q1095: Use a Coordinate record as a Dict key.
- Q1096: Verify that two equal objects produce the same hashcode.
- Q1097: Create a Product class with full operator support in one line.
- Q1098: Generate all operators with default, but customise the string representation.
- Q1099: Check if a greeting string contains the word 'world'.
- Q1100: Check if an email string matches a basic pattern.
- Q1101: Check if 'banana' is in a list of approved fruits.
- Q1102: Check if a score falls within the range 1 to 10.
- Q1103: Increment an Integer, a Float, and a Character value.
- Q1104: Get the absolute value of -42 and the square root of 16.
- Q1164: Build a formatted string with embedded expressions using backtick interpolation.
- Q1165: Split a comma-separated string into a list of fields.
- Q1166: Extract the first and last characters from a string.
- Q1184: Extract magic literals in comparisons into named constants to satisfy the compiler.
- Q1186: How do I compare two dates and determine which is earlier?
- Q1187: How do I check if a meeting time is before noon in EK9?
- Q1188: How do I compare two durations and find the shorter one using coalescing?
- Q1189: How do I compare two money amounts and find the cheaper price in EK9?
- Q1190: How do I check if two colours are equal and convert a colour to its string representation?
- Q1191: How do I compare two dimensions and determine which is longer?
- Q1192: How do I increment a character and compare two characters in EK9?
- Q1193: How do I compare screen resolutions and find the higher one in EK9?
- Q1194: How do I compare two timeout values in milliseconds in EK9?
- Q1195: How do I define an Event record with Date, Time, and String fields and compare two events?
- Q1200: Sum the line totals of an order where each line has a quantity and unit price in Money.
- Q1202: Calculate the time gap between two scheduled events.
- Q1205: Check if a Time value falls within business hours (09:00 to 17:00).
- Q1207: Build a list of Colour values and check if a specific colour is in the palette.
- Q1208: Find the earlier of two delivery dates, even if one is unknown.
- Q1209: Select the cheaper of two price quotes where one vendor hasn't responded.
- Q1210: Pick the shorter of two timeout durations for a retry policy.
- Q1211: Find the earlier meeting time from two optional schedule slots.
- Q1212: Get the lower of two sensor readings where one sensor might be offline.
- Q1213: Select the lower temperature from two weather stations.
- Q1214: Find the highest bid from two optional auction offers.
- Q1215: Determine the latest expiry date from two optional certificates.
- Q1216: Select the longer warranty period from two product options.
- Q1217: Get the higher score from two optional exam results.
- Q1218: Select the earlier-or-equal time from two shift starts.
- Q1219: Get the higher-or-equal temperature threshold.
- Q1226: Demonstrate the difference between <? coalescing and :=? guarded assignment.
- Q1227: Show all four coalescing comparison operators on Integer values.
- Q1228: Find the cheaper Product from two optional product records.
- Q1229: Select the higher-priority Task from two optional task records.
- Q1230: Sort two Measurement records by value and pick the smaller using <? coalescing.
- Q1231: Find the nearest Waypoint from two optional locations using <? on a class with distance.
- Q1232: Apply a default Configuration record only if no configuration was provided.
- Q1255: Create me a Product record and use the SINGLE-dollar $ operator to convert it to a plain-text human-readable String.
- Q1256: Create me a Customer record and use the DOUBLE-dollar $$ operator to convert it to a JSON representation — not plain text.
- Q1257: Write me a Booking class with a SINGLE-dollar $ operator that returns a human-readable reservation line — no JSON, just plain text.
- Q1258: Create me an Invoice class with a DOUBLE-dollar $$ operator that returns a JSON value — no plain-text formatting, only JSON.
- Q1259: Show me how to use the ++ and -- operators on an Integer counter, demonstrating that they are statement-only and modify the variable in place.
- Q1260: Show me how to use ++ and -- on a Float temperature reading, demonstrating that floating-point types also support in-place increment and decrement.
- Q1261: Show me how to use ++ on a Date to advance one day at a time, iterating through a week starting from a known date.
- Q1262: Show me how to use ++ on an enumeration to walk through ProcessState values (Pending → Running → Complete), demonstrating that walking past the last value makes the variable unset.
- Q1263: If I have a String variable that might be unset, how can I conditionally assign a default value to it only when it has not been set yet?
- Q1264: Walk me through using :=? on an Integer retry counter so that the counter only gets initialised on the first call and is preserved on subsequent calls.
- Q1265: How can I record a 'first seen' Date that is set on the first observation and never overwritten on subsequent observations, using :=?
- Q1266: Show me how to use :=? on a custom class field — give me a worked example where a UserSession class has a sessionToken that is set on first login and never overwritten.
- Q1315: Why does 'default operator' fail when a property's type has no operators?
- Q1320: Why can't I declare 'operator !=' on my EK9 type?
- Q1321: Why can't I declare 'operator not' on a type in EK9?
- Q1363: Can I apply a mutating operator like += to a method-call result?