#
Chapter 19
Honu

Honu is a family of languages built on top of MzScheme. Honu syntax resembles Java, instead of Scheme. Like Scheme, however, Honu has no fixed syntax. Honu supports extensibility through macros and a base syntax of H-expressions, which are analogous to S-expressions.

The MzScheme reader incorporates an H-expression reader, and MzScheme's printer also supports printing values in Honu syntax. The reader can be put into H-expression mode either by including `#hx` or `#honu` in the input stream, or by calling `read-honu` or `read-honu-syntax` instead of `read` or `read-syntax`:

- `(read-honu``` [`input-port`]`)` is the same as calling ``read`` with the same arguments, but with `#hx` implicitly in the stream at the start of the read.

- `(read-honu-syntax``` [`source-name-v input-port`]`)` is the same as calling ``read-syntax`` with the same arguments, but with `#hx` implicitly in the stream at the start of the read.

Similarly, ``print``56 produces Honu output when the `print-honu` parameter is set to `#t`.

When the reader encounters `#hx`, it reads a single H-expression, and it produces an S-expression that encodes the H-expression. Except for atomic H-expressions, evaluating this S-expression as Scheme is unlikely to succeed. In other words, H-expressions are not intended as a replacement for S-expressions to represent Scheme code.

When the reader encounters `#honu`, it reads H-expressions repeatedly until an end-of-file is encountered. The collected H-expression results are wrapped with `(module id (`lib` "honu-module.ss" "honu-module") ....)`, where `id` is generated as described below. The `honu-module.ss` module defines `#%module-begin` to parse S-expressions that encode H-expressions; expanding the module produces a Scheme program that corresponds to the H-expression-based Honu program in the original input stream. Thus, a file that starts with `#honu` can define a module to be `require`d in a Scheme module or another Honu module.

In the `module` wrapper for `#honu`, the `id` is derived from the read port's name: if the port's name is a symbol, then it is used as `id`; if the port's name is a path, then the last element of the path is converted to a symbol and used as `id`; otherwise, `'unknown` is used.

The `honu-module.ss` module and Honu language dialects are documented elsewhere. In principle, MzScheme's parsing and printing of H-expressions is independent of the Honu language, so it is currently documented here.

## 19.1 Honu Input Parsing

Ignoring whitespace, an H-expression is either

- a number (see section 19.1.1);

- an identifier (see section 19.1.2);

- a string (see section 19.1.3);

- a character (see section 19.1.4);

- a sequence of H-expressions between parentheses (see section 19.1.5);

- a sequence of H-expressions between square brackets (see section 19.1.5);

- a sequence of H-expressions between curly braces (see section 19.1.5);

- a comment followed by an H-expression (see section 19.1.6);

- `#;` followed by two H-expressions (see section 19.1.6);

- `#hx` followed by an H-expression;

- `#sx` followed by an S-expression (see section 11.2.4).

Whitespace for H-expressions is as in Scheme: any character for which ``char-whitespace?`` returns true counts as a whitespace.

### 19.1.1 Numbers

The syntax for Honu numbers is the same as for Java. The S-expression encoding of a particular H-expression number is the obvious Scheme number.

### 19.1.2 Identifiers

The syntax for Honu identifiers is the union of Java identifiers plus semicolon (`;`), comma (`,`), and a set of operator identifiers. An operator identifier is any combination of the following characters:

``

+ - _ = ? : < > . ! % `^` & * / ~ |

The S-expression encoding of an H-expression identifier is the obvious Scheme symbol.

Input is parsed to form maximally long identifiers. For example, the input `int->int;` is parsed as four H-expressions: `int`, `->`, `int`, and `;`.

### 19.1.3 Strings

The syntax for an H-expression string is exactly the same as for an S-expression string, and an H-expression string is represented by the obvious Scheme string.

### 19.1.4 Characters

The syntax for an H-expression character is the same as for an H-expression string that has a single content character, except that a single quote (`'`) surrounds the character instead of double quotes (`"`). The S-expression representation of an H-expression character is the obvious Scheme character.

### 19.1.5 Parentheses, Brackets, and Braces

A parenthesized (), bracketed [], or braced {} H-expression sequence is represented by a Scheme list. The first element of the list is `'#%parens` for a paremnthesized sequence, `'#%brackets` for a brackets sequence, or `'#%braces` for a braced sequence. The remaining elements are the Scheme representation for the parenthesized, bracketed, or braced H-expressions in order.

### 19.1.6 Comments

An H-expression comment starts with either `//` or `/*`. In the former case, the comment runs until a linefeed or return. In the second case, the comment runs until `*/`, but `/* .... */` comments can be nested. Comments are treated like whitespace.

A `#;` starts an H-expression comment, as in Scheme. It is followed by an H-expression to be treated as white. Note that `#;` is equivalent to `#sx#;#hx`.

## 19.2 Honu Output Printing

Some Scheme values have a standard H-expression representation. For values with no H-expression representation but with a ``read``able S-expression form, the MzScheme printer produces an S-expression prefixed with `#sx`. For values with neither an H-expression form or a ``read``able S-expression form, then printer produces output of the form `#<...>`, as in Scheme mode.

The values with H-expression forms are as follows:

- Every real number has an H-expression form, although the representation for an exact, non-integer rational number is actually three H-expressions, where the middle H-expression is `/`.

- Every character string is represented the same in H-expression form as its S-expression form.

- Every character is represented like a single-character string, but (1) using a single quote as the delimiter instead of double quotes, and (2) protecting a single-quote character content a backslash instead of protecting double-quote character content.

- A list is represented with the H-expression sequence `list(`v`, `···`)`, where each `v` is the representation of each element of the list.

- A pair that is not a list is represented with the H-expression sequence `cons(`v1`, `v2`)`, where `v1` and `v2` are the representations of the pair elements.

- A vector's representation depends on the value of the `print-vector-length` parameter (see section 7.9.1.4). If it is true, the vector is represented with the H-expression sequence `vectorN(`n`, `v`, `···`)`, where `n` is the length of the vector and each `v` is the representation of each element of the vector, and multiple instances of the same value at the end of the vector are represented by a single `v`. If `print-vector-length` is set to false, the vector is represented with the H-expression sequence `vector(`v`, `···`)`, where each `v` is the representation of each element of the vector.

- The empty list is represented as the H-expression `null`.

- True is represented as the H-expression `true`.

- False is represented as the H-expression `false`.

56 More precisely, the default print handler.