Article View: comp.lang.prolog
Article #2047Re: converting ascii character lists to functors
From: Micha Meier
Date: Mon, 22 Apr 1991 11:54
Date: Mon, 22 Apr 1991 11:54
34 lines
2164 bytes
2164 bytes
In article <EIVERSON.91Apr19200202@aigyptos.nmsu.edu> eiverson@nmsu.edu (Eric Iverson) writes:
>Can you think of a way to do this which does not involve writing to,
>reading from, and then removing a file? The current routine is rather
>slow. Is there some way that I could just open up a stream, write
>things to it, and then read from it?
The string streams available in Sepia have proven to be a very useful
feature to implement such types of algorithms. They basically allow the user to
write data into a string and read it back or modify. It then looks like
:- open(S, string, s), % open the stream s into the string S
write(s, Data), % write Data there
seek(s, 0), % start reading from the beginning
read(s, NewData), % read the written stuff back
close(s). % get rid of the string stream
Sepia has also a built-in predicate term_string(?Term, ?String) which
makes the conversion between any term and its string form, which is
implemented using string streams. The advantage of using string streams
over pipes is that the string streams are completely processed withing the
Prolog system, without system calls, and the current form of the string
can be always obtained with :- current_stream(String, string, s).
Note that although one can also write into a given string, e.g. with
:- open("abcdef", string, s),
put(s, 0'b).
the original string is not destructed, and so the logical semantics
is preserved.
--Micha
--
E-MAIL micha@ecrc.de MAIL Micha Meier
ECRC, Arabellastr. 17
8000 Munich 81
Germany
Technical Details
Message-ID:
<1991Apr22.115409.5513@ecrc.de>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!ox.com!math.fu-berlin.de!fauern!unido!ecrc!michaReferences:
<EIVERSON.91Apr19200202@aigyptos.nmsu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!ox.com!math.fu-berlin.de!fauern!unido!ecrc!micha From: micha@ecrc.de (Micha Meier) Newsgroups: comp.lang.prolog Subject: Re: converting ascii character lists to functors Message-ID: <1991Apr22.115409.5513@ecrc.de> Date: 22 Apr 91 11:54:09 GMT References: <EIVERSON.91Apr19200202@aigyptos.nmsu.edu> Sender: news@ecrc.de Reply-To: micha@ecrc.de (Micha Meier) Distribution: comp Organization: European Computer-Industry Research Centre Lines: 34