1 H-expressions
On this page:
1.1 Numbers
1.2 Identifiers
1.3 Strings
1.4 Characters
1.5 Parentheses, Brackets, and Braces
1.6 Comments
1.7 Honu Output Printing
Version: 4.0.2

 

1 H-expressions

The Scheme reader incorporates an H-expression reader, and Scheme’s printer also supports printing values in Honu syntax. The reader can be put into H-expression mode either by including #hx in the input stream, or by calling read-honu or read-honu-syntax instead of read or read-syntax. Similarly, print (or, more precisely, the default print handler) 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.

Honu syntax is normally used via #lang honu, which reads H-expressions repeatedly until an end-of-file is encountered, and processes the result as a module in the Honu language.

Ignoring whitespace, an H-expression is either

Within a sequence of H-expressions, a sub-sequence between angle brackets is represented specially (see Parentheses, Brackets, and Braces).

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

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.

1.2 Identifiers

The syntax for Honu identifiers is the union of Java identifiers plus ;, ,, 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 represented by symbols: 'int, '->, 'int, and '|;|.

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.

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 ' surrounds the character instead of ". The S-expression representation of an H-expression character is the obvious Scheme character.

1.5 Parentheses, Brackets, and Braces

A H-expression between ( and ), [ and ], or { and } is represented by a Scheme list. The first element of the list is '#%parens for a (...) sequence, '#%brackets for a [...] sequence, or '#%braces for a {...} sequence. The remaining elements are the Scheme representations for the grouped H-expressions in order.

In an H-expression sequence, when a < is followed by a >, and when nothing between the < and > is an immediate symbol containing a =, &, or |, then the sub-sequence is represented by a Scheme list that starts with '#%angles and continues with the elements of the sub-sequence between the < and > (exclusive). This representation is applied recursively, so that angle brackets can be nested.

An angle-bracketed sequence by itself is not a single H-expression, since the < by itself is a single H-expression; the angle-bracket conversion is performed only when representing sequences of H-expressions.

Symbols with a =, &, or | prevent angle-bracket formation because they correspond to operators that normally have lower or equal precedence compared to less-than and greater-than operators.

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 S-expressions. It is followed by an H-expression to be treated as whitespace. Note that #; is equivalent to #sx#;#hx.

1.7 Honu Output Printing

Some Scheme values have a standard H-expression representation. For values with no H-expression representation but with a readable S-expression form, the Scheme printer produces an S-expression prefixed with #sx. For values with neither an H-expression form nor a readable S-expression form, then printer produces output of the form #<...>, as in Scheme mode. The print-honu parameter controls whether Scheme’s printer produces Scheme or Honu output.

The values with H-expression forms are as follows: