[erlang-questions] Erlang list comprehension optimization

caio ariede caio.ariede@REDACTED
Fri Mar 19 21:55:04 CET 2010


Just a small question.

http://www.erlang.org/doc/efficiency_guide/listHandling.html#id2261027

'lc^0'([E|Tail], Expr) ->
    Expr(E),
    'lc^0'(Tail, Expr);
'lc^0'([], _Expr) -> [].


Where this name ('lc^0') is generated?

Thanks

Caio Ariede
http://caioariede.com/


2010/3/17 Björn Gustavsson <bgustavsson@REDACTED>

> On Wed, Mar 17, 2010 at 5:07 AM, Robert Virding <rvirding@REDACTED>
> wrote:
> >
> > There is one strange thing further up in the text:
> >
> > "Lists comprehensions still have a reputation for being slow. They
> > used to be implemented using funs, which used to be slow."
> >
> > List comprehensions have never been implemented with funs, at least
> > not when they were first introduced. I know.
>
> Have a look the function lc_tq/3 starting at line 430 in R6B:
>
>
> http://github.com/mfoemmel/erlang-otp/blob/b48c3645b0e28fe61cb53771d2b84bfc30d48bad/lib/compiler/src/sys_pre_expand.erl
>
> It seems clear to me from the code that list comprehensions are
> rewritten to an expression that uses a fun. Also see the comment
> before the function. It says that because Erlang doesn't have letrecs, the
> lambda (fun) is explicitly passed as an extra argument.
>
> Nowadays, list comprehensions are translated to letrecs
> (which are available in Core Erlang), and the letrecs are in
> turn translated to ordinary recursive functions.
>
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list