9.7 Variables Example

9.7.1 Source file (various/variables.cws)

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

<h2> Simple assignments </h2>

<cows>

// We store a short quote and author's name in three variables
quote1 = "<p> Once I was fishing and caught the hook in the fish's";
quote2 = "eye. That was the last time I ate a killed creature. <br>";
author = "-- Janet Barkas, editor of Grove Press";

// Now, we display them (print automatically adds \n characters)
print (quote1);
print (quote2);
print (author);

// You can also undefine a variable: the following lines won't print
// anything and a warning will be raised by Cows
undef (quote1);
print (quote1);

</cows>

<h2> Concatenation </h2>

<cows>

// This quotation is split
quote1 = "<p>  ... the art of angling, the cruelest, the coldest,\n";
quote2 = "and the stupidest of pretended sports. <br>";

// You can concatenate strings and print the result in only one step ..
print (quote1 + quote2 + "\n-- Lord (George) Byron\n");

// ... or create another variable with the full quote
quote1 = "<p> But what pleasure can it possibly be to \n";
quote2 = "a man of culture... when a splendid beast \n";
quote3 = "is transfixed with a hunting spear? <br>";
quote = quote1 + quote2 + quote3 + "\n-- Marcus Tilluis Cicero";
print (quote);

</cows>

<h2> A bit more complicated ... </h2>

<cows>

/* The following line defines three variables:
   - quote's value will be:
     "<p> Humans are the only hunters who kill when not hungry. <br>"
   - author's value will be "Steven Spielberg"
   - quote_and_author's value will be the concatenation of the two
     above and the constant strings "\n-- "  */

quote_and_author = (quote = "<p> Humans are the only hunters who "
                    + "kill when not hungry. <br>")
                    + "\n-- " + (author = "Steven Spielberg");

print ("<p> A quote from " + author + ":\n");
print (quote_and_author);

</cows>

<h2> Long strings </h2>

<cows>
// Of course you can also define long strings
long_quote = "<p> The person who kills for fun is announcing that,
could he get away with it, he'd kill you for fun. Your...life may be
of no consequence to anyone else but is invaluable to you because it's
the only one you've got. Exactly the same is true of each individual
deer, hare, rabbit, fox, fish, pheasant and butterfly. Humans should
enjoy their own lives, not taking others'. <br>
-- Brigid Brophy";
print (long_quote);
</cows>

<hr> See G-Cows manual for further details

9.7.2 Resulting HTML file

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

<h2> Simple assignments </h2>

<p> Once I was fishing and caught the hook in the fish's
eye. That was the last time I ate a killed creature. <br>
-- Janet Barkas, editor of Grove Press



<h2> Concatenation </h2>

<p>  ... the art of angling, the cruelest, the coldest,
and the stupidest of pretended sports. <br>
-- Lord (George) Byron

<p> But what pleasure can it possibly be to
a man of culture... when a splendid beast
is transfixed with a hunting spear? <br>
-- Marcus Tilluis Cicero


<h2> A bit more complicated ... </h2>

<p> A quote from Steven Spielberg:

<p> Humans are the only hunters who kill when not hungry. <br>
-- Steven Spielberg


<h2> Long strings </h2>

<p> The person who kills for fun is announcing that,
could he get away with it, he'd kill you for fun. Your...life may be
of no consequence to anyone else but is invaluable to you because it's
the only one you've got. Exactly the same is true of each individual
deer, hare, rabbit, fox, fish, pheasant and butterfly. Humans should
enjoy their own lives, not taking others'. <br>
-- Brigid Brophy


<hr> See G-Cows manual for further details

9.7.3 Resulting HTML file viewed with the Lynx text-browser

                   This is a minimal example about variables

Simple assignments

   Once I was fishing and caught the hook in the fish's eye. That was the
   last time I ate a killed creature.
   -- Janet Barkas, editor of Grove Press

Concatenation

   ... the art of angling, the cruelest, the coldest, and the stupidest
   of pretended sports.
   -- Lord (George) Byron

   But what pleasure can it possibly be to a man of culture... when a
   splendid beast is transfixed with a hunting spear?
   -- Marcus Tilluis Cicero

A bit more complicated ...

   A quote from Steven Spielberg:

   Humans are the only hunters who kill when not hungry.
   -- Steven Spielberg

Long strings

   The person who kills for fun is announcing that, could he get away
   with it, he'd kill you for fun. Your...life may be of no consequence
   to anyone else but is invaluable to you because it's the only one
   you've got. Exactly the same is true of each individual deer, hare,
   rabbit, fox, fish, pheasant and butterfly. Humans should enjoy their
   own lives, not taking others'.
   -- Brigid Brophy
     _________________________________________________________________

   See G-Cows manual for further details

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