## Extensions to the standard

### Identifiers

Identifiers may contain special characters if delimited with `| ... |`.

### Brackets and braces

The brackets `[ ... ]` and the braces `{ ... }` are provided as an alternative syntax for `( ... )`. A number of reader extensions is provided. See Non-standard read syntax.

### Non-standard macros

Numerous non-standard macros are provided. See Non-standard macros and special forms for more information.

### Extended DSSSL style lambda lists

Extended DSSSL style lambda lists are supported. DSSSL parameter lists are defined by the following grammar:

    <parameter-list> ==> <required-parameter>*
                         [(#!optional <optional-parameter>*)]
                         [(#!rest <rest-parameter>)]
                         [(#!key <keyword-parameter>*)]
    <required-parameter> ==> <ident>
    <optional-parameter> ==> <ident>
                             | (<ident> <initializer>)
    <rest-parameter> ==> <ident>
    <keyword-parameter> ==> <ident>
                            | (<ident> <initializer>)
    <initializer> ==> <expr>

When a procedure is applied to a list of arguments, the parameters and arguments are processed from left to right as follows:

- Required-parameters are bound to successive arguments starting with the first argument. It shall be an error if there are fewer arguments than required-parameters.
- Next, the optional-parameters are bound with the remaining arguments. If there are fewer arguments than optional-parameters, then the remaining optional-parameters are bound to the result of the evaluation of their corresponding <initializer>, if one was specified, otherwise `#f`. The corresponding <initializer> is evaluated in an environment in which all previous parameters have been bound.
- If there is a rest-parameter, then it is bound to a list containing all the remaining arguments left over after the argument bindings with required-parameters and optional-parameters have been made.
- If `#!key` was specified in the parameter-list, there should be an even number of remaining arguments. These are interpreted as a series of pairs, where the first member of each pair is a keyword specifying the parameter name, and the second member is the corresponding value. If the same keyword occurs more than once in the list of arguments, then the corresponding value of the first keyword is the binding value. If there is no argument for a particular keyword-parameter, then the variable is bound to the result of evaluating <initializer>, if one was specified, otherwise `#f`. The corresponding <initializer> is evaluated in an environment in which all previous parameters have been bound.

Needing a special mention is the close relationship between the rest-parameter and possible keyword-parameters. Declaring a rest-parameter binds up all remaining arguments in a list, as described above. These same remaining arguments are also used for attempted matches with declared keyword-parameters, as described above, in which case a matching keyword-parameter binds to the corresponding value argument at the same time that both the keyword and value arguments are added to the rest parameter list. Note that for efficiency reasons, the keyword-parameter matching does nothing more than simply attempt to match with pairs that may exist in the remaining arguments. Extra arguments that don't match are simply unused and forgotten if no rest-parameter has been declared. Because of this, the caller of a procedure containing one or more keyword-parameters cannot rely on any kind of system error to report wrong keywords being passed in.

It shall be an error for an `<ident>` to appear more than once in a parameter-list.

If there is no rest-parameter and no keyword-parameters in the parameter-list, then it shall be an error for any extra arguments to be passed to the procedure.

Example:

    ((lambda x x) 3 4 5 6)       => (3 4 5 6)
    ((lambda (x y #!rest z) z)
     3 4 5 6)                    => (5 6)
    ((lambda (x y #!optional z #!rest r #!key i (j 1))
        (list x y z i: i j: j))
     3 4 5 i: 6 i: 7)            => (3 4 5 i: 6 j: 1)

### `set!`

`set!` for unbound toplevel variables is allowed. `set! (PROCEDURE ...) ...)` is supported, as CHICKEN implements SRFI-17.

### `cond`

The `cond` form supports SRFI-61.

### Binding values in `letrec`

It is allowed for initialization values of bindings in a `letrec` construct to refer to previous variables in the same set of bindings, so

    (letrec ((foo 123)
             (bar foo) )
      bar)

is allowed and returns `123`.

### `begin`

`(begin)` is allowed in non-toplevel contexts and evaluates to an unspecified value.

### Delayed expressions

Delayed expressions may return multiple values.

### Internal definitions

CHICKEN extends standard semantics by allowing internal definitions everywhere, and not only at the beginning of a body. A set of internal definitions is equivalent to a `letrec` form enclosing all following expressions in the body:

    (let ((foo 123))
      (bar)
      (define foo 456)
      (baz foo) )

expands into

    (let ((foo 123))
      (bar)
      (letrec ((foo 456))
        (baz foo) ) )

Local sequences of `define-syntax` forms are translated into equivalent `letrec-syntax` forms that enclose the following forms as the body of the expression.

### Curried definitions

`define` with a single argument is allowed and initializes the toplevel or local binding to an unspecified value. CHICKEN supports curried definitions, where the variable name may also be a list specifying a name and a nested lambda list. So

    (define ((make-adder x) y) (+ x y))

is equivalent to

    (define (make-adder x) (lambda (y) (+ x y)))

### Non-standard procedures

CHICKEN provides numerous non-standard procedures. See the manual sections on library units for more information.

### Special IEEE floating-point numbers

The special IEEE floating-point numbers +nan, +inf and -inf are supported, as is negative zero.

### User defined character names

User defined character names are supported. See `char-name`. Characters can be given in hexadecimal notation using the #\xXX syntax where XX specifies the character code. Character codes above 255 are supported and can be read (and are written) using the #\uXXXX and #\UXXXXXXXX notations.

Non-standard characters names supported are `#\tab`, `#\linefeed`, `#\return`, `#\alarm`, `#\vtab`, `#\nul`, `#\page`, `#\esc`, `#\delete` and `#\backspace`.

### Special characters in strings

CHICKEN supports special characters preceded with a backslash \ in quoted string constants. \n denotes the newline-character, \r carriage return, \b backspace, \t TAB, \v vertical TAB, \a alarm, \f formfeed, \xXX a character with the code `XX` in hex and \uXXXX (and \UXXXXXXXX) a unicode character with the code `XXXX`. The latter is encoded in UTF-8 format.

The third argument to `substring` is optional and defaults to the length of the string.

### Number/String conversions

The optional "base" argument to `string->number` and `number->string` may be any integral value from 2 to 36.

### `force`

`force` called with an argument that is not a promise returns that object unchanged. Captured continuations can be safely invoked inside before- and after-thunks of a `dynamic-wind` form and execute in the outer dynamic context of the `dynamic-wind` form.

Implicit non-multival continuations accept multiple values by discarding all but the first result. Zero values result in the continuation receiving an unspecified value. Note that this slight relaxation of the behaviour of returning mulitple values to non-multival continuations does not apply to explicit continuations (created with `call-with-current-continuation`).

### `eval`

The second argument to `eval` is optional and defaults to the value of `(interaction-environment)`. `scheme-report-environment` and `null-environment` accept an optional 2nd parameter: if not `#f` (which is the default), toplevel bindings to standard procedures are mutable and new toplevel bindings may be introduced.

### Pathnames expansion

The tilde character (`~`) is automatically expanded in pathnames. Additionally, if a pathname starts with `$VARIABLE...`, then the prefix is replaced by the value of the given environment variable.

### Optional arguments for port-related procedures

If the procedures `current-input-port` and `current-output-port` are called with an argument (which should be a port), then that argument is selected as the new current input- and output-port, respectively. The procedures `open-input-file`, `open-output-file`, `with-input-from-file`, `with-output-to-file`, `call-with-input-file` and `call-with-output-file` accept an optional second (or third) argument which should be one or more keywords, if supplied. These arguments specify the mode in which the file is opened. Possible values are the keywords `#:text`, `#:binary` or `#:append`.

### `exit`

The `exit` procedure exits a program right away and does not invoke pending `dynamic-wind` thunks.

Previous: Deviations from the standard

Next: Non-standard read syntax