source: project/chicken/branches/release/manual/Extensions to the standard @ 6573

Last change on this file since 6573 was 5945, checked in by felix winkelmann, 13 years ago

renamed some tools in misc/; apply hack fix on x86-64 (again); re-added manual

File size: 8.0 KB
1[[tags: manual]]
3== Extensions to the standard
5[2.1] Identifiers may contain special characters if delimited with
6{{| ... |}}.
8[2.3] The brackets {{[ ... ]}} are provided as an alternative syntax
9for {{( ... )}}.  A number of reader extensions is provided. See
10[[Non-standard read syntax]].
12[4] Numerous non-standard macros are provided. See
13[[Non-standard macros and special forms]] for more information.
15[4.1.4] Extended DSSSL style lambda lists are supported. DSSSL parameter lists are defined by the following grammar:
17 <parameter-list> ==> <required-parameter>*
18                      [(#!optional <optional-parameter>*)]
19                      [(#!rest <rest-parameter>)]
20                      [(#!key <keyword-parameter>*)]
21 <required-parameter> ==> <ident>
22 <optional-parameter> ==> <ident>
23                          | (<ident> <initializer>)
24 <rest-parameter> ==> <ident>
25 <keyword-parameter> ==> <ident>
26                         | (<ident> <initializer>)
27 <initializer> ==> <expr>
29When a procedure is applied to a list of arguments, the parameters and arguments are processed from left to right as follows:
31* 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.
32* 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.
33* 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. These remaining arguments are also eligible to be bound to keyword-parameters, in which case the argument will be a member of both the rest-parameter list and the keyword-parameter. If there is no rest-parameter and there are no matching keyword-parameters, then it shall be an error for there to be any remaining arguments left unbound.
34* If {{#!key}} was specified in the parameter-list, there shall 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. It shall be an error if the first member of an argument pair is not a keyword, unless there is a rest-parameter. 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.
36It shall be an error for an {{<ident>}} to appear more than once in a parameter-list.
38Keyword arguments are internally handled as rest-parameters with subsequent processing
39of the argument list. Extra arguments (for example by specifying keyword arguments
40but no rest argument) are not checked and simply ignored.
44 ((lambda x x) 3 4 5 6)       => (3 4 5 6)
45 ((lambda (x y #!rest z) z)
46  3 4 5 6)                    => (5 6)
47 ((lambda (x y #!optional z #!rest r #!key i (j 1))
48     (list x y z i: i j: j))
49  3 4 5 i: 6 i: 7)            => (3 4 5 i: 6 j: 1)
51[4.1.6] {{set!}} for unbound toplevel variables is allowed. {{set! (PROCEDURE ...) ...)}}
52is supported, as CHICKEN implements [[|SRFI-17]].
53[4.2.1] The {{cond}} form supports [[|SRFI-61]].
55[4.2.2] It is allowed for initialization values of bindings in a {{letrec}}
56construct to refer to previous variables in the same set of bindings, so
58 (letrec ((foo 123)
59          (bar foo) )
60   bar)
62is allowed and returns {{123}}.
64[4.2.3] {{(begin)}} is allowed in non-toplevel contexts and evaluates
65to an unspecified value.
67[4.2.5] Delayed expressions may return multiple values.
69[5.2.2] CHICKEN extends standard semantics by allowing internal definitions
70everywhere, and not only at the beginning of a body. A set of internal definitions
71is equivalent to a {{letrec}} form enclosing all following expressions
72in the body:
74 (let ((foo 123))
75   (bar)
76   (define foo 456)
77   (baz foo) )
79expands into
81 (let ((foo 123))
82   (bar)
83   (letrec ((foo 456))
84     (baz foo) ) )
86[5.2] {{define}} with a single argument is allowed and initializes the toplevel or local binding
87to an unspecified value. CHICKEN supports ''curried'' definitions, where the variable name
88may also be a list specifying a name and a nested lambda list. So
90 (define ((make-adder x) y) (+ x y))
92is equivalent to
94 (define (make-adder x) (lambda (y) (+ x y)))
96[6] CHICKEN provides numerous non-standard procedures. See the manual
97sections on library units for more information.
99[6.2.4] The special IEEE floating-point numbers ''+nan'', ''+inf'' and ''-inf''
100are supported, as is negative zero.
102[6.3.4] User defined character names are supported. See
103{{char-name}}. Characters can be given
104in hexadecimal notation using the ''#\xXX'' syntax where ''XX'' specifies the
105character code. Character codes above 255 are supported and can be read (and are
106written) using the ''#\uXXXX'' and ''#\UXXXXXXXX'' notations.
108Non-standard characters names supported are {{#\tab}}, {{#\linefeed}}, {{#\return}}, {{#\alarm}},
109{{#\vtab}}, {{#\nul}}, {{#\page}}, {{#\esc}}, {{#\delete}} and {{#\backspace}}.
111[6.3.5]  CHICKEN supports special characters preceded with
112a backslash ''\'' in quoted string
113constants. ''\n'' denotes the newline-character,
114''\r'' carriage return, ''\b''
115backspace, ''\t'' TAB, ''\v'' vertical TAB, ''\a'' alarm, ''\f'' formfeed,
116''\xXX'' a character with the code {{XX}} in hex and
117''\uXXXX'' (and ''\UXXXXXXXX'') a unicode character with the code {{XXXX}}.
118The latter is encoded in UTF-8 format.
120The third argument to {{substring}} is optional and defaults to the length
121of the string.
123[6.4] {{force}} called with an argument that is not a promise returns
124that object unchanged.  Captured continuations can be safely invoked
125inside before- and after-thunks of a {{dynamic-wind}} form and
126execute in the outer dynamic context of the {{dynamic-wind}} form.
128'''Implicit''' non-multival continuations accept multiple values by discarding all
129but the first result. Zero values result in the continuation receiving an
130unspecified value. Note that this slight relaxation of the behaviour of
131returning mulitple values to non-multival continuations does not apply to
132explicit continuations (created with {{call-with-current-continuation}}).
134[6.5] The second argument to {{eval}} is optional and
135defaults to the value of {{(interaction-environment)}}.
136{{scheme-report-environment}} and {{null-environment}} accept
137an optional 2nd parameter: if not {{#f}} (which is the default),
138toplevel bindings to standard procedures are mutable and new toplevel
139bindings may be introduced.
141[6.6] The ''tilde'' character ({{~}}) is automatically expanded in pathnames.
142Additionally, if a pathname starts with {{$VARIABLE...}}, then the prefix is replaced
143by the value of the given environment variable.
145[6.6.1] if the procedures {{current-input-port}} and
146{{current-output-port}} are called with an argument (which should
147be a port), then that argument is selected as the new current input- and
148output-port, respectively.  The procedures {{open-input-file}},
149{{open-output-file}}, {{with-input-from-file}},
150{{with-output-to-file}}, {{call-with-input-file}} and
151{{call-with-output-file}} accept an optional second (or third)
152argument which should be one or more keywords, if supplied. These
153arguments specify the mode in which the file is opened. Possible
154values are the keywords {{#:text}}, {{#:binary}} or
157Previous: [[Deviations from the standard]]
159Next: [[Non-standard read syntax]]
Note: See TracBrowser for help on using the repository browser.