[erlang-questions] behavior of lists:append/1
Thu Sep 19 12:36:50 CEST 2019
On 2019/09/19 17:29, Richard O'Keefe wrote:
> "Not checking for whether something is a properly formed list (the whole
> objection some have is that append/2 should be able to accept an
> improper list as the second argument) but merely checking whether the
> second argument is a list of any form at all."
> But what the heck is the point of *that*?
> Why is it important for [a] ++ c to fail
> but OK for [a] ++ [b|c] to succeed?
> I'm sorry, but that makes no sense to me at all.
You'd have to ask the OP.
The only reason I can think of would be to make sure I didn't change
something trivial in code somewhere and wind up passing a record or map
to append/2 without realizing it (crash on the first run/test/whatever).
But this is what I use Dialyzer for anyway.
The point of the thread was the feasibility of making a runtime check to
guarantee a crash if the arguments weren't lists instead of merely going
with "garbage in, garbage out". I can see some sense to that, but
wouldn't prioritize append/2 over all the other functions that expect
lists and *might* receive junk -- I certainly wouldn't want to make ALL
functions have runtime type checks!
The only place I put dynamic checks in my own code is when I'm
sanitizing data coming in from the outside. Everything else gets Dialyzed.
More information about the erlang-questions