Water Quick Reference Guide |
|
| Aug 23, 2006 | Language for Simplified Web Services and XML Programming |
| Concise XML Syntax source => result | |
| Full closing tag | <body> the content </body> |
| Short closing tag | <body> the content </> |
| No content | <body/> |
| Attributes hold any object or expression | <thing age=<plus 2 2/> male=true/>.age => 4 |
| Pass arg via keyword | <class boat weight=req/>
=> 123 |
| Pass arg via position | <class boat weight=req/> <boat 123/>.weight => 123 |
| Comment | <!-- code in here is ignored. --> |
| Subject of call | 2.<plus 3/> <!-- 2 is the _subject of the call to plus --> => 5 |
| Object System: everything is an object | |
| Objects | Objects have fields, each of which has a key and a value.
|
| Root: Water Object | <!-- all objects have both a _parent field and
=> wob |
| Generic object | thing <!-- a thing can have any fields --> => thing |
| Named & vector fields | wob.<set foo=<thing x=100 y=555 20 30 40/> /> |
| value of field 'x' | wob.foo.x => 100 |
| value of field 2 | wob.foo.2 => 40 |
| Instance of class? | 10.<is_a number/> => true |
| Basic Operations: get, set, remove | |
| Dot notation | <thing bar=5/>.bar => 5 |
| Get value | <thing 6="hi"/>.<get 2.<times 3/>/> => "hi" |
<thing 6="hi"/>.<get 5 lookup=false
=> 0 | |
| Assign variable(s) | <set key1="value1" key2="value2"/> key1 => "value1" |
| Assign field | thing.<set material="wood"/> thing.material => "wood" |
| Field exists? | thing.<has "material"/> => true |
thing.<has "junk"/> => false | |
| Remove field | thing.<remove "material"/> => "wood" |
thing.<has "material"/> => false | |
| boolean: true and false | |
| and | true.<and false/> => false |
| or | true.<or false true/> => true |
| not | true.<not/> <not true/> 123.<not/> <!--any arg but false returns false-->=> false |
| Same object? | 5.<is 5/> => true |
<thing/>.<is <thing/>/> => false | |
| Same valued fields | <thing foo=5/>.<equal <thing foo=5/> /> => true |
| false values using boolean.from. Other args result in true. | boolean.<from "false"/> boolean.<from "no"/>
=> false |
| number | |
| integer | 42.<is_a integer/> => true |
-1.<is_a integer/> => true | |
| double: floating point | 4.53.<is_a number.double/> => true |
-0.11.<is_a number.double/> => true | |
| Arithmetic | plus minus times divide remainder |
| plus | 2.<plus 3.3/> => 5.3 |
| _subject defaults to 0 | <plus 2 3 4/> <!--plus and times take any number of args--> => 9 |
| ( 5 * 6 ) / 3 - 1 | 5.<times 6/>.<divide 3/>.<minus 1/> => 9.0 |
| Rounding | integer.<from 5.3 direction='down'/> => 5 |
| Modulus | 10.<remainder 3/> => 1 |
| Comparators | 7.<more 5/> 5.<less 7/> 5.<more_or_equal 5/> 5.<less_or_equal 5/>
=> true |
| string | |
| Create string | "a_string" 'a_string' <string>a_string</string> <![CDATA[a_string]]>=> "a_string" |
| Concatenate | "you".<join 2 "me"/> => "you2me" |
| Length | "Water".<length/> => 5 |
| Get a character | "Water".0 => <char "W"/> |
| Substring | "Water".<subvector start=0 end=3/> => "Wat" |
| Index of value | "Water".<key_of <char "t"/> /> => 2 |
| Replace string | "Water".<replace "Wa" "bet"/> => "better" |
| Strings are interned | "a".<is "a"/> => true |
| Loose equality | " CM".<equal "cm" same_case=false same_whitespace=false/> => true |
| Data collection or array: vector | |
| Create vectors | <vector 5 "a" "bcd"/> <vector> 5 "a" "bcd" </vector> |
| synonym for vector | <v 5 "a" "bcd"/> |
| Get field value | <vector 5 "a"/>.1 => "a" |
| Indirect | <set x=1/> <vector 5 "a"/>.<get x/> => "a" |
| Vector length | <vector 5 "a"/>.<length/> => 2 |
| Sorting | <vector "m" "a" "x" />.<sort/> => <vector "a" "m" "x"/> |
| Reverse | <vector "x" "y" "z" />.<reverse/> => <vector "z" "y" "x"/> |
| 2D vector | <set Q=<vector 4 5 <vector 6 7 8/> /> /> Q.2.0 => 6 |
| Get from end | <vector 5 10 15 20 25 30/>.<last 1/> => 25 |
| Push value on end | <vector "a"/>.<insert "z"/> => <vector "a" "z"/> |
| Insert at index | <vector "a"/>.<insert "z" at_key=0/> => <vector "z" "a"/> |
| Append vector values | <v 6 7/>.<insert _other_unkeyed=<v 8 9/> /> => <vector 6 7 8 9/> |
| Remove | <vector "a" "b" "c"/>.<remove 1/> => "b" |
| Subvector | <vector 6 7 8 9/>.<subvector start=1 end=3/> => <vector 7 8 /> |
| datetime, etc | |
| Create datetime | <datetime year=2000 month=12 day=25 hour=5
=> 50 |
| Now | datetime.<current/>.<is_a datetime/> => true |
| Create duration | <duration months=1 days=9/> => <duration months=1 days=9/> |
| date plus duration | <date 2005 4 1/>.<plus <duration days=32/>/> => <date 2005 5 3/> |
| Grouping expressions: do | |
| Execute all ... | <do 0.<sin/> 0.<cos/> /> => 1.0 |
| & return last result | <do> <set x="all done"/> x </do> => "all done" |
| Code within HTML | <h1> <do 2.<power 3/>/> </h1> => <h1 0=8/> |
| Conditional flow control: if | |
| Condition-action pairs, use do for big action, 'else' means true, return executed action | <if> number.double.pi.<more 4/> "high"
=> "just right" |
| Returns null if no match | <if> 3.<is 2/> "never happens" </if> => null |
| Iteration: for_each | |
| Iterate over vector fields, return last | <vector "a" "b"/>.<for_each> <vector key value/></> => <v 1 "b"/> |
| Iterate over string fields | <thing a=7 b=8/>.<for_each include=string_key combiner=plus>
=> 15 |
| Iterate over 0 thru 3 | 4.<for_each combiner=plus> value </> <!-- 0.<plus 1 2 3/>--> => 6 |
| Return vector of values | <vector 7 8 9/>.<for_each combiner=insert> value.<times 10/> </>=> <v 70 80 90/> |
| Return filtered vector | <v "k1" "j1" "j2" "k2"/>.<for_each combiner=insert>
=> <v "k1" "k2"/> |
| Exclude fields | <vector 97 98 99/>.<for_each exclude=<vector 0 2/> combiner=insert>
=> <vector 98/> |
| Methods, Functions, Macros: method | |
| method & call | <method five> 5 </> <five/> => 5 |
| One required arg | <method twice x=req> x.<plus x/> </> <twice 3/> => 6 |
| Method on person | person.<method hire |
| Required arg | manager=req |
| Typed arg | position=req=string |
| Default value | date=<datetime/>.<current/> |
| Optional, no default | salary=opt=number |
| End parameters | > |
| Implementation | <join "Boss: " manager " hires: " position /> |
| End method | </method> |
| Call the method | person.<hire "J.B." "sales"/> => "Boss: J.B. hires: sales" |
| Execution kinds permit delayed execution | <method m x=req=string=ekind.string>
=> <v 9 "junk"/> |
| Classes: class | |
| Define class | <class person first=req last=opt zip=opt/> => person |
| ... with param types | <class person first=req=string
=> person |
| Construct instance | <person zip=10483 first="Mike" last="Jones"/> |
| ...without keywords | <person "Mike" "Jones" 10483/> |
| Define subtype | <class person.employee/> => person.employee |
| Define a class with a method and a subtype | <class person last=req first=opt><!--put req params 1st-->
=> person |
| Get subclass | person.employee <!-- classes hold subclasses in fields --> |
| Special methods are : 'make' as constructor, 'to_htm' for display | <class person name=req>
=> person |
| Multiple inheritance | <<union <class car wheels=4/> <class boat hull="mono"/>/>
|
| Presentation: XHTML and Hypertext | |
| All XHTML is included in Water | html, body, table, form, script, style, div, span, b, i, etc.
|
| Mix html and Water | <font size=3.<plus 4/>> <i>Now <do datetime.<current/>/></i></font> |
| CSS | <h1 style=<style color="red"/> >Title</h1> |
| Web server using HTML form | |
| XHTML input | form, input, select, textarea |
| Web app on integer. Action is method to call with arg from input when submit button clicked | <method integer.square in=2>
|
| Launch server | <server integer port=9090/> |
| Get page from Water | <resource "http://localhost:9090/square?"/>.content |
| Browse the app | <open_browser_window "http://localhost:9090/square?"/> |
| Importing/parsing | |
| string to primitive | primitive.<from "123"/> => 123 |
| Returns vector | "C,Fry,2".<make_object field_separator=","/> => <v "C" "Fry" "2"/> |
| Returns person | <class person first_name=req last_name=req zip="00000"/>
=> <person first_name="M" last_name="Joy" zip="28840"/> |
| Vector of objects | "C,Fry,28838===M,Plusch,02481".
=> <v <person "C" "Fry" "28838"/> <person "M" "Plusch" "02481"/>/> |
| Convert to XHTML | "<body bgcolor=red>hello</body>".<html_to_xhtml/>=> '<body bgcolor="red">
|
| Output | |
| Object to String | <b>Water</>.<to_htm/> => "<b>Water</b>" |
| Format XML 1.0 | <thing weight=123/>.<to_xml/>=> "<thing>
|
| Make path if possible | number.integer.<to_cxs/> => "number.integer" |
| Text, no markup | <thing size="xl"/>.<to_txt/> => "thing size=xl" |
| Tools | |
| Print to Java console | <echo "X: " <plus 2 3/>/> <!-- all arg values printed--> => 5 |
| Inspect object or path | "foo".ii thing.<iip p/> 3.<plus 4/>.ii.<plus 1/> => 8 |
| Make test case | <test result=5> 5.<minimum 8/> </test> |
| Make documentation | <doc on=minimum> return the smallest number</doc> |
| www.clearmethods.com |