Re: Iterating over generic sequences.



On Sep 26, 6:32 pm, Kent M Pitman <pit...@xxxxxxxxxxx> wrote:

Pillsy <pillsb...@xxxxxxxxx> writes:
[...]
1. Using ELT with LOOP or DOTIMES (which seems needlessly inefficient,
especially for lists). The upside is that it's very simple.

It's also potentially O(n^2) since ELT is O(n) for lists. You do not
want to use ELT for much of anything, but most certainly you do not want
to use it for iterating across a list.

Yeah. That's the reason I never use it, but I never use it, so I
forgot why I never use it. :-/

Pascal wrote a solution to this, so I won't repeat that. But I just don't
see why you expect this to be better than a nice pretty call to MAP
(optionally abstracted into some other calling sequence if you know some
additional fact about return value or whatever that allows you to simplify
its notation further).

The main thing that started me thinking in that direction is probably
that I was doing something where I wanted to use LOOP (and drive
multiple variables at once and do some of the other LOOPy stuff),
which tends to be pretty awkward when you're using MAP. Then I wrote
an example that totally failed to capture that.

I also find it pretty helpful to have my misguided gut feelings
thoroughly refuted.

Cheers,
Pillsy

.



Relevant Pages

  • Re: Perl Performance Tuning
    ... >> choosing for vs map is more than just speed. ... even with shorter lists, there are times where map will take ... win over calling push inside a for (the push is more perl ops than the ... >> fix bugs when they were used outside their very tiny design envelope. ...
    (comp.lang.perl.misc)
  • Re: Perl Performance Tuning
    ... >> choosing for vs map is more than just speed. ... even with shorter lists, there are times where map will take ... longer than the equivilent explicit for/push loop (which is really what ... win over calling push inside a for (the push is more perl ops than the ...
    (comp.lang.perl.misc)
  • Re: HashSet is strange
    ... > actually what i would like to have is an interface as you have in ANSI ... Collection, List, Set, and maybe Map) ... Those defined on Lists and not on Sets are inapplicable to a Java Set ... > i would have never guessed that the removal of the keys from the keySet ...
    (comp.lang.java.programmer)
  • Re: coerce for arbitrary types
    ... sequence looking for a start sequence per that code then passing ... with two parts, CDR-chained lists, assoc lists, trees with only ... it's possible to define what a shallow copy of the container would ... except in the sense that a map can emulate a set ...
    (comp.lang.lisp)
  • Re: Cant figure out the algorithm
    ... (let ((fields (car data)) ... some map calls to avoid consing intermediate lists. ... Yes, and I have seen fold being used recently in a few posts, but I am not familar with it. ...
    (comp.lang.scheme)