[erlang-questions] Generators?

Ludovic Coquelle lcoquelle@REDACTED
Tue Jul 31 06:05:11 CEST 2007


How would you write it with python generator?

And yet another solution:
dot(L1,L2) ->
    {R, _} = lists:foldl(fun(X, {Acc, [Y|YT]}) -> {Acc + X*Y, YT} end, {0,
L2}, L1),
    R.

On 7/31/07, Ryan Rawson <ryanobjc@REDACTED> wrote:
>
> This is why language features > libraries generally. The compiler
> knows nothing, so it has limited optimization abilities.
>
> On a side note, most optimization strategies involve obtaining more
> info. Type system, pragmas, explicit syntax support, etc. Its cool
> stuff.
>
> -ryan
>
>
> On Jul 30, 2007, at 2:27 PM, "James Hague" <james.hague@REDACTED>
> wrote:
>
> >> But the problem is that these abstractions, or
> >> at least the combination of them, are slower than a hand-coded
> >> function explicit recursion function. So, is there any way to make
> >> the
> >> natural abstractions work as fast as the hand-coded version?
> >
> > It's interesting that list comprehensions are compiled into code that
> > acts the same as hand-coded functions, but uses of similar functions
> > like lists:foldl, lists:flatmap, and lists:partition are not.
> >
> > James
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070731/5b90bc53/attachment.htm>


More information about the erlang-questions mailing list