next up previous
Next: Elements that create instances
Up: The WOM language
Previous: Syntax

An example of WOM --- calculating factorials

 

To make this more concrete, I shall give an example. The code below is a form with one field and a Submit button. Every time the user enters a number and presses Submit, a new copy of the form will be sent back, with a line displaying the number's factorial. At the time of writing, this example can be tried out at http://users.ox.ac.uk/~popx/webomatic_intro.html .

<!-- Fact.wom -->

<HTML>
<HEAD><TITLE>Factorials</TITLE></HEAD>
<BODY>
<H1>Factorials</H1>

Type a number into the field below, and we
will calculate its factorial for you.

<WOMForm>
  <IntegerField input display=""><BR>
  <Text output value=""><BR>
  <INPUT TYPE=SUBMIT>

  <OnSubmit rexx>
  {
  n = $input~getValue
  if n<1 then
    $output~setValue( "Input must be positive" )
  else
    do
    f = localnamebase~factorial(n)
    $output~setValue( n||'! =' f )
    end
  }
  </OnSubmit>
</WOMForm>

</BODY>
</HTML>

<Methods>
{
::method factorial
  use arg n
  if n=1 then
    return 1
  else
    return n*self~factorial(n-1)
}
</Methods>

It should be fairly obvious what the code is doing, but for a complete understanding, we must go into the semantics of WOM. Since the audience for this paper has a good knowledge of Rexx, I shall describe the semantics informally in an implementation-oriented way.



Jocelyn Ireson-Paine
Fri May 30 14:03:06 BST 1997