[erlang-questions] Question about lists:filter
Thu Aug 29 07:05:26 CEST 2013
I proposed (a) eliminating obvious duplication from cand()
and (b) checking palindromicity by pattern matching rather
than making two copies of a list and reversing one of them.
I _believed_ the result should be faster.
reductions: go down by a factor of 1.88;
run time: goes down by a factor of 3.95.
One thing that will surprise anyone coming to Erlang from
Haskell is that the two calls to integer_to_list(X) are
_not_ merged into a single call by the compiler, so for an
n-digit number, you get 3n list cells here.
Since Erlang functions in general can have side effects, it is
in general unsafe to merge calls to the same function with the
same arguments. In the Erlang version I tried, the compiler
treated integer_to_list/1 like any other function.
More information about the erlang-questions