O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What Is WMLScript?

WMLScript is loosely based on JavaScript but is much simpler in order to reduce the requirements on the device running the browser. (JavaScript can require quite large amounts of memory, and the interpreter to run it is complex.)

If you’ve ever done any programming in Java, JavaScript, C, C++, ECMAScript, or any of the large variety of other languages that borrow bits of syntax from each other, then a lot of the syntax of WMLScript should look familiar.

For example, a WMLScript function to calculate the factorial of a positive integer can be written as:

/* Calculate factorial of n. */
function factorial (n)
{
    var result = 1;

    for (var i=2; i<n; i++) {
        result *= n;
    }

    return result;
}

The curly braces, the for statement in the middle, and the return statement at the end are all similar to languages such as C, Java, JavaScript, or C++. The function line and the var line may be less familiar; they will be covered in later chapters.

WMLScript comments can have two forms: like in C, starting with /* and continuing until */ even across lines, and like in C++, starting with // and continuing until the end of the line:

/* C comments look like this. */

// C++ comments look like this.

/*
    C comments may span
    as many lines as you like.
*/

// C++ comments must have a
// new // at the start of every
// line of the comment.

Everything in WMLScript is case-sensitive, including function names, variable names, literal values, keywords, and everything else.

Spacing, however, is flexible. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required