Introduction to Water Programming

This Site is intended to provide helps to Water language programmers around the world through technical examples, informational articles, and personal assistance.

The following examples are meant to be a quick Getting Started sort of tutorial using the Steam Free Version or the IDE. (If you are using the Free Version, be sure to set the output to "Rendered HTML".)

Example 5. Assigning Other Variable Types - Arrays/Vectors/Lists

Another fundamental feature of programming languages is to provide a mechanism for storing values in memory other than numbers. Here are some examples in Basic, Lisp and Water.

Basic:
Dim x(5)
FOR y = 1 to 5
x(y - 1) = 10 * y
NEXT y
Lisp:
(setq x '(10 20 30 40 50))
Water:
<set x=<vector 10 20 30 40 50 /> />

If I want to use the nth element of each list, I would access it like this:

Basic:
PRINT x(3)
Lisp:
(nth 3 x)
Water:
x.3

Notice that Water and Lisp return the variable's value like Example 1. Whereas, Basic needs a PRINT statement to display the value.

If I want to list the contents of each list, I could use this:

Basic:
FOR y = 1 to 5
PRINT x(y-1);
NEXT y
Lisp:
(do*
((counter 0 (1+ counter)))
((eq counter 5) t)
(format t "~d\n" (nth counter x))
)
Water:
x.<for_each returns='all'>
<concat value <BR /> />
</>

Notice the use of the <concat /> method to stick a line-break after each element printed.

Go back to go to the next example.

©Copyright 2004, Mr. Merrick J. Stemen. All rights reserved.