Existential Operator / Null Propagation Operator
herby at mailbox.sk
Tue Apr 7 19:09:32 UTC 2015
Kevin Smith wrote:
> > Plus, it can be used for "normalizing" null/undefined to undefined:
> > var normalizedFoo = ?foo;
> > Seems sort of nice that it is separated and there are no special
> operations for ?., ?(, ?[.
> I agree, that is nice. But how does Nil get transformed into undefined?
While you do operations like call, construct, get on the reference
(obtaining another reference), it shortcuts to return Nil. Whenever you
are not in position to shortcut ref-to-ref (end of expression, for
example), and you actually needs a value, it just converts to undefined.
?a.b()['foo'] => "smalltalk-like"
(((('a' asRefIn: env) nilRefIfValueNullOrUndefined "ref, may be nil"
at: 'b') "returns ref, may be Nil"
callWithArguments: #()) "returns ref, may be Nil"
at: 'foo') "returns ref, may be Nil")
value "now, value is needed, ref needs to dereference"
Hopefully this sheds some light. If not, then I don't know how to
explain it someone with better pedagogy skill must weight in.
More information about the es-discuss