Re: Iterators [was: worth adding collections to the core language?]

2002-10-31 Thread Leopold Toetsch
Luke Palmer wrote:



I wonder if things should have a more general interface than
numerical indices.  I've wanted linked lists in perl, and every time I
do a splice on an array I cringe for speed reasons.

Heh, we could use my linked array implementation.  Or not.



Please have a look at list.c, which is the engine for *Array classes.



But I think we need a concept of iterators in the core.  


There were some patches floating around. Dunno what happened to them.



Luke



leo




Re: Iterators [was: worth adding collections to the core language?]

2002-10-30 Thread Luke Palmer
 Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
 Cc: [EMAIL PROTECTED] [EMAIL PROTECTED]
 From: Piers Cawley [EMAIL PROTECTED]
 Date: Wed, 30 Oct 2002 18:59:15 +
 X-SMTPD: qpsmtpd/0.12, http://develooper.com/code/qpsmtpd/
 
 Dave Storrs [EMAIL PROTECTED] writes:
 
  In the Re: Wh[ie]ther Infix Superposition ops thread
 
  On Wed, 30 Oct 2002, Piers Cawley wrote:
 
  But given a decent Collection hierarchy:
 
  my $seen = Set.new($start,$finish);
 
  for  - $next {
  print $next unless $next =~ $seen;
  $seen.insert($next);
  }
 
  Just a thought...are sets (or other Collection types) something that we
  use often enough that they would deserve to be in the core language?  I
  know I've used hashes as no-repeats-allowed sets many times, so clearly
  they are commonly useful.  On the other hand, since this can be done,
  maybe there is no need to implement a new core feature for them.
 
  I suspect the answer is no, we don't need them but I just thought I'd
  ask; I'm curious about the design reasons either way.
 
 Personally, I'd love to see something like the whole Smalltalk
 Collection hierarchy available complete with Bags, Sets, Dictionaries,
 OrderedCollections and the whole deal. I note, for instance that
 Christian Lemburg has implemented Set::Object, and it's substantially
 faster than a hash based implementation for insertion, and marginally
 faster for lookup. See
 http://search.cpan.org/author/JLLEROY/Set-Object-1.02/Object.pm#PERFORMANCE
 for Christian's numbers. I would hope that we could see other
 performance gains for other Collection classes. 

Well, to generalize the notion of array and hash wouldn't be that
difficult.  Change them, respectively, to ordered and unordered.

I wonder if @things should have a more general interface than
numerical indices.  I've wanted linked lists in perl, and every time I
do a splice on an array I cringe for speed reasons.

Heh, we could use my linked array implementation.  Or not.

But I think we need a concept of iterators in the core.  I like the
C++ STL because of it's generalization of iterators.  I think it's
worth repeating, rantexcept the part about declaring them taking a
page of code:

listactor::id_type::const_reverse_iterator = idlist.rbegin();

That's more hideous than anything Perl haters yell about.  At least
perl does something. I mean, in that many Perl characters people have
made computer algebra systems ;) 
/rant

So lets see, ... derefrences and increments its prisoner.  Perhaps
just ++ing and --ing would work.  Of course, I'd hate to use $iter--
for a derefrence without an increment.  Or, yes, of course!  Would it
be possible to overload prefix:$ ?  Then we could derefrence with the
derefrence operator $$iter.

Um, yeah, my mind is kinda scattered. Just a little bit.

Luke