Prev |  | Next

## 4. Lexical syntax

Larceny's default lexical syntax extends the lexical syntax required by the R5RS, R6RS, and R7RS standards.

The R6RS forbids most lexical extensions, however, so Larceny provides several mechanisms for turning its lexical extensions on and off.

### 4.1. Flags

By default, Larceny recognizes several Larceny-specific flags of the form permitted by the R6RS. The flag you are most likely to encounter represents one of Larceny's unspecified values:

        #!unspecified

Certain other flags have special meanings to Larceny's `read` and `get-datum` procedures. They are described below.

### 4.2. Case-sensitivity

By default, Larceny is case-sensitive. This global default can be overridden by specifying `—foldcase` or `—nofoldcase` on Larceny's command line, or by changing the value of Larceny's `case-sensitive?` parameter.

The case-sensitivity of a particular textual input port is affected by reading one of the following flags from the port using the `read` or `get-datum` procedures:

        #!fold-case
        #!no-fold-case

The `#!fold-case` flag enables case-folding on data read from the port by the `read` and `get-datum` procedures, while the `#!no-fold-case` flag disables case-folding. The behavior established by one of these flags extends to the next such flag read from the port by `read` or `get-datum`.

Both `#!fold-case` and `#!no-fold-case` are treated as comments by Larceny's `read` and `get-datum` procedures. (This is a change from Larceny v0.97.)

### 4.3. Lexical extensions

When a port is first opened, the Larceny-specific lexical extensions that are accepted on the port are determined by Larceny's lexical parameters.

The following flags change the case-sensitivity and lexical extensions on the specific port from which they are read:

        #!r7rs         ; implies #!no-fold-case, enables R7RS syntax
        #!r6rs         ; implies #!no-fold-case, negates other flags
        #!r5rs         ; implies #!fold-case, enables R7RS syntax
        #!err5rs       ; enables R7RS/R6RS syntax with extensions
        #!larceny      ; implies #!no-fold-case and #!err5rs

All of those flags are treated as comments by Larceny's `read` and `get-datum` procedures. (This is a change from Larceny v0.97.)

### Note

The `#!r6rs` flag is the only flag that disables lexical extensions. To disable R6RS lexical extensions when new ports are created, use the `read-r6rs-weirdness?` parameter described below.

### 4.4. Lexical parameters

When given no argument, these parameters return the current default for some aspects of the lexical syntax that will be accepted on newly created input ports or written to newly created output ports. When given an argument, these procedures change the default as specified by the argument.

The initial values of these parameters are determined by the `-r7r6`, `-r7rs`, `-r6rs`, or `-r5rs` options on Larceny's command line. The `-r6rs` option disables non-R6RS lexical syntax; the `-r7r6`, `-r7rs`, and `-r5rs` options allow both R7RS and R6RS syntax.

Procedure case-sensitive?

`(case-sensitive? ) => boolean`

`(case-sensitive? boolean)`

If true, newly created textual input ports behave as though they began with `!fold-case`. If false, newly created textual input ports behave as though they began with `!no-fold-case`.

Procedure read-r6rs-flags?

`(read-r6rs-flags? ) => boolean`

`(read-r6rs-flags? boolean)`

If true, allows flags other than `!r6rs` to be read from newly created ports. If false, flags other than `!r6rs` raise exceptions when read.

Procedure read-r7rs-weirdness?

`(read-r7rs-weirdness? ) => boolean`

`(read-r7rs-weirdness? boolean)`

If true, newly created textual input ports behave as though they began with `#!r7rs`, and R7RS lexical syntax will be used when writing external representations to newly created textual output ports. If false, R7RS-specific extensions to R5RS/R6RS lexical syntax may raise exceptions.

Procedure read-r6rs-weirdness?

`(read-r6rs-weirdness? ) => boolean`

`(read-r6rs-weirdness? boolean)`

If true, allows all R6RS lexical syntax on newly created ports without disabling other lexical syntax on those ports (so newly created textual input ports do not behave as though they began with `#!r6rs`). If false, R6RS-specific extensions to R5RS/R7RS lexical syntax may raise exceptions.

If `read-r6rs-weirdness?` is true and `read-r7rs-weirdness?` is false, then the R6RS bytevector syntax will be used when writing to newly opened textual output ports. If neither or both are true, then R7RS bytevector syntax will be used.

Procedure read-larceny-weirdness?

`(read-larceny-weirdness? ) => boolean`

`(read-larceny-weirdness? boolean)`

Determines whether newly created textual ports allow Larceny's usual extensions to R5RS lexical syntax. In addition, this parameter determines whether newly created ports allow `#` as an insignificant digit, which is required by the R5RS but disallowed by the R6RS and not required by the R7RS.

Procedure read-traditional-weirdness?

`(read-traditional-weirdness? ) => boolean`

`(read-traditional-weirdness? boolean)`

Determines whether newly created textual ports allow certain lexical extensions that are deprecated in Larceny.

### Note

The semantics of `read-larceny-weirdness?` and `read-traditional-weirdness?` will change over time as deprecated misfeatures are added or dropped in response to popular demand or apathy. For the current semantics of these parameters, please consult the Larceny developers' web page that describes Larceny's lexical syntax.

Prev |  | Next
| Home |