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
with the same arguments, but withread
#hx
implicitly in the stream at the start of the read.(read-honu-syntax
[source-name-v input-port
])
is the same as calling
with the same arguments, but withread-syntax
#hx
implicitly in the stream at the start of the read.
Similarly,
56 produces Honu output when the print
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 (
, where lib
"honu-module.ss" "honu-module") ....)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).
Within a sequence of H-expressions, a sub-sequence between angle brackets is represented specially (see section 19.1.5).
Whitespace for H-expressions is as in Scheme: any character for which
returns true counts as a whitespace.char-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 parenthesized 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.
In an H-expression sequence, when a less-than sign (<
) is
followed by a greater-than sign (>
), and when nothing
between the less-than and greater-than signs is an immediate symbol
containing an equal sign (=
), ampersand (&
), or
vertical bar (|), 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 less-than and
greater-than signs (exclusive). This reprsentation is applied
recursively, so that angle brackets can be nested. An angle-bracketed
sequence by itself is not a single H-expression, since the less-than
sign by itself is a single H-expression; the angle-bracket conversion
is performed only when representing sequences of H-expressions. Also,
symbols with an equal sign, ampersand, or vertical bar prevent
angle-bracket formation, because they correspond to operators that
normally have lower or equal precedence compared to less-than and
greater-than.
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 whitespace. 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
able S-expression form, the MzScheme printer produces an
S-expression prefixed with read
#sx
. For values with neither an
H-expression form nor a
able S-expression form, then
printer produces output of the form read
#<...>
, as in Scheme
mode. The print-honu
parameter (see section 7.9.1.4)
controls whether Mzscheme's printer produces Scheme or Honu output.
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(
, where eachv
, ···)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(
, wherev1
,v2
)v1
andv2
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 sequencevectorN(
, wheren
,v
, ···)n
is the length of the vector and eachv
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 singlev
. Ifprint-vector-length
is set to false, the vector is represented with the H-expression sequencevector(
, where eachv
, ···)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.