Re: String is not string in SWI prolog , part/2.



On Thu, 25 May 2006 03:56:14 +0200, <newser.bbs@xxxxxxxxxxxxxxxxx> wrote:

) , I gave codes for getting line:
--------------------------------------------------------
assertz((get_line(L):-get_char(C),(C=end_of_file->copy_term('',L);C='\n'->c­opy_term(C,L);get_line(L1),atom_concat(C,L1,L)))).

assertz((eof:-get_char(C),(C=end_of_file,!;unget_char(C),fail))).
---------------------------------------------------------
In these codes , you can see that I use atoms for strings ,
(see the atom_concat ?)

swi has read_line_to_codes/[2,3], which can be used as a base.
I'd use:

newser_read_line(Stream,LineAsAtom,LineAsCodes) :-
read_line_to_codes(Stream,LineAsCodes),
( LineAsCodes = end_of_file
-> LineAsAtom = end_of_file
; atom_codes(LineAsAtom,LineAsCodes
).

But I have read about inside lisp before , and it is said that
an atom was presented as an ID Number inside lisp . If this is
also true in prolog , my represenation for strings might cause
problems. Eg for an web page of thousands of lines ,
the number of atoms it created might become up to millions,
thus millions of ID Numbers will be wasted unnecessarily and
it might cause slow-down in compiling or interpretation of
my program.

This is not a problem in swi prolog.

In other prolog implementations, it may or may not be a problem,
depending on whether they do or do not do atom garbage collection.

P.


--
Anything below this line is being added by the newsserver

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
.



Relevant Pages