3 ms·
Erlang provides an 'if' expression as syntactic sugar for 'case' (switch), which must always have a true (else) clause. The 'if' form is strongly deprecated. E
by mikhailfranco 8y ago
Erlang provides an 'if' expression as syntactic sugar for 'case' (switch), which must always have a true (else) clause. The 'if' form is strongly deprecated.
Even the 'case' expression is mildly deprecated in favor of pattern matching and guards in function heads (definitions).
There are no null values, no classes and no inheritance, but the presence of atoms (arbitrary tokens that can be used like null, true, false or enumerations), and pattern matching (data polymorphism and destructuring), means that conditional execution is elegantly implemented by functions.
This is the second, often forgotten, meaning of functional programming. Providing functions as first-class types, supporting anonymous lambdas (closures), and applying functions over collections are given all the glory, but deprecating conditionals in favor of pattern matching over many fine-grained functions is just as significant.
- macintux 8y agoNow that I'm comfortable with Erlang, writing in any language that doesn't support branching at the function heads is so depressing.
- philsnow 8y agoalso not being able to write multiple versions of a function with different arity is annoying.
- macintux 8y agoVery very much so, good point.
- cbcoutinho 8y agoI recently started learning Clojure and using this pattern is immensely satisfying as well.
- TooBrokeToBeg 8y ago> There are no null values, Unbound variables are the equivalent (detected if used, at compile time), but a much saner way to deal with value-less variables