B.4 Essential Operators and Expressions

  • Character conversions. The ord and chr functions are used for character conversions:

    A set of six code lines in M L with the functions o r d and c h r.
    Description
  • String concatenation. The append operator is used for string concatenation:

    A set of two code lines in M L with the append operator.
    Description
  • Arithmetic. The infix binary1 operators +, -, and * only accept two values of type int or two values of type real; the prefix unary minus operator ∼ accepts a value of type int or real; the infix binary division operator / only accepts two values of type real; the infix binary division operator div only accepts two values of type int; and the infix binary modulus operator mod only accepts two values of type int.

    A set of six code lines in M L with prefix unary operator, infix binary operator, and division operator.
    Description
  • Comparison. The infix binary operators = (equal to), <, >, <=, >=, and <> (not equal to) compare ints, reals, chars, or strings with one exception: reals may not be compared using = or <>. Instead, use the prefix functions Real.== and Real.!=. For now, we can think of Real as an object (in an object-oriented program), == as a message, and the expression Real.== as sending the message == to the object Real, which in turn executes the method definition of the message. Real is called a structure in ML (Section B.10). Structures are used again in Section B.12.

    A set of 10 code lines in M L with infix binary operators for comparison.
    Description
  • Boolean operators. The infix operators orelse, andalso (not to be confused with and), and not are the or, and, and not boolean operators with their usual semantics. The operators orelse and andalso use short-circuit evaluation (or lazy evaluation, as discussed in Chapter 12):

    A set of six code lines in M L with Boolean operators.
    Description
  • Conditionals. Use ifthenelse expressions:

    A set of two code lines in M L with if-then-else expressions.
    Description

    There is no if expression without an else because all expressions must return a value.

  • Comments.

    A set of five code lines in M L that consists of comments.
    Description
  • The explode and implode functions:

    A set of 10 code lines in M L with the functions explode and implode.
    Description

1. Technically, all operators in ML are unary operators, in that each accepts a single argument that is a pair. However, generally, though not always, there is no problem interpreting a unary operator that only accepts a single pair as a binary operator.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.218.221