Getting the position of a list item

Tim Fletcher twoggle@REDACTED
Thu Dec 3 22:50:05 CET 2009

> I usually see code like this implemented like this:
> base32_decode2(Char) when Char>=$0, Char=<$9 ->
>     Char-47;
> base32_decode2(Char) when Char>=$b, Char=<$h ->
>     Char-87;
> base32_decode2(Char) when Char>=$j, Char=<$k ->
>     Char-88;
> base32_decode2(Char) when Char>=$m, Char=<$n ->
>     Char-89;
> base32_decode2(Char) when Char>=$p, Char=<$z ->
>     Char-90.

Sure, that's the style i'd usually use for similar problems, but
because there were gaps in the sequence of letters i thought that the
2 shorter functions would be better than the one longer one.

Something like "0123456789bcdefghjkmnpqrstuvwxyz".index(char) is
pretty succinct in comparison, but then languages like Python, Ruby
etc. don't have the pattern matching as an alternative, so the index
function is more idiomatic there.


More information about the erlang-questions mailing list