Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 5154

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>strings and nets</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="__sl_sl_sl.html">next</a> | <a href="_numeric_sptypes.html">previous</a> | <a href="_lists_spand_spsequences.html">forward</a> | <a href="_numeric_sptypes.html">backward</a> | <a href="___The_sp__Macaulay2_splanguage.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_strings_spand_spnets.html" title="">strings and nets</a></div>
<hr/>
<div><h1>strings and nets</h1>
<div>In this section we discuss strings and nets.  Strings are sequences of characters intended to be printed, and are encountered almost every programming language.  Nets are two-dimensional arrays of characters intended to be printed, and constitute a natural generalization of strings that makes ascii printing of complicated objects much easier.<h2>strings</h2>
A string is a sequence of characters.  Strings can be manipulated in various ways to produce printed output.  One enters a string by surrounding a sequence of characters with quotation marks.<table class="examples"><tr><td><pre>i1 : "abcdefghij"

o1 = abcdefghij</pre>
</td></tr>
</table>
Strings may contain newline characters.<table class="examples"><tr><td><pre>i2 : "abcde
     fghij"

o2 = abcde
     fghij</pre>
</td></tr>
</table>
Strings, like anything else, can be assigned to variables.<table class="examples"><tr><td><pre>i3 : w = "abcdefghij"

o3 = abcdefghij</pre>
</td></tr>
</table>
<p>There are escape sequences that make it possible to enter special characters, see <a href="__dq.html" title="delineate a string with quotation marks">"</a>.</p>
<table class="examples"><tr><td><pre>i4 : u = "abc\101\102\n\tstu"

o4 = abcAB
             stu</pre>
</td></tr>
</table>
<p>We can use <a href="_peek.html" title="examine contents of an object">peek</a> to see what characters are in the string.</p>
<table class="examples"><tr><td><pre>i5 : peek u

o5 = "abcAB
     \tstu"</pre>
</td></tr>
</table>
Another way to enter special characters into strings is to use <a href="__sl_sl_sl.html" title="delineate a string with slashes">///</a> as the string delimiter.  That makes it easier to enter the special characters into the string, but impossible to enter three consecutive slashes.<table class="examples"><tr><td><pre>i6 : ///a \ n = "c"///

o6 = a \ n = "c"</pre>
</td></tr>
</table>
The function <a href="_ascii.html" title="ASCII character conversion">ascii</a> converts strings to lists of ascii character code, and back again.<table class="examples"><tr><td><pre>i7 : ascii u

o7 = {97, 98, 99, 65, 66, 10, 9, 115, 116, 117}

o7 : List</pre>
</td></tr>
<tr><td><pre>i8 : ascii oo

o8 = abcAB
             stu</pre>
</td></tr>
</table>
We may use the operator <a href="__vb.html" title="a binary operator, often used for horizontal concatenation">|</a> to concatenate strings.<table class="examples"><tr><td><pre>i9 : w|w|w

o9 = abcdefghijabcdefghijabcdefghij</pre>
</td></tr>
</table>
The operator <a href="__sh.html" title="length, or access to elements">#</a> computes the length of a string.<table class="examples"><tr><td><pre>i10 : #w

o10 = 10</pre>
</td></tr>
</table>
We may also use the operator <a href="__sh.html" title="length, or access to elements">#</a> to extract single characters from a string.  Warning: we number the characters starting with 0.<table class="examples"><tr><td><pre>i11 : w#5

o11 = f</pre>
</td></tr>
</table>
The function <a href="_substring.html" title="extract part of a string">substring</a> will extract portions of a string for us.<table class="examples"><tr><td><pre>i12 : substring(5,w)

o12 = fghij</pre>
</td></tr>
<tr><td><pre>i13 : substring(5,2,w)

o13 = fg</pre>
</td></tr>
</table>
<h2>nets</h2>
A net is a rectangular two-dimensional array of characters, together with an imaginary horizontal baseline that allows nets to be assembled easily into lines of text.  A string is regarded as a net with one row.<p>Nets are used extensively for such things as formatting polynomials for display on ascii terminals.  Use <a href="_net.html" title="format for printing, as a net">net</a> to obtain such nets directly.</p>
<table class="examples"><tr><td><pre>i14 : R = ZZ[x,y];</pre>
</td></tr>
<tr><td><pre>i15 : (x+y)^2

       2           2
o15 = x  + 2x*y + y

o15 : R</pre>
</td></tr>
<tr><td><pre>i16 : n = net oo

       2           2
o16 = x  + 2x*y + y</pre>
</td></tr>
</table>
The net <tt>n</tt> above looks exactly the same as the original polynomial - that's because a polynomial is printed by printing its net.  But the net <tt>n</tt> is no longer usable as a polynomial; it's just an array of characters.  We may use <a href="_peek.html" title="examine contents of an object">peek</a> to clarify the extent of a net.<table class="examples"><tr><td><pre>i17 : peek n

      +--------------+
      | 2           2|
o17 = |x  + 2x*y + y |
      +--------------+</pre>
</td></tr>
</table>
One way to create nets directly is with the operator <tt>||</tt>, which concatenates strings or nets vertically.<table class="examples"><tr><td><pre>i18 : x = "a" || "bb" || "ccc"

o18 = a
      bb
      ccc</pre>
</td></tr>
</table>
We may use the operator <a href="_^.html" title="a binary operator, usually used for powers">^</a> to raise or lower a net with respect to its baseline.  Look carefully to see how the baseline has moved - it is aligned with the equal sign.<table class="examples"><tr><td><pre>i19 : x^2

      a
      bb
o19 = ccc</pre>
</td></tr>
</table>
Nets may appear in lists, and elsewhere.<table class="examples"><tr><td><pre>i20 : {x,x^1,x^2}

                 a
            a    bb
o20 = {a  , bb , ccc}
       bb   ccc
       ccc

o20 : List</pre>
</td></tr>
</table>
Nets and strings can be concatenated horizontally with the operator <a href="__vb.html" title="a binary operator, often used for horizontal concatenation">|</a>.<table class="examples"><tr><td><pre>i21 : x^2 | "-------" | x

      a
      bb
o21 = ccc-------a
                bb
                ccc</pre>
</td></tr>
</table>
Each net has a width, a depth, and a height.  The width is the number of characters in each row.  The depth is the number of rows below the baseline, and the height is the number of rows above the baseline.  The depth and the height can be negative.<table class="examples"><tr><td><pre>i22 : width x, height x, depth x

o22 = (3, 1, 2)

o22 : Sequence</pre>
</td></tr>
</table>
We may extract the rows of a net as strings with <a href="_unstack.html" title="list the rows of a net">unstack</a> and put them back together again with <a href="_stack.html" title="join nets or string vertically">stack</a>.<table class="examples"><tr><td><pre>i23 : v = unstack x

o23 = {a, bb, ccc}

o23 : List</pre>
</td></tr>
<tr><td><pre>i24 : peek oo

o24 = {"a", "bb", "ccc"}</pre>
</td></tr>
<tr><td><pre>i25 : stack v

o25 = a
      bb
      ccc</pre>
</td></tr>
</table>
</div>
<div><h3>Menu</h3>
<ul><li><span><a href="__sl_sl_sl.html" title="delineate a string with slashes">///</a> -- delineate a string with slashes</span></li>
</ul>
<h4>functions for handling strings</h4>
<ul><li><span><a href="_concatenate.html" title="join strings">concatenate</a> -- join strings</span></li>
<li><span><a href="_format.html" title="format a string or a real number">format</a> -- format a string or a real number</span></li>
<li><span><a href="_lines.html" title="split a string into lines">lines</a> -- split a string into lines</span></li>
<li><span><a href="_separate.html" title="split a string into pieces">separate</a> -- split a string into pieces</span></li>
<li><span><a href="_regular_spexpressions.html" title="">regular expressions</a></span></li>
</ul>
<h4>functions for handling nets</h4>
<ul><li><span><a href="_horizontal__Join.html" title="join nets or strings horizontally">horizontalJoin</a> -- join nets or strings horizontally</span></li>
<li><span><a href="_stack.html" title="join nets or string vertically">stack</a> -- join nets or string vertically</span></li>
<li><span><a href="_unstack.html" title="list the rows of a net">unstack</a> -- list the rows of a net</span></li>
</ul>
<h4>more information</h4>
<ul><li><span><a href="___String.html" title="the class of all strings">String</a> -- the class of all strings</span></li>
<li><span><a href="___Net.html" title="the class of all nets and strings">Net</a> -- the class of all nets and strings</span></li>
</ul>
</div>
</div>
</body>
</html>