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

Last change on this file since 7276 was 7276, checked in by felix winkelmann, 12 years ago

merged trunk

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