<!--
  - Authors:
  -   Christian Schulte <schulte@ps.uni-sb.de>
  -
  - Contributors (sgml translation):
  -   Daniel Simon <dansim@ps.uni-sb.de>
  -   Andy Walter <anwalt@ps.uni-sb.de>
  -
  - Copyright:
  -   Christian Schulte, 1998
  -
  - Last change:
  -   $Date$ by $Author$
  -   $Revision$
  -
  - This file is part of Mozart, an implementation
  - of Oz 3
  -    http://www.mozart-oz.org
  -
  - See the file "LICENSE" or
  -    http://www.mozart-oz.org/LICENSE.html
  - for information on usage and redistribution
  - of this file, and for a DISCLAIMER OF ALL
  - WARRANTIES.
  -
  -->

<Chapter id="chapter.data">
  <Title/Data Structures/
  <P>
    Data written and sent from Mozart are <Def/virtual strings/<Index
    /strings<AND>virtual/, whereas data read and received are <Def
    class=noindex/strings/<Index/string/.  In the following we review
    these data types and show some operations which may prove helpful
    in the context of Open Programming.  Additional information on these
    data types can be found in <Ptr.extern to="ozdoc:base" key="chapter.text">.

  <Section id="section.data.strings">
    <Title/Strings/
    <P>
      Strings are lists of characters, with characters being small
      integers between 0 and 255.  For the coding of characters with
      integers we use the ISO&nbsp;8859-1 standard&nbsp;<Ptr to=ISO_8859_1>.
    <P>
      There are special operations on strings, like testing whether a given
      value&nbsp;<<X>> is a string, by <<{IsString X}>><Index class=module
      /IsString/.  For transforming strings into atoms, integers, or floats
      the procedures
      <List>
	<Item>
	  <<String.toAtom>><Index class=module/String<And>toAtom/,
	<Item>
	  <<String.toInt>><Index class=module/String<And>toInt/, and
	<Item>
	  <<String.toFloat>><Index class=module/String<And>toFloat/
      </List>
      are provided.  For testing whether a given string can be transformed
      into an atom, integer, or float, the procedures
      <List>
	<Item>
	  <<String.isAtom>><Index class=module/String<And>isAtom/,
	<Item>
	  <<String.isInt>><Index class=module/String<And>isInt/, and
	<Item>
	  <<String.isFloat>><Index class=module/String<And>isFloat/
      </List>
      are provided.
    <P>
      In addition, all functionality provided by the module <Span class=index
      /<<List>>/ is applicable.  It is especially useful in combination with
      the functionality provided by the module <Span class=index/<<Char>>/.
    <P>
      Suppose that after reading or receiving a string <<S="C@l!3E4aN#61!">>
      all characters which are neither uppercase nor lowercase letters must
      be filtered out.  This is achieved by using a combination of
      <Span class=index/<<Filter>>/ and <<Char.isAlpha>><Index class=module
      /Char<And>isAlpha/.  Feeding:
<chunk class=anoymous><title/{Filter S}/
{Browse {String.toAtom {Filter S Char.isAlpha}}}
</chunk>
      will show the cleaned information in the browser window.
    <P>
      Instead of creating an atom from the cleaned string, the browser offers
      functionality to display strings directly in a convenient form.  The
      functionality can be selected in the <Span class=menu/Representation,
      Type/ option, see also <Ptr.extern to="ozdoc:browser">.  For Example,
<chunk class=anoymous><title/{Browse S}/
{Browse {Filter S Char.isAlpha}}
</chunk>
      displays in the browser window the character sequence <<"ClEaN">>.
    <P>
      Remember that character codes for letters are syntactically supported.
      For instance, the string
      <<<"hi there">>>
      can be written equivalently as
      <<<[&amp;h &amp;i &amp;  &amp;t &amp;h &amp;e &amp;r &amp;e]>>>

  <Section id="section.data.virtualstrings">
    <Title/Virtual Strings/
    <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>
      Mozart uses <Def/virtual strings/<Index/strings<And>virtual/ for this
      purpose instead.  A virtual string is either an atom, a float, an
      integer, a string, or a tuple with label <<'#'>>, whose subtrees are
      virtual strings themselves.  For instance,
      <<<12#(2#fast#4#"U")#~3.1415>>>
      is a virtual string.  In the above example it is quite clear, that <<#>>
      stands for concatenation (&ie;, for <Em/virtual/ concatenation).
    <P>
      There is predefined functionality for virtual strings, like testing,
      by <Span class=index/<<IsVirtualString>>/, converting to a string,
      by <<VirtualString.toString>><Index class=module/VirtualString<And
      >toString/, and changing of signs, by <<VirtualString.changeSign>><Index
      class=module/VirtualString<And>changeSign/.  The latter procedure is
      quite important, because
<chunk class=anonymous><title/-/
{Browse 12#(2#fast#4#"U")#~3.1415}
</chunk>
      reveals that the usual unary minus sign (&ie;, <<->>) is used rather
      than the &Oz; operator&nbsp;<<~>>.
    <P>
      The procedure <<VirtualString.changeSign>> 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
      <<->>&nbsp;character as a unary minus sign in numbers of the first
      argument by the second argument.  For example,
<chunk class=anonymous><title/-~/
{VirtualString.changeSign 12#(2#fast#4#"U")#~3.1415 '~'}
</chunk>
      returns the virtual string with the &Oz;-style unary minus sign.
    <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/ option, see also <Ptr.extern to="ozdoc:browser">.  In the following we
      assume that the Browser is configured for displaying virtual strings.

<![ %EXTRA; [
<section><title/NONE/
<p>
<chunk><title/EXAMPLES/
%%%
%%% Chapter: Data Structures
%%%

%%
%% Strings
%%

declare
S="C@l!3E4aN#61!"

<chunk.ref/{Filter S}/

<chunk.ref/{Browse S}/


%%
%% Virtual Strings
%%

<chunk.ref/-/

{Browse <chunk.ref/-~/}



</chunk>
]]>

</Chapter>
