[gambit-list] Seekable String Ports

Taylor Venable taylor at metasyntax.net
Sat Jun 13 11:55:36 EDT 2009


On Fri, Jun 12, 2009 at 08:12:48AM +0100, David Rush wrote:
> 2009/6/12 Taylor Venable <taylor at metasyntax.net>:
> > I'm trying to write a parser combinator library, and part of that
> > entails some rewinding of streams for ordered-choice operations (as
> > illustrated above). ?A potential alternative would be to duplicate the
> > port's contents and use a different port for each alternative, but I
> > am not aware of any API to do this either. ?Any ideas on how to
> > accomplish this objective?
> 
> I realize this is not what you are looking for, but when I hit this
> kind of problem in the lisp world, I found that life became much
> simpler by using a list of chars than by using string-ports (or ports
> of any kind for that matter). Yes it's expensive in terms of memory,
> but it's not that often that you need to keep the original full text
> very far into the computation...

Thanks for the idea; I hadn't thought of that one yet.  I implemented
it and it's working well for small things, so I think I'll implement a
backend to fill a char list buffer from a port source, and let the
functions that need to back-track (e.g. choice) decide when they can
empty the buffer (e.g. on success of a child, for choice).

I'll have to examine the various stream implementations that have been
proposed as well.  Thanks to all for the pointers and advice.

-- 
Taylor Christopher Venable
http://real.metasyntax.net:2357/



More information about the Gambit-list mailing list