|
From: | Ron Stodden |
Subject: | Re: How to read a line of text? |
Date: | Wed, 07 Jan 2004 23:33:23 +1100 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031015 |
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! |
[Prev in Thread] | Current Thread | [Next in Thread] |