source: project/wiki/man/5/Extensions to the standard @ 35525

Last change on this file since 35525 was 35525, checked in by felix, 6 months ago

man/5: restructuring, fixed links, added csi module, simplification

File size: 7.0 KB
Line 
1[[tags: manual]]
2
3[[toc:]]
4
5== Extensions to the standard
6
7=== Identifiers
8
9Identifiers may contain special characters if delimited with
10{{| ... |}}.
11
12=== Brackets and braces
13
14The brackets {{[ ... ]}} and the braces {{ { ... } }} are
15provided as an alternative syntax for {{( ... )}}.  A number of reader
16extensions is provided. See [[Non-standard read syntax]].
17
18=== Non-standard macros
19
20Numerous non-standard macros are provided. See
21[[Non-standard macros and special forms]] for more information.
22
23=== Non-standard procedures
24
25CHICKEN provides numerous non-standard procedures. See the manual
26sections on library units for more information.
27
28=== User defined character names
29
30User defined character names are supported. See
31{{char-name}}. Characters can be given
32in hexadecimal notation using the ''#\xXX'' syntax where ''XX'' specifies the
33character code. Character codes above 255 are supported and can be read (and are
34written) using the ''#\uXXXX'' and ''#\UXXXXXXXX'' notations.
35
36Non-standard characters names supported are {{#\tab}}, {{#\linefeed}}, {{#\return}}, {{#\alarm}},
37{{#\vtab}}, {{#\nul}}, {{#\page}}, {{#\esc}}, {{#\delete}} and {{#\backspace}}.
38
39=== Special characters in strings
40
41CHICKEN supports special characters preceded with
42a backslash ''\'' in quoted string
43constants. ''\n'' denotes the newline-character,
44''\r'' carriage return, ''\b''
45backspace, ''\t'' TAB, ''\v'' vertical TAB, ''\a'' alarm, ''\f'' formfeed,
46''\xXX'' a character with the code {{XX}} in hex and
47''\uXXXX'' (and ''\UXXXXXXXX'') a unicode character with the code {{XXXX}}.
48The latter is encoded in UTF-8 format.
49
50The third argument to {{substring}} is optional and defaults to the length
51of the string.
52
53=== {{exit}}
54
55The {{exit}} procedure exits a program right away and does ''not'' invoke pending {{dynamic-wind}} thunks.
56
57
58== Non-standard read syntax
59
60=== Escapes in symbols
61
62{{| ... |}} may be used to escape a sequence of characters when reading a symbol.
63{{\X}} escapes a single character in a symbols name:
64
65  (symbol->string '|abc def|)       =>   "abc def"
66  (symbol->string '|abc||def|)      =>   "abcdef"
67  (symbol->string '|abc|xyz|def|)   =>   "abcxyzdef"
68  (symbol->string '|abc\|def|)      =>   "abc|def"
69  (symbol->string 'abc\ def)        =>   "abc def"
70
71=== Multiline Block Comment
72
73<read>#|</read>
74
75 #| ... |#
76
77A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].
78
79=== Expression Comment
80
81<read>#;</read>
82
83 #;EXPRESSION
84
85Treats {{EXPRESSION}} as a comment.  That is, the comment runs through the whole S-expression, regardless of newlines, which saves you from having to comment out every line, or add a newline in the middle of your parens to make the commenting of the last line work, or other things like that. Implements [[http://srfi.schemers.org/srfi-62/srfi-62.html|SRFI-62]].
86
87=== External Representation
88
89<read>#,</read>
90
91 #,(CONSTRUCTORNAME DATUM ...)
92
93Allows user-defined extension of external representations. (For more information see the documentation for
94[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])
95
96=== Location Expression
97
98 #$EXPRESSION
99
100An abbreviation for {{(location EXPRESSION)}}.
101
102=== Blob literals
103
104<read>#${</read>
105
106  #${ HEX ... }
107
108Syntax for literal "blobs" (byte-sequences). Expects hexadecimal digits and ignores
109any whitespace characters:
110
111  #;1> ,d '#${deadbee f}
112  blob of size 4:
113     0: de ad be ef                                     ....
114
115=== Keyword
116
117<read>#:</read>
118
119 #:SYMBOL
120 SYMBOL:
121 :SYMBOL
122
123Syntax for keywords. Keywords are symbols that evaluate to themselves, and as such don't have to be quoted.  Either {{SYMBOL:}} or {{:SYMBOL}} is accepted, depending on the setting of the {{keyword-style}} parameter, but never both.  {{#:SYMBOL}} is always accepted.
124
125=== Multiline String Constant
126
127<read>#<<</read>
128
129 #<<TAG
130
131Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:
132
133 (define msg #<<END
134  "Hello, world!", she said.
135 END
136 )
137
138is equivalent to
139
140 (define msg "\"Hello, world!\", she said.")
141
142=== Multiline String Constant with Embedded Expressions
143
144<read>#<#</read>
145
146 #<#TAG
147
148Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:
149
150 (define three 3)
151 (display #<#EOF
152 This is a simple string with an embedded `##' character
153 and substituted expressions: (+ three 99) ==> #(+ three 99)
154 (three is "#{three}")
155 EOF
156 )
157
158prints
159
160 This is a simple string with an embedded `#' character
161 and substituted expressions: (+ three 99) ==> 102
162 (three is "3")
163
164=== Foreign Declare
165
166<read>#></read>
167
168 #> ... <#
169
170Abbreviation for {{(foreign-declare " ... ")}}.
171
172=== String escape sequences
173
174String-literals may contain the following escape sequences:
175
176<table style="margin-top: 1em; max-width: 40em">
177<tr><th>Escape sequence</th><th>Character</th></tr>
178<tr><td>{{\n}}</td><td>line feed / newline</td></tr>
179<tr><td>{{\t}}</td><td>tab</td></tr>
180<tr><td>{{\r}}</td><td>carriage return</td></tr>
181<tr><td>{{\b}}</td><td>backspace</td></tr>
182<tr><td>{{\a}}</td><td>bell</td></tr>
183<tr><td>{{\v}}</td><td>vertical tab</td></tr>
184<tr><td>{{\f}}</td><td>form feed</td></tr>
185<tr><td>{{\x}}''XX''</td><td>hexadecimal 8-bit character code</td></tr>
186<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>
187<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>
188<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>
189<tr><td>{{\|}}   {{\"}}    {{\\}}    {{\'}}</td><td>the escaped character</td></tr>
190</table>
191
192
193=== Sharp Prefixed Symbol
194
195<read>#%</read>
196
197 #%...
198
199Reads like a normal symbol.
200
201=== Bang
202
203<read>#!</read>
204
205 #!...
206
207Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.
208
209; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored
210
211; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned
212
213; DSSSL Formal Parameter List Annotation : If followed by any of the character sequences {{optional}}, {{rest}} or {{key}}, then a symbol with the same name (and prefixed with {{#!}}) is returned
214
215; Read Mark Invocation : If a ''read mark'' with the same name as the token is registered, then its procedure is called and the result of the read-mark procedure will be returned
216
217=== Case Sensitive Expression
218
219<read>#cs</read>
220
221 #cs...
222
223Read the next expression in case-sensitive mode (regardless of the current global setting).
224
225=== Case Insensitive Expression
226
227<read>#ci</read>
228
229 #ci...
230
231Read the next expression in case-insensitive mode (regardless of the current global setting).
232
233=== Conditional Expansion
234
235<read>#+</read>
236
237 #+FEATURE EXPR
238
239Rewrites to
240
241 (cond-expand (FEATURE EXPR) (else))
242
243and performs the feature test at macroexpansion time.  Therefore, it may not
244work as expected when used within a macro form.
245
246---
247Previous: [[Deviations from the standard]]
248
249Next: [[Included modules]]
Note: See TracBrowser for help on using the repository browser.