[next][previous][up][top][index]
search for:

nets -- an overview

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.

Nets are used extensively for such things as formatting polynomials for display on ascii terminals. Use net to obtain such nets directly.

i1 : R = ZZ[x,y];
i2 : (x+y)^2

      2           2
o2 = x  + 2x*y + y

o2 : R
i3 : n = net oo

      2           2
o3 = x  + 2x*y + y

The net n above looks exactly the same as the original polynomial - that's because a polynomial is printed by printing its net. But the net n is no longer usable as a polynomial; it's just an array of characters. We may use peek to clarify the extent of a net.

i4 : peek n

     +--------------+
     | 2           2|
o4 = |x  + 2x*y + y |
     +--------------+

One way to create nets directly is with the operator ||, which concatenates strings or nets vertically.

i5 : x = "a" || "bb" || "ccc"

o5 = a
     bb
     ccc

We may use the operator ^ 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.

i6 : x^2

     a
     bb
o6 = ccc

Nets may appear in lists, and elsewhere.

i7 : {x,x^1,x^2}

                a
           a    bb
o7 = {a  , bb , ccc}
      bb   ccc
      ccc

o7 : List

Nets and strings can be concatenated horizontally with the operator |.

i8 : x^2 | "-------" | x

     a
     bb
o8 = ccc-------a
               bb
               ccc

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.

i9 : width x, height x, depth x

o9 = (3, 1, 2)

o9 : Sequence

We may extract the rows of a net as strings with netRows.

i10 : netRows x

o10 = {a, bb, ccc}

o10 : List
i11 : peek oo

o11 = {"a","bb","ccc"}

The class of all nets is Net.


[next][previous][up][top][index]
search for: