Water 5-Getting Started and Examples-Getting Started
A first example

Welcome

Steam XML IDE is an interactive development environment for XML Web Services and Water. This pane is the Editor where you type in XML, HTML, and Water code.

Hello World

To execute a simple "Hello World!" program, select the line of Water code below, including the double quotes, and then press Execute. The Execute button is in the toolbar at the bottom of the window.
"Hello World!"
The output result is shown to the right. The upper-output pane shows the result in ConciseXML syntax. The lower-output pane renders the result in an HTML viewer. Method calls are used to perform tasks. Below is an expression that represents a method call.
"Hello".<join " World!"/>"Hello World!"
This produces the same output as the above example by concatenating the string "Hello", i.e. the subject, with " World!", an argument, using the "join" method. Below is a simple math expression:
2.<plus 3/>5
Select the line above and then press 'Execute'. The result of 5 will appear in the output panes. Here 2 is the subject and 3 is the argument of calling the method "plus". Note that most popular languages would use something like 2 + 3 to represent math computations. In Water computations are performed using method calls. Water has a uniform syntax for all method calls. This simplified syntax offers benefits in more complex computations such as the lack of a need for precidence rules or grouping expressions with parens. Steam XML also lets you directly execute HTML. In fact, Water is a superset of HTML so your knowledge of HTML is immediately useful. You can even mix HTML and general purpose code.
<font size=2.<plus 4/> > Hello World </>
Select the code above and press Execute. The lower-output pane shows "Hello World" in a larger font. Double-clicking at the start or end of an expression will select the entire expression. This is handy for verifying that your syntax is correct by showing you exactly where an expression starts and ends. If there is not a valid expression, say unmatched angle brackets, you'll see an error message in the lower right pane. We could have achieved the same effect by replacing 2. 4 with "6" as is done in pure HTML. But with Water and ConciseXML, an attribute value can be any Water code and it will be executed. Note that in the upper right pane we see that size has been set to 6 and the font in the lower right is larger than usual.

Web Application

Water is a 100% object oriented general purpose programming language. There's lots more to learn about how it works, but in this brief introduction we want to spare you those details and leap ahead to show you a small but functional web application. The following Water code is a two-page Web application called 'my_first_app'. It defines a class with a couple of methods that create some HTML, and launches a web server to run the app. When running in a web browser, it asks the user to type some text in a text box and then displays that text on another browser page. You're not expected to understand all of the below code but we hope you'll find it readable. This program is implemented by creating a web server that serves an initial page with a form on it. Once the user enters a value and clicks Submit, the server extracts the value the user entered, and returns a second web page that displays the entered text. To load and start the application, select the code below and press Execute. Define the application:
<class my_first_app>      
 <method htm_class>
  <FORM action=.simple_action>
   Type in some text:
   <INPUT name="a_value"/>
   <INPUT type="submit"/>
  </FORM>
 </method>

 <method simple_action a_value=req>
  <H1> You entered: <do a_value/> </H1>
 </method>
</class>
Start an application server:
<server my_first_app port=9090/>
Use the application:
<open_browser_window "http://localhost:9090"/>
If executing the above code does NOT open a browser window, just start your Web browser and type in the following address: http://localhost:9090/

Next Steps

You CAN modify any editor buffer including this one but its best to create a file for your own code. use the "File" menu and choose "New Scratch File" to make a file for playing with in the Water User Folder. The "Insert" menu has many examples of Water code that are inserted into the editor buffer when you choose them. It great for seeing a list of common computations and their syntax. The Insert menu is also available by right-clicking in the Editor pane (this pane). If you're on a Macintosh, use control_click to simulate a right-click. Select one of the menu items to insert a Water expression into the Editor at the cursor location. This hierarchical menu has many items including these "initial instructions" on the "Misc" submenu should you ever need them again. Full documentation for the Water language can be found at: http://www.watercode.com/ Double-click on a method or class name to show information about it in the lower-output pane. You'll also find the items on the "Help" menu to be useful. For additional assistance, the Water community and Water book can be found at: http://www.waterlanguage.org or send an e-mail to: info@clearmethods.com