Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!Germany.EU.net!EU.net!uknet!festival!castle.ed.ac.uk!jlothian
From: jlothian@castle.ed.ac.uk (J Lothian)
Subject: Re: sscanf,sprintf in prolog
References: <marianne.799892869@coral.cs.jcu.edu.au> <D89Gs3.x8@ecrc.de>
Message-ID: <D8H8D7.26u@festival.ed.ac.uk>
Sender: news@festival.ed.ac.uk (Network News)
Organization: Edinburgh University
Date: Fri, 12 May 1995 17:53:30 GMT
Lines: 36

In article <D89Gs3.x8@ecrc.de>, joachim@ecrc.de (Joachim Schimpf) writes:
|> In article 799892869@coral.cs.jcu.edu.au, marianne@cs.jcu.edu.au (Marianne Brown) writes:
|> >
|> >I'm looking for a way to read from a string as opposed to from a stream -
|> >sort of a prolog equivalent to C's sscanf (and sprintf would be nice too).
|> 
|> 
|> There is no portable way of doing this. For ECLiPSe, the answer is:
|> 
|> Either term_string/2 (works both ways):
|> 
|>     term_string(Term, String)
|> 
|> Or using string I/O:
|> 
|>     sread(String, Term) :-
|>         open(String, string, Stream), read(Stream, Term), close(Stream).
|> 
|>     swrite(Term, String) :-
|>         open("", string, Stream), write(Stream, Term),
|>         current_stream(String, _, Stream), close(Stream).
|> 
|> 
Failing all else, the cheap-and-ugly semi-portable way
of doing this is of course to write the string to a file
and then read it back in. 

james
-- 

-------------------------------------------------------
James Lothian        |      "It's life, Jim, 
james@uk.ac.ed.caad  |   but not as we know it"
-------------------------------------------------------
          These opinions have nothing to do 
             with Edinburgh University.
