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

Chapter 11. WMLScript Operators and Expressions

Now that you know about WMLScript’s datatypes, it’s time to see how they can be linked with operators to form expressions.

If you know such languages as C or Java, the operators in this section will be familiar to you. Some of them have subtle differences, however, which are usually linked to WMLScript’s dynamic typing. These differences will be pointed out as we encounter them.

Appendix C lists all the operators and summarizes their behaviors. If you know C or Java syntax, you may want to skip this chapter and check back only for the operators you’re not familiar with. It’s probably worth reading the next section, however, since this explains how the datatype conversion rules from Chapter 10, apply to operators.

Operand Conversions

Some operators can take values of more than one type. For example, the * operator for multiplication can operate on either integers or floating-point numbers. WMLScript also defines which conversions are done in these cases:

  • Operators that always take the same type of operands simply convert the arguments to those types. If the conversion fails, the result of the operation is invalid.

  • Operators that take operands of any type simply use the values as they are. No conversion is performed because none is needed.

Tip

As you see from these rules, there can be unexpected gotchas: sometimes things don’t do what you expect. If you’re not sure of the type of a value at a particular time, it’s worth using standard library ...

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