3 ms·
foo(_Else). -> undefined. Doesn't seem very erlangy. I'd expect a runtime error, as someone's passed foo() the wrong value.
by mml 11y ago
foo(_Else). -> undefined. Doesn't seem very erlangy. I'd expect a runtime error, as someone's passed foo() the wrong value.
- kevinwang 11y agoBut in the given example, isn't foo(_Else) = foo1(_Else) = undefined anyways?
- simoncion 11y ago> Doesn't seem very erlangy. I'd expect a runtime error, as someone's passed foo() the wrong value. It depends. Sometimes you want to crash when handed an unexpected value. Sometimes you expect that you'll be handed unexpected values and need to either fail more gracefully, print a warning and then fail, or warn and keep going, or whatever. Erlang gives you a bunch of tools, and they all have their place. [0] :) [0] With the possible exception of the if statement... which is of questionable utility.
- asabil 11y agoThe "if" keyword should have been "when" instead. It's useful in some cases, but rarely used.