5 ms·
JS went for a?.[b] https://github.com/tc39/proposal-optional-chaining#faq https://github.com/tc39/proposal-optional-chaining#faq
by 11235813213455 7y ago
JS went for a?.[b] https://github.com/tc39/proposal-optional-chaining#faq https://github.com/tc39/proposal-optional-chaining#faq
- asdfman123 7y agoI was trying to find which programming language did it first, because I knew C# did it well before JS, although I definitely wouldn't be surprised if they weren't the first. However, in my search I found a list of languages and how they use safe navigation operators: https://en.wikipedia.org/wiki/Safe_navigation_operator https://en.wikipedia.org/wiki/Safe_navigation_operator
- jbverschoor 7y agoSwift was earlier 2015-04-08
- pjmlp 7y agoInteresting enough that list fails to mention Eiffel, which was probably one of the first languages to handle nullability. https://www.eiffel.org/doc/eiffel/Void-safety-_Background%2C_definition%2C_and_tools https://www.eiffel.org/doc/eiffel/Void-safety-_Background%2C...
- goldenkey 7y agoProbably lisp, if we aren't counting syntax, since most standard or auxilary toolbelt libraries have had something similar since the age of programming languages: https://lodash.com/docs/4.17.15#get https://lodash.com/docs/4.17.15#get
- kazinator 7y agoInterLisp allowed (car nil) and (cdr nil) to safely yield nil, thus making it safe to probe list structure to any depth. This spread into other dialects and is that way in Common Lisp > In 1974, about a dozen persons attended a meeting at MIT between the MacLisp and Interlisp implementors, including Warren Teitelman, Alice Hartley, Jon L White, Jeff Golden, and Guy Steele. [ ... ] In the end only a trivial exchange of features resulted from “the great MacLisp/Interlisp summit”: MacLisp adopted from Interlisp the behavior (CAR NIL) → NIL and (CDR NIL) → NIL, and Interlisp adopted the concept of a read table. [Evolution of Lisp, https://www.dreamsongs.com/Files/HOPL2-Uncut.pdf https://www.dreamsongs.com/Files/HOPL2-Uncut.pdf] In the Common Lisp Object System, we can specialize any method to arguments of the null class, a type whose only element is nil. Thus for instance, if we have a generic function salary like this: (salary employee) then if employee is nil, this simply calls for the following primary method to exist: (defmethod salary ((emp null)) ...) This can return whatever you want: just nil, or zero or whatever is appropriate. If the method is not defined, then (salary nil) signals a condition.