[erlang-questions] Question about lists:filter

David Mercer dmercer@REDACTED
Thu Aug 29 15:52:35 CEST 2013


On Thursday, August 29, 2013, Richard A. O'Keefe wrote:

> >> isPal(X)->integer_to_list(X)==lists:reverse(integer_to_list(X)).
> 
> 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.

Curiously enough, though, timingwise the following 2 seem to do roughly the same:

is_palindrome1(X) ->
	integer_to_list(X) == lists:reverse(integer_to_list(X)).

is_palindrome2(X) ->
	Digits = integer_to_list(X),
	Digits == lists:reverse(Digits).

Cheers,

DBM




More information about the erlang-questions mailing list