Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 1520

mozart-1.4.0-1mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>2.2 Virtual Strings</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node3.html#section.data.strings">&lt;&lt; Prev</A></TD><TD><A href="node2.html">- Up -</A></TD></TR></TABLE><DIV id="section.data.virtualstrings"><H2><A name="section.data.virtualstrings">2.2 Virtual Strings</A></H2><P> The data to be sent or to be written consists of a sequence of integers, atoms, floats, and strings. If only strings were allowed to be sent as information, the data would have to be transformed into a string. This would be clumsy and inefficient with regard to both space and time. </P><P> Mozart uses <A name="label32"></A><EM>virtual strings</EM><A name="label33"></A> for this purpose instead. A virtual string is either an atom, a float, an integer, a string, or a tuple with label <CODE><SPAN class="string">'#'</SPAN></CODE>, whose subtrees are virtual strings themselves. For instance, </P><BLOCKQUOTE class="code"><CODE>12<SPAN class="keyword">#</SPAN>(2<SPAN class="keyword">#</SPAN>fast<SPAN class="keyword">#</SPAN>4<SPAN class="keyword">#</SPAN><SPAN class="string">&quot;U&quot;</SPAN>)<SPAN class="keyword">#~</SPAN>3<SPAN class="keyword">.</SPAN>1415</CODE></BLOCKQUOTE><P> is a virtual string. In the above example it is quite clear, that <CODE><SPAN class="keyword">#</SPAN></CODE> stands for concatenation (i.&nbsp;e., for <EM>virtual</EM> concatenation). </P><P> There is predefined functionality for virtual strings, like testing, by <A name="label34"></A><SPAN class="index"><CODE>IsVirtualString</CODE></SPAN>, converting to a string, by <CODE>VirtualString<SPAN class="keyword">.</SPAN>toString</CODE><A name="label36"></A>, and changing of signs, by <CODE>VirtualString<SPAN class="keyword">.</SPAN>changeSign</CODE><A name="label38"></A>. The latter procedure is quite important, because </P><DL class="anonymous"><DD class="code"><CODE>{Browse&nbsp;12<SPAN class="keyword">#</SPAN>(2<SPAN class="keyword">#</SPAN>fast<SPAN class="keyword">#</SPAN>4<SPAN class="keyword">#</SPAN><SPAN class="string">&quot;U&quot;</SPAN>)<SPAN class="keyword">#~</SPAN>3<SPAN class="keyword">.</SPAN>1415}</CODE></DD></DL><P> reveals that the usual unary minus sign (i.&nbsp;e., <CODE><SPAN class="keyword">-</SPAN></CODE>) is used rather than the Oz operator&nbsp;<CODE><SPAN class="keyword">~</SPAN></CODE>. </P><P> The procedure <CODE>VirtualString<SPAN class="keyword">.</SPAN>changeSign</CODE> provides the possibility to choose any virtual string as minus sign in numbers. It takes as input arguments two virtual strings, and substitutes every occurrence of the <CODE><SPAN class="keyword">-</SPAN></CODE>&nbsp;character as a unary minus sign in numbers of the first argument by the second argument. For example, </P><DL class="anonymous"><DD class="code"><CODE>{VirtualString<SPAN class="keyword">.</SPAN>changeSign&nbsp;12<SPAN class="keyword">#</SPAN>(2<SPAN class="keyword">#</SPAN>fast<SPAN class="keyword">#</SPAN>4<SPAN class="keyword">#</SPAN><SPAN class="string">&quot;U&quot;</SPAN>)<SPAN class="keyword">#~</SPAN>3<SPAN class="keyword">.</SPAN>1415&nbsp;<SPAN class="string">'~'</SPAN>}</CODE></DD></DL><P> returns the virtual string with the Oz-style unary minus sign. </P><P> Note that in order to display virtual strings in readable form in the Oz Browser, you have to configure the <SPAN class="menu">Representation, Type</SPAN> option, see also <A href="../browser/index.html">``The Oz Browser''</A>. In the following we assume that the Browser is configured for displaying virtual strings. </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node3.html#section.data.strings">&lt;&lt; Prev</A></TD><TD><A href="node2.html">- Up -</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian&nbsp;Schulte</A><BR><SPAN class="version">Version 1.4.0 (20090610)</SPAN></ADDRESS></BODY></HTML>