Next: Output Printing Up: Support Facilities Previous: Exiting

# Input Parsing

MzScheme's input parser follows these non-standard rules:

- Square brackets (``['' and ``]'') and curly braces (``{'' and ``}'') can be used in place of parentheses. An open square bracket must be closed by a closing square bracket and an open curly brace must be closed by a closing curly brace. Whether square brackets are treated as parentheses is controlled by the `read-square-bracket-as-paren` parameter (see section 9.4.1.3). Similarly, the parsing of curly braces is controlled with the `read-curly-brace-as-paren` parameter. By default, square brackets and curly braces are treated as parentheses.

- Vector constants can be unquoted, and a vector size can be specified with a decimal integer between the `#` and opening parenthesis. If the specified size is larger than the number of vector elements that are provided, the last specified element is used to fill the remaining vector slots. For example, `#4(1 2)` is equivalent to `#(1 2 2 2)`. If no vector elements are specified, the vector is filled with `0`. If a vector size is provided and it is smaller than the number of elements provided, the `exn:read` exception is raised.

- Boxed constants can be created using `#&`. The S-expression following `#&` is treated as a quoted constant and put into the new box. (Spaces following the `#&` are ignored.) Box reading is controlled with the `read-accept-box` Boolean parameter (see section 9.4.1.3). Box reading is enabled by default. When box reading is disabled and `#&` is provided as input, the `exn:read` exception is raised.

- The following character constants are recognized:
  - `#\nul` or `#\null` (ASCII 0)
  - `#\backspace` (ASCII 8)
  - `#\tab` (ASCII 9)
  - `#\newline` or `#\linefeed` (ASCII 10)
  - `#\vtab` (ASCII 11)
  - `#\page` (ASCII 12)
  - `#\return` (ASCII 13)
  - `#\space` (ASCII 32)
  - `#\rubout` (ASCII 127)
  Whenever `#\` is followed by at least two alphabetic characters, characters are read from the input port until the next non-alphabetic character is returned. If the resulting string of letters does not match one of the above constants (case-insensitively), the `exn:read` exception is raised.

  Character constants can also be specified through direct ASCII values in octal notation: `#\n n n` where n is in the range [`0`, `3`] and n and n are in the range [`0`, `7`]. Whenever `#\` is followed by at least two characters in the range [`0`, `7`], the next character must also be in this range and the resulting octal number must be in the range to .

- Numbers containing a decimal point or exponent (e.g., `1.3`, `2e78`) are normally read as inexact. If the `read-decimal-as-inexact` parameter is set to `#f`, then such numbers are instead read as exact. The parameter does not affect the parsing of numbers with an explicit exactness tag (`#e` or `#i`).

- MzScheme's identifier and symbol syntax is considerably more liberal than the syntax specified by R5RS. When input is scanned for tokens, the following characters delimit an identifier:

  ``

        " , ' ` ( ) [ ] { } space tab return newline page vtab

  In addition, an identifier cannot start with a hash mark (```#`'') unless the hash mark is immediately followed by a percent sign (```%`''). The only other special characters are backslash (``\'') or quoting vertical bars (```|`''); any other character is used as part of an identifier.

  Symbols containing special characters (including delimiters) are expressed using an escaping backslash (``\'') or quoting vertical bars (```|`''):

  - A backslash preceding any character includes that character in the symbol literally; double backslashes produce a single backslash in the symbol.
  - Characters between a pair of vertical bars are included in the symbol literally. Quoting bars can be used for any part of a symbol, or the whole symbol can be quoted. Backslashes and quoting bars can be mixed within a symbol, but a backslash is not a special character within a pair of quoting bars.

  An input token constructed in this way is an identifier when it is not a numerical constant (following the extended number syntax described in section 4.3). A token containing a backslash or vertical bars is never treated as a numerical constant.

  Examples:

  - `(quote a\(b)` produces the same symbol as `(string->symbol "a(b")`.
  - `(quote a b)`, `(quote |a b|)`, and `(quote a| |b)` all produce the same symbol as `(string->symbol "a b")`.
  - `(quote |a||b|)` is the same as `(quote ab)`.
  - `(quote 10)` is the number 10, but `(quote |10|)` produces the same symbol as `(string->symbol "10")`.

  Whether a vertical bar is used as a special or normal symbol character is controlled with the `read-accept-bar-quote` Boolean parameter (see section 9.4.1.3). Vertical bar quotes are enabled by default.

- S-expressions with shared structure are expressed using `#n=` and `#n#`, where n is a decimal integer. See section 14.5.

- Expressions of the form `#%x` are symbols, where x can be a symbol or a number. See section 9.3.2.

- Expressions beginning with `#`` are interpreted as compiled MzScheme code. See section 14.6.

- Multi-line comments are started with `#|` and terminated with `|#`. Comments of this form can be nested arbitrarily.

- If the first line of a `load`ed file begins with `#!`, it is ignored by the default load handler. If an ignored line ends with a backslash (``\''), then the next line is also ignored.

Next: Output Printing Up: Support Facilities Previous: Exiting