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 .

<!-- Fact.wom -->


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

  <IntegerField input display=""><BR>
  <Text output value=""><BR>

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


::method factorial
  use arg n
  if n=1 then
    return 1
    return n*self~factorial(n-1)

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