12.15 Array Example

12.15.1 Source file (various/array.cws)

<h1> This is a minimal example about arrays </h1>

<h2> Array definition and expansion </h2>

<cows>
// The simplest array definition:
quote [ ] = { "Many years ago, I was in a Broadway show\n", // Element 0
              "and I had to wear a fox fur around my\n",    // Element 1
              "shoulders. One day my hand touched one\n" }; // Element 2

// Now, we assign a single element ... we can use a variable instead
// of a quoted string
author = "-- Bea Arthur";
quote [6] = author;    /* This is element 6 .. array is automatically
                          filled with empty elements quote[3],
                          quote[4], quote[5] */

// Now, we assign elements quote [3], quote [4], quote [5]
quote [3] = "of the fox's legs. It seemed to be in two pieces.\n";
quote [4] = "Then it dawned on me... her leg had probably been\n";
quote [5] = "snapped in two by the steel trap that had caught it. ";

print ("<p> " + quote [0] + quote [1] + quote [2] + quote [3]
              + quote [4] + quote [5] + "<br>\n"  + quote [6]);
</cows>

<h2> Array concatenation </h2>

<cows>
author = "-- Trish Donnally";
new_quote [ ]  = { "<p> The 1950's American dream\n",
                   "of owning a mink coat\n" };
new_quote [ ] += { "is as dead as the 60 mink\n",
                   "killed to make that coat. <br>\n",
                   author };

print (new_quote [0] + new_quote [1] + new_quote [2]
                     + new_quote [3] + new_quote [4]);
</cows>

<h2> Array elements </h2>

<cows>

// Array elements can be used to test conditions within if statements
dummy_array [ ] = {"foo_1", "foo_2"};
var = "foo_1";

if (var == dummy_array [0]) {
  print ("<p> I admit to having worn suede and leather pants myself");
  print ("for a while, but you just never feel clean, and it's");
  print ("degenerate, anyway, to wear animal skins....");
}

if (dummy_array [1] != "foo_2") {
  // We'll never get here
  print ("We'll never display this ...");
} else {
  print ("So I went back to bluejeans after my degenerate period. <br>");
  print ("-- Andy Warhol\n");
}

// Array elements __CAN'T__ be used to test conditions within
// ifdef statements:
//   ifdef (dummy_array [0]) {   // __WRONG__
//      print ("Something");
//   }

// Of course, you can use array elements within the body of an ifdef
// or ifndef statement
ifdef (var) {
  cows [ ] = {
    "<p> The person I love would never wear fur. Fur just makes me \n",
    "think of shallow women who have no conscience. The fur \n",
    "industry belongs to a time when people were selfish beyond \n",
    "belief. <BR> \n",
    "-- Gavin Rossdale"
  };
  print (cows [0] + cows [1]  + cows [2]  + cows [3] + cows [4]);
}

</cows>

<hr> See G-Cows manual for further details

12.15.2 Resulting HTML file

<h1> This is a minimal example about arrays </h1>

<h2> Array definition and expansion </h2>

<p> Many years ago, I was in a Broadway show
and I had to wear a fox fur around my
shoulders. One day my hand touched one
of the fox's legs. It seemed to be in two pieces.
Then it dawned on me... her leg had probably been
snapped in two by the steel trap that had caught it. <br>
-- Bea Arthur


<h2> Array concatenation </h2>

<p> The 1950's American dream
of owning a mink coat
is as dead as the 60 mink
killed to make that coat. <br>
-- Trish Donnally


<h2> Array elements </h2>

<p> I admit to having worn suede and leather pants myself
for a while, but you just never feel clean, and it's
degenerate, anyway, to wear animal skins....
So I went back to bluejeans after my degenerate period. <br>
-- Andy Warhol

<p> The person I love would never wear fur. Fur just makes me
think of shallow women who have no conscience. The fur
industry belongs to a time when people were selfish beyond
belief. <BR>
-- Gavin Rossdale


<hr> See G-Cows manual for further details

12.15.3 Resulting HTML file viewed with the Lynx text-browser

                    This is a minimal example about arrays

Array definition and expansion

   Many years ago, I was in a Broadway show and I had to wear a fox fur
   around my shoulders. One day my hand touched one of the fox's legs. It
   seemed to be in two pieces. Then it dawned on me... her leg had
   probably been snapped in two by the steel trap that had caught it.
   -- Bea Arthur

Array concatenation

   The 1950's American dream of owning a mink coat is as dead as the 60
   mink killed to make that coat.
   -- Trish Donnally

Array elements

   I admit to having worn suede and leather pants myself for a while, but
   you just never feel clean, and it's degenerate, anyway, to wear animal
   skins.... So I went back to bluejeans after my degenerate period.
   -- Andy Warhol

   The person I love would never wear fur. Fur just makes me think of
   shallow women who have no conscience. The fur industry belongs to a
   time when people were selfish beyond belief.
   -- Gavin Rossdale
     _________________________________________________________________

   See G-Cows manual for further details

This manual can be downloaded from http://www.g-cows.org/.