users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to read a line of text?


From: Alexander V. Diemand
Subject: Re: How to read a line of text?
Date: Wed, 07 Jan 2004 14:44:15 +0100
User-agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.5) Gecko/20031107 Thunderbird/0.3

Ron Stodden wrote:

> Vic, of course I can, and did, use get_char, but something like
> swi-prolog's read_line_to_codes(Stream,Codes)  from its readutil
> library followed by atom_codes(Line,Codes)does a fast efficient
> job.      gprolog lacks such a library.
>
> Space efficiency is critically important and is compromised by a
> get_char solution, even when I've done a subsequent contrived fail
> to clear the stacks.     gprolog has no garbage collector (yet?),
> but swi-prolog has.
>
> My current development program tops out a 256K RAM 2.0 GHz machine
> with a 1GB swap file and uses about 20% CPU, 100% swap, and 89%
> memory (-> severe thrashing) whereas it runs at top speed under
> swi-prolog.      The two languages are virtually identical and
> directly interchangable except swi-prolog has modules but gprolog
> not.
>
> However, despite its ahortcomings gprolog has the nicer and much
> sounder quality of implementation.
>
>
> Vic Bancroft wrote:
>
>> On Sun, 4 Jan 2004, Ron Stodden wrote:
>>
>>
>>
>>> How to read lines from a text file to a list in gprolog?
>>>
>>>
>>
>> Have you tried open/3 ?  This can be used to create a Stream that
>> can then be read one character at a time using get_code/2  . . .
>>
>>
>>
>>
>>> I have unsuccessfully tried all the read variants, the best so
>>> far being read_char, but that leads to 'atom table full' under
>>> gplc when reading a text file of 3090 lines, 238,153 characters
>>> on my 256KB ram machine. That is no good, period!
>>>
>>>
>>
>> Yea, many of the predicates are for reading and parsing prolog
>> code.
>>
>>
>>
>>> I feel a read_line description must be missing from the
>>> documentation?
>>>
>>>
>>
>> One can construct such a thing, though it might be fun to do some
>> wrapper for the GNU readline library.
>>
>>
>>
>>> There are no examplesPL of any input/output!
>>>
>>>
>>
>> Perhaps one can see the idea from a working example,
>>
>> http://aisun0.ai.uga.edu/~bancroft/pub/gplfaq/faq_parse.pl
>>
>> That code runs over the gprolog mailing list archives without
>> difficulty. It even records every word with occurrence counts,
>> two place transitions between words with occurrence counts, three
>> place transitions with occurrence counts and messege intervals.
>> I have run it across a archive file that is 1.8M . . .
>>
>> more, l8r, v
>>
>>
>>
>
> -- Ron. [Melbourne, Australia] "If you keep a green bough in your
> heart, the singing bird will come" Get Fastest Mandrake downloader,
> English-only, from: http://members.optusnet.com.au/ronst/    <---
> Last Change 2nd November!
>
>
> ----------------------------------------------------------------------
>
>
> _______________________________________________ Users-prolog
> mailing list address@hidden
> http://mail.gnu.org/mailman/listinfo/users-prolog


Hi,

I somehow missed the discussion but want to throw my 2c in:

the trick is to avoid working with "atoms" when reading files but to
use lists of characters. memory space for atoms is limited, lists
consume stack space (dynamic, released).

Since ages I am using a small toolbox in pure Prolog code. It has
recently been published:
http://apax.net/swpets/plg_p3.html

The predicate you might be interested in is read_txtline/2. It returns
a list of characters read from a (file) stream.

example:

open('file.txt',read,Str), repeat, read_txtline(Str,Line),
parseline(Line), at_end_of_stream(Str), close(Str).

% matches  "From:"
parseline([70,114,111,109,58|R]) :-
   do_some_thing.
% matches "To:"
parseline([84,111,58|R]) :-
   do_some_thing_else.
% fallback
parseline(_).


hope that helps

Alex.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]