From: John Thingstad
Subject: Efficient iterators?
Date: 
Message-ID: <op.t9anforrut4oq5@pandora.alfanett.no>
Anyone know a efficient way of eliminating runtime checks on iterators?
Mine seem first to need a type dispatch (or method specialisation), then  
various conditions to be called each time. Beyond compiling the function  
with the variables instated at runtime I can't see a way around this.

--------------
John Thingstad

From: Scott Burson
Subject: Re: Efficient iterators?
Date: 
Message-ID: <14723225-deb4-4e49-a1c0-d09876440ec6@s13g2000prd.googlegroups.com>
On Apr 8, 6:22 am, "John Thingstad" <·······@online.no> wrote:
> Anyone know a efficient way of eliminating runtime checks on iterators?
> Mine seem first to need a type dispatch (or method specialisation), then
> various conditions to be called each time. Beyond compiling the function
> with the variables instated at runtime I can't see a way around this.

I'm not sure I understand your question, but have you tried using
closures as iterators?  My impression (which anyone who really cares
should verify on their own; I'm not certain) is that this approach is
faster than using an instance, in most implementations anyway.

So, for example:

(defmethod iterator ((list list))
  (lambda (op)
    (ecase op
      (:get (pop list))
      (:more? list))))

This way you get rid of the type dispatch on each iteration.

Does that help?

-- Scott
From: John Thingstad
Subject: Re: Efficient iterators?
Date: 
Message-ID: <op.t9aygcs1ut4oq5@pandora.alfanett.no>
P� Tue, 08 Apr 2008 18:03:17 +0200, skrev Scott Burson  
<········@gmail.com>:

> On Apr 8, 6:22 am, "John Thingstad" <·······@online.no> wrote:
>> Anyone know a efficient way of eliminating runtime checks on iterators?
>> Mine seem first to need a type dispatch (or method specialisation), then
>> various conditions to be called each time. Beyond compiling the function
>> with the variables instated at runtime I can't see a way around this.
>
> I'm not sure I understand your question, but have you tried using
> closures as iterators?  My impression (which anyone who really cares
> should verify on their own; I'm not certain) is that this approach is
> faster than using an instance, in most implementations anyway.
>
> So, for example:
>
> (defmethod iterator ((list list))
>   (lambda (op)
>     (ecase op
>       (:get (pop list))
>       (:more? list))))
>
> This way you get rid of the type dispatch on each iteration.
>
> Does that help?
>
> -- Scott

Yes, something like that.

--------------
John Thingstad
From: vanekl
Subject: Re: Efficient iterators?
Date: 
Message-ID: <ftg581$nof$1@aioe.org>
John Thingstad wrote:
> Anyone know a efficient way of eliminating runtime checks on iterators?
> Mine seem first to need a type dispatch (or method specialisation), then 
> various conditions to be called each time. Beyond compiling the function 
> with the variables instated at runtime I can't see a way around this.
> 
> --------------
> John Thingstad

Ron's take on iterators
http://rondam.blogspot.com/2008/02/joy-of-iterators.html
From: Marco Antoniotti
Subject: Re: Efficient iterators?
Date: 
Message-ID: <d7ecbf60-4315-4e67-a72a-fe55ffa0d755@k37g2000hsf.googlegroups.com>
On Apr 8, 6:05 pm, vanekl <·····@acd.net> wrote:
> John Thingstad wrote:
> > Anyone know a efficient way of eliminating runtime checks on iterators?
> > Mine seem first to need a type dispatch (or method specialisation), then
> > various conditions to be called each time. Beyond compiling the function
> > with the variables instated at runtime I can't see a way around this.
>
> > --------------
> > John Thingstad
>
> Ron's take on iteratorshttp://rondam.blogspot.com/2008/02/joy-of-iterators.html

http://common-lisp.net/project/cl-enumeration/ (shameless plug)

--
Marco
From: John Thingstad
Subject: Re: Efficient iterators?
Date: 
Message-ID: <op.t9awobwrut4oq5@pandora.alfanett.no>
P� Tue, 08 Apr 2008 15:22:26 +0200, skrev John Thingstad  
<·······@online.no>:

> Anyone know a efficient way of eliminating runtime checks on iterators?
> Mine seem first to need a type dispatch (or method specialisation), then  
> various conditions to be called each time. Beyond compiling the function  
> with the variables instated at runtime I can't see a way around this.
>

Thanks all.
But I think I have found what I am looking for in Edi Weitz closure  
composition in CL-PPCRE.

--------------
John Thingstad