A simple generator application

Dilton McGowan II diltonm at pacbell.net
Mon Oct 14 06:41:31 CEST 2002


Guess I missed your point Avery, maybe it's overly intellectually
stimulating. Doug wrote a piece of code that does something programmers need
to do every day, iterate directory trees and work with files. (Though I
agree with Oren about recursion, also Erik made a good point about the
copyright.)

I'm addressing your comment that your code *does* something. I grant that it
*may* do something.

Instead of taking aim, try helping load the ammo.

"Avery Andrews" <andrews at pcug.org.au> wrote in message
news:Pine.GSO.4.21.0210130849040.122-100000 at supreme.pcug.org.au...
>
>
> On Sat, 12 Oct 2002, Doug Fort wrote:
>
> > I'm interested in generators. I've read Dr. David Mertz's 'Charming
> > Python' articles (http://gnosis.cx/publish/tech_index_cp.html), and
> > the discussion here on c.l.p.
> >
> > I've been looking for an excuse to actually use a generator. I need to
put
> > include guards on a bunch of C++ header files. So I started out to
create
> > a generator that does what os.path.walk does, with yield in place of the
> > callback 'visitor' function.
> >
>
> Here's one that I just wrote that actually does something, basically
> combining two calls to an interface to AmziProlog into one convenient
> package, the context is looking at sequentially numbered lines of text
> where some line numbers appear twice (variants, errors, etc),
> 'next_line_num' is a 'deterministic' Prolog call that produces one answer,
> 'retrive_num_line' is a 'nondeterminstic one that produces multiple
> answers.  the results of the .run and .calls methods are basically
> copies of the argument with the capital letters filled out by whatever
> the Prolog engine can come up with, if anything, that makes the statements
> true; the argument-positions are then accessible by indexing:
>
>   #
>   # generator to smooth out call-redo cycle.  Might be better
>   #  if the Prolog were also rethought.
>   #
>   def LineGetter(engine, linenum=0):
>       #
>       # Loops indefinitely until it kills itself
>       #
>       engine.clearCall()
>       while (1):
>           lino=engine.run("next_line_num(%d,X)"%linenum)
>           if lino == None:
>               return
>           linenum = int(lino[2])
>           for result in
engine.calls("retrieve_num_line(%d,T,I,N,L)"%linenum):
>               yield result[1:6]
>
>
>





More information about the Python-list mailing list