|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
inserting stuff at beginning of a streamHi all,
I almost know this is an elementary question, but as I seem to struggle... I wonder how one could `push' stuff to the *beginning* of a file in SWI. Appending stuff at the end of a stream is easy, with open(File, append, ID), write(ID, stuff). But how do I insert stuff at the beginning? I tried open(File, update, ID), write(ID, stuff) and realised this *replaces* the beginning of the File with stuff, rather than inserting it (and pushing the File content after it). Advice would be appreciated. Yo _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: inserting stuff at beginning of a streamHello,
On Mon, Oct 26, 2009 at 1:14 AM, Yo Sato <yosato16@...> wrote: > > I almost know this is an elementary question, but as I seem to > struggle... I wonder how one could `push' stuff to the *beginning* of a > file in SWI. Appending stuff at the end of a stream is easy, with > > open(File, append, ID), write(ID, stuff). > > But how do I insert stuff at the beginning? I tried > > open(File, update, ID), write(ID, stuff) > > and realised this *replaces* the beginning of the File with stuff, rather > than inserting it (and pushing the File content after it). Did you try writing to a new file, as in: open(New_file, write, Out_stream), write(Out_stream, Stuff), open(File, read, In_stream), copy_stream_data(In_stream, Out_stream)... % This uses put_code/2 HTH, -- Nicolas _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
|
|
|
Re: Re: inserting stuff at beginning of a stream Yo:
There is perhaps another alternative. SWI-Prolog provides a "memory file" library that is roughly equivalent to Smalltalk's ReadWriteStream class. You can create a memory-based virtual file that implements the stream interface. If your stuff is small, this may be the way to go. Example is attached. Regards, Jeff R. From: Yo Sato <yosato16@...> To: swi-prolog@... Sent: Fri, Oct 30, 2009 9:18 am Subject: [SWIPL] Re: inserting stuff at beginning of a stream Thanks Nicolas, this seems to work fine ('copy_stream_data/2' is very
|
| Free embeddable forum powered by Nabble | Forum Help |