source: project/wiki/man/5/TODO/Non-standard read syntax @ 35323

Last change on this file since 35323 was 35323, checked in by felix winkelmann, 18 months ago

manual: more links changed, added R5RS page (or should it be R7RS?)

File size: 5.3 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 escape sequences:
122
123<table style="margin-top: 1em; max-width: 40em">
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>{{\x}}''XX''</td><td>hexadecimal 8-bit character code</td></tr>
133<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>
134<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>
135<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>
136<tr><td>{{\|}}   {{\"}}    {{\\}}    {{\'}}</td><td>the escaped character</td></tr>
137</table>
138
139
140=== Sharp Prefixed Symbol
141
142<read>#%</read>
143
144 #%...
145
146Reads like a normal symbol.
147
148=== Bang
149
150<read>#!</read>
151
152 #!...
153
154Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.
155
156; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored
157
158; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned
159
160; 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
161
162; 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
163
164=== Case Sensitive Expression
165
166<read>#cs</read>
167
168 #cs...
169
170Read the next expression in case-sensitive mode (regardless of the current global setting).
171
172=== Case Insensitive Expression
173
174<read>#ci</read>
175
176 #ci...
177
178Read the next expression in case-insensitive mode (regardless of the current global setting).
179
180=== Conditional Expansion
181
182<read>#+</read>
183
184 #+FEATURE EXPR
185
186Rewrites to
187
188 (cond-expand (FEATURE EXPR) (else))
189
190and performs the feature test at macroexpansion time.  Therefore, it may not
191work as expected when used within a macro form.
192
193---
194Previous: [[Non-standard macros and special forms]]
195
196Next: [[Macros]]
Note: See TracBrowser for help on using the repository browser.