optimization of list comprehensions
Mats Cronqvist
mats.cronqvist@REDACTED
Wed Mar 8 11:07:00 CET 2006
Richard A. O'Keefe wrote:
> Mats Cronqvist <mats.cronqvist@REDACTED> wrote:
> foo(Xs) -> foo(Xs, root).
>
> foo([], A) -> A;
> foo([X|T], A) when is_atom(X) -> foo(T, {A,X});
> foo([_|T], A) -> foo(T, A).
>
> would look a lot better like this (using Per Gustafsson's syntax;
> http://www.erlang.org/ml-archive/erlang-questions/200603/msg00034.html)
>
> foo(Xs) ->
> ({A,X} || X<-Xs, A<--root, is_atom(X)).
>
> Er, weren't round parentheses the proposed syntax for
> "evaluate these expressions like a list comprehension but throw
> the results away and just return 'ok'"?
i see you didn't bother clicking on that link.
[deleted critique of the example syntax]
i think it has been made clear several times that i have no strong opinion
about what the notation should look like. i'll let the pro's deal with that.
> I am also extremely unconvinced by this example since it is a very very
> strange thing to want to compute.
[deleted critique of silly example]
the example was just that; an example, and kept deliberately simple at that.
the point of the example was that fold-like comprehensions would change the
way people write code. the new notation would be used instead of recursive
functions with guards and accumulators.
just like list comprehensions are now used much more frequently than one
would have estimated by looking at the (pre-lc) use of lists:map and lists:foreach.
> secondly; for whatever reason normal industry programmers(*)
> will rarely if ever use lists:fold* (or indeed anything that involves
> funs). they didn't use lists:map or lists:foreach either, but they do
> use list comprehensions.
>
> If you have evidence to back this up, it's publishable.
> Please publish it. Some sort of survey analysing what kind of
> programmers use what kind of language features would be most illuminating.
alas, i am not a researcher (any longer). but maybe i can find the time to
grep around a bit in the sources.
> But if I understand you, you are claiming that normal industry programmers
> are incompetent, ineducable, or both.
no, you do most certainly not understand me. and it actually seems you're
making a concious effort to misunderstand.
just for the record;
i don't think a reluctance to use funs indicates incompetence.
i am aware that my proposed syntax is not optimal, and possibly even "quite
astonishingly BAD".
i remain convinced that fold-like comprehensions would be an excellent thing,
just like map-like comprehensions were.
mats
More information about the erlang-questions
mailing list