Changes between Version 10 and Version 11 of ExpressionTour
- Timestamp:
- 05/31/13 09:24:44 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ExpressionTour
v10 v11 218 218 == Nil == 219 219 220 Operations and literals around nil/null values.[[BR]] 221 '''nil''' is the nil/null literal 222 223 EXPR to ? 224 - cast the type of EXPR to the nilable form of the same type (EXPR.typeOf?, nilable EXPR.typeof) 225 226 EXPR to ! 227 - cast the type of EXPR to the the non-nilable form of same type( EXPR.typeOf!) 220 Cobra has various operations and literals around nil/null values.[[BR]] 221 222 '''nil''' is the nil/null literal. 223 224 Cobra provides operators to allow coalescing of expressions that evaluate nil or non nil.[[BR]] 225 This saves an explicit nil comparison check and assignment in favor of a coalescing expression or augmented assignment. 226 227 '?' is nil coalesce operator[[BR]] 228 '!' is non-nil coalesce operator 228 229 229 230 EXPR ? EXPR1 … … 234 235 235 236 EXPR1 ?= EXPR1 236 - nil coalesce EXPR1 to itself or EXPR2237 - augmented assignment: nil coalesce EXPR1 to itself or EXPR2 237 238 - same as EXPR1 = EXPR1 ? EXPR2 238 239 239 240 EXPR1 != EXPR1 240 - non-nil coalesce EXPR1 to itself or EXPR2241 - augmented assignment: non-nil coalesce EXPR1 to itself or EXPR2 241 242 - same as EXPR = EXPR1 ! EXPR2 242 243 … … 247 248 #!cobra 248 249 249 if a is nil, print 'Bad a' 250 if a is nil, print 'Bad a' # explicit comparison and statement 250 251 251 252 y = a ? b # coalesce nil : y gets a if a non nil, b otherwise … … 264 265 }}} 265 266 267 See also wiki:NilableTypes 266 268 267 269 == Method References ==