Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!sun4nl!freya.let.rug.nl!vannoord
From: vannoord@let.rug.nl (Gertjan van Noord)
Subject: Re: DCGs
Sender: news@let.rug.nl (News system at let.rug.nl)
Message-ID: <1994Nov10.093544.5343@let.rug.nl>
Date: Thu, 10 Nov 1994 09:35:44 GMT
References:  <geoff.784440211@coral.cs.jcu.edu.au>
Nntp-Posting-Host: vidar.let.rug.nl
Organization: Faculteit der Letteren, Rijksuniversiteit Groningen, NL
Keywords: DCGs Lists
Lines: 22

In article <geoff.784440211@coral.cs.jcu.edu.au>, geoff@coral.cs.jcu.edu.au (Geoff Sutcliffe) writes:
> Hi,
> 
> One of the researchers in Building Management is using DCGs to some parsing
> of data files (yes, I'll tell him to submit to Prolog 1000!). He has a
> problem that the files are very large, so he cannot get all the tokens into
> a list to be submitted to the DCG. I've been trying to dream up a way of
> making 'demand driven lists' (ala Scheme's streams) for DCGs, but have 
> failed. The idea is that the tokens should only be read from the file when
> the DCG needs them for the parse. If backtracking is required in the parse
> then the tokens remain in memory as part of the list. Ha anyone a solution
> to this? Thanks for any suggestions.
> 

for a start, you probably shouldn't use lists in this case. Furthermore, if you're
lucky you're using a Prolog in which you are allowed to redefine 'C'. 
What you could do is use two pointers instead of a difference list. The predicate
'C'(P0,Terminal,P) could then be defined in such a way that it searches for the P'th
member of the datafile. Furthermore, you memo-ize this predicate such that upon
backtracking you don't have to redo this work.


