[erlang-questions] Erlang list comprehension optimization
Wed Mar 17 04:28:11 CET 2010
Vinayak Pawar wrote:
> Are these equivalent in terms of space utilization?
> 1) lists:foreach(fun(X) -> SomeOpFun(X) end, Xs).
> 2) [SomeOpFun(X) || X <- Xs].
> In case 1) output list isn't generated. In case 2) output list is generated,
> but it is not used(or not assigned to any variable). So in such cases, does
> Erlang VM optimize and doesn't create any temporary list?
"In R12B [and presumably later], if the result of the list comprehension
will *obviously* not be used, a list will not be constructed."
More information about the erlang-questions