<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>SWI-Prolog 8.5.15 Reference Manual: Section A.17</title><link rel="home" href="index.html"> <link rel="contents" href="Contents.html"> <link rel="index" href="DocIndex.html"> <link rel="summary" href="summary.html"> <link rel="previous" href="error.html"> <link rel="next" href="gensym.html"> <style type="text/css"> /* Style sheet for SWI-Prolog latex2html */ dd.defbody { margin-bottom: 1em; } dt.pubdef, dt.multidef { color: #fff; padding: 2px 10px 0px 10px; margin-bottom: 5px; font-size: 18px; vertical-align: middle; overflow: hidden; } dt.pubdef { background-color: #0c3d6e; } dt.multidef { background-color: #ef9439; } .bib dd { margin-bottom: 1em; } .bib dt { float: left; margin-right: 1.3ex; } pre.code { margin-left: 1.5em; margin-right: 1.5em; border: 1px dotted; padding-top: 5px; padding-left: 5px; padding-bottom: 5px; background-color: #f8f8f8; } div.navigate { text-align: center; background-color: #f0f0f0; border: 1px dotted; padding: 5px; } div.title { text-align: center; padding-bottom: 1em; font-size: 200%; font-weight: bold; } div.author { text-align: center; font-style: italic; } div.abstract { margin-top: 2em; background-color: #f0f0f0; border: 1px dotted; padding: 5px; margin-left: 10%; margin-right:10%; } div.abstract-title { text-align: center; padding: 5px; font-size: 120%; font-weight: bold; } div.toc-h1 { font-size: 200%; font-weight: bold; } div.toc-h2 { font-size: 120%; font-weight: bold; margin-left: 2em; } div.toc-h3 { font-size: 100%; font-weight: bold; margin-left: 4em; } div.toc-h4 { font-size: 100%; margin-left: 6em; } span.sec-nr { } span.sec-title { } span.pred-ext { font-weight: bold; } span.pred-tag { float: right; padding-top: 0.2em; font-size: 80%; font-style: italic; color: #fff; } div.caption { width: 80%; margin: auto; text-align:center; } /* Footnotes */ .fn { color: red; font-size: 70%; } .fn-text, .fnp { position: absolute; top: auto; left: 10%; border: 1px solid #000; box-shadow: 5px 5px 5px #888; display: none; background: #fff; color: #000; margin-top: 25px; padding: 8px 12px; font-size: larger; } sup:hover span.fn-text { display: block; } /* Lists */ dl.latex { margin-top: 1ex; margin-bottom: 0.5ex; } dl.latex dl.latex dd.defbody { margin-bottom: 0.5ex; } /* PlDoc Tags */ dl.tags { font-size: 90%; margin-left: 5ex; margin-top: 1ex; margin-bottom: 0.5ex; } dl.tags dt { margin-left: 0pt; font-weight: bold; } dl.tags dd { margin-left: 3ex; } td.param { font-style: italic; font-weight: bold; } /* Index */ dt.index-sep { font-weight: bold; font-size: +1; margin-top: 1ex; } /* Tables */ table.center { margin: auto; } table.latex { border-collapse:collapse; } table.latex tr { vertical-align: text-top; } table.latex td,th { padding: 2px 1em; } table.latex tr.hline td,th { border-top: 1px solid black; } table.frame-box { border: 2px solid black; } </style> </head> <body style="background:white"> <div class="navigate"><a class="nav" href="index.html"><img src="home.gif" alt="Home"></a> <a class="nav" href="Contents.html"><img src="index.gif" alt="Contents"></a> <a class="nav" href="DocIndex.html"><img src="yellow_pages.gif" alt="Index"></a> <a class="nav" href="summary.html"><img src="info.gif" alt="Summary"></a> <a class="nav" href="error.html"><img src="prev.gif" alt="Previous"></a> <a class="nav" href="gensym.html"><img src="next.gif" alt="Next"></a> </div> <h2 id="sec:fastrw"><a id="sec:A.17"><span class="sec-nr">A.17</span> <span class="sec-title">library(fastrw): Fast reading and writing of terms</span></a></h2> <p><a id="sec:fastrw"></a> <dl class="tags"> <dt class="tag">Compatibility</dt> <dd> The format is not compatible to SICStus/Ciao (which are not compatible either). Future versions of this library might implement a different encoding. </dd> <dt class="tag">bug</dt> <dd> The current implementation of <a class="pred" href="fastrw.html#fast_read/1">fast_read/1</a> <b>is not safe</b>. It is guaranteed to safely read terms written using <a class="pred" href="fastrw.html#fast_write/1">fast_write/1</a>, but may crash on arbitrary input. The implementation does perform some basic sanity checks, including validation of the magic start byte. </dd> <dt class="tag">To be done</dt> <dd> Establish a portable binary format. </dd> </dl> <p>This library provides the SICStus and Ciao <code>library(fastrw)</code> interface. The idea behind this library is to design a fast serialization for Prolog terms. Ideally, this should be portable between Prolog implementation. Unfortunately there is no portably binary term format defined. <p>The current implementation is based on PL_record_external(), which provides a binary representation of terms that is processed efficiently and can handle subterm sharing, cycles and attributed variables. In other words, this library can handle any Prolog term except <i>blobs</i> such as stream handles, database references, etc. We try to keep the format compatible between versions, but this is not guaranteed. Conversion is always possible by reading a database using the old version, dump it using <a class="pred" href="termrw.html#write_canonical/1">write_canonical/1</a> and read it into the new version. <p>This library is built upon the following built in predicates: <p> <ul class="latex"> <li><a class="pred" href="IO.html#fast_term_serialized/2">fast_term_serialized/2</a> translates between a term and its serialization as a byte string. <li><a class="pred" href="IO.html#fast_read/2">fast_read/2</a> and <a class="pred" href="IO.html#fast_write/2">fast_write/2</a> read/write binary serializations. </ul> <dl class="latex"> <dt class="pubdef"><a id="fast_read/1"><strong>fast_read</strong>(<var>-Term</var>)</a></dt> <dd class="defbody"> The next term is read from current standard input and is unified with <var>Term</var>. The syntax of the term must agree with fast_read / fast_write format. If the end of the input has been reached, <var>Term</var> is unified with the term <code>end_of_file</code>.</dd> <dt class="pubdef"><a id="fast_write/1"><strong>fast_write</strong>(<var>+Term</var>)</a></dt> <dd class="defbody"> Output <var>Term</var> in a way that <a class="pred" href="fastrw.html#fast_read/1">fast_read/1</a> and <a class="pred" href="IO.html#fast_read/2">fast_read/2</a> will be able to read it back.</dd> <dt class="pubdef"><a id="fast_write_to_string/3"><strong>fast_write_to_string</strong>(<var>+Term, -String, ?Tail</var>)</a></dt> <dd class="defbody"> Perform a fast-write to the difference-slist <var>String</var><code>\</code><var>Tail</var>. </dd> </dl> <p></body></html>