source: project/wiki/man/4/Non-standard read syntax @ 25875

Last change on this file since 25875 was 25875, checked in by felix winkelmann, 9 years ago

merged some manual changes from master into wiki

File size: 5.2 KB
Line 
1[[tags: manual]]
2
3[[toc:]]
4
5== Non-standard read syntax
6
7=== Escapes in symbols
8
9{{| ... |}} may be used to escape a sequence of characters when reading a symbol.
10{{\X}} escapes a single character in a symbols name:
11
12  (symbol->string '|abc def|)       =>   "abc def"
13  (symbol->string '|abc||def|)      =>   "abcdef"
14  (symbol->string '|abc|xyz|def|)   =>   "abcxyzdef"
15  (symbol->string '|abc\|def|)      =>   "abc|def"
16  (symbol->string 'abc\ def)        =>   "abc def"
17
18=== Multiline Block Comment
19
20<read>#|</read>
21
22 #| ... |#
23
24A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].
25
26=== Expression Comment
27
28<read>#;</read>
29
30 #;EXPRESSION
31
32Treats {{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]].
33
34=== External Representation
35
36<read>#,</read>
37
38 #,(CONSTRUCTORNAME DATUM ...)
39
40Allows user-defined extension of external representations. (For more information see the documentation for
41[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])
42
43=== Location Expression
44
45 #$EXPRESSION
46
47An abbreviation for {{(location EXPRESSION)}}.
48
49=== Blob literals
50
51<read>#{</read>
52
53  #{ HEX ... }
54
55Syntax for literal "blobs" (byte-sequences). Expects hexadecimal digits and ignores
56any whitespace characters:
57
58  #;1> ,d '${deadbee f}
59  blob of size 4:
60     0: de ad be ef                                     ....
61
62=== Keyword
63
64<read>#:</read>
65
66 #:SYMBOL
67 SYMBOL:
68 :SYMBOL
69
70Syntax 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.
71
72=== Multiline String Constant
73
74<read>#<<</read>
75
76 #<<TAG
77
78Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:
79
80 (define msg #<<END
81  "Hello, world!", she said.
82 END
83 )
84
85is equivalent to
86
87 (define msg "\"Hello, world!\", she said.")
88
89=== Multiline String Constant with Embedded Expressions
90
91<read>#<</read>
92
93 #<#TAG
94
95Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:
96
97 (define three 3)
98 (display #<#EOF
99 This is a simple string with an embedded `##' character
100 and substituted expressions: (+ three 99) ==> #(+ three 99)
101 (three is "#{three}")
102 EOF
103 )
104
105prints
106
107 This is a simple string with an embedded `#' character
108 and substituted expressions: (+ three 99) ==> 102
109 (three is "3")
110
111=== Foreign Declare
112
113<read>#></read>
114
115 #> ... <#
116
117Abbreviation for {{(foreign-declare " ... ")}}.
118
119=== String escape sequences
120
121String-literals may contain the following of the escape sequences:
122
123<table>
124<tr><th>Escape sequence</th><th>Character</th></tr>
125<tr><td>\n</td><td>line feed / newline</td></tr>
126<tr><td>\t</td><td>tab</td></tr>
127<tr><td>\r</td><td>carriage return</td></tr>
128<tr><td>\b</td><td>backspace</td></tr>
129<tr><td>\a</td><td>bell</td></tr>
130<tr><td>\v</td><td>vertical tab</td></tr>
131<tr><td>\f</td><td>form feed</td></tr>
132<tr><td>\xXX</td><td>hexadecimal 8-bit character</td></tr>
133<tr><td>\uXXXX</td><td>hexadecimal 16-bit UNICODE character</td></tr>
134<tr><td>\UXXXXXXXX</td><td>hexadecimal 32-bit UNICODE character</td></tr>
135<tr><td>\OOO</td><td>octal 8-bit character</td></tr>
136<tr><td>\| \" \\ \'</td><td>represents escaped character</td></tr>
137</table>
138
139
140=== Foreign Declare
141
142 #> ... <#
143
144Abbreviation for {{foreign-declare " ... ")}}.
145
146=== Sharp Prefixed Symbol
147
148<read>#%</read>
149
150 #%...
151
152Reads like a normal symbol.
153
154=== Bang
155
156<read>#!</read>
157
158 #!...
159
160Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.
161
162; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored
163
164; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned
165
166; 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
167
168; 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
169
170=== Case Sensitive Expression
171
172<read>#cs</read>
173
174 #cs...
175
176Read the next expression in case-sensitive mode (regardless of the current global setting).
177
178=== Case Insensitive Expression
179
180<read>#ci</read>
181
182 #ci...
183
184Read the next expression in case-insensitive mode (regardless of the current global setting).
185
186=== Conditional Expansion
187
188<read>#+</read>
189
190 #+FEATURE EXPR
191
192Rewrites to
193
194 (cond-expand (FEATURE EXPR) (else))
195
196and performs the feature test at macroexpansion time.  Therefore, it may not
197work as expected when used within a macro form.
198
199---
200Previous: [[Extensions to the standard]]
201
202Next: [[Non-standard macros and special forms]]
Note: See TracBrowser for help on using the repository browser.