~ chicken-core (master) /manual/Extensions to the standard
Trap1[[tags: manual]]23[[toc:]]45== Extensions to the R7RS standard67=== Brackets and braces89The brackets {{[ ... ]}} and the braces {{ { ... } }} are10provided as an alternative syntax for {{( ... )}}. A number of reader11extensions is provided.1213=== User defined character names1415User defined character names are supported. See16{{char-name}}. Numeric hexadecimal character codes above are supported and can be read17using ''#\uXXXX'' and ''#\UXXXXXXXX'', in addition to the standard ''\x...;'' notation.1819Non-standard characters names supported are {{#\linefeed}}, {{#\vtab}}, {{#\nul}}, {{#\page}} and {{#\esc}}.2021== Non-standard read syntax2223=== Multiline Block Comment2425<read>#|</read>2627 #| ... |#2829A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].3031=== Expression Comment3233<read>#;</read>3435 #;EXPRESSION3637Treats {{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]].3839=== External Representation4041<read>#,</read>4243 #,(CONSTRUCTORNAME DATUM ...)4445Allows user-defined extension of external representations. (For more information see the documentation for46[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])4748=== Location Expression4950<read> #$EXPRESSION</read>5152An abbreviation for {{(location EXPRESSION)}}.5354=== Bytevector strings5556<read>#u8"..."</read>5758String syntax for bytevectors, as an alternative to {{#u8(...)}}. The usual escape sequences for strings are recognized.5960=== Keyword6162<read>#:</read>6364 #:SYMBOL65 SYMBOL:66 :SYMBOL6768Syntax for keywords. Keywords are symbol-like objects 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.6970=== Multiline String Constant7172<read>#<<</read>7374 #<<TAG7576Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:7778 (define msg #<<END79 "Hello, world!", she said.80 END81 )8283is equivalent to8485 (define msg "\"Hello, world!\", she said.")8687=== Multiline String Constant with Embedded Expressions8889<read>#<#</read>9091 #<#TAG9293Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:9495 (define three 3)96 (display #<#EOF97 This is a simple string with an embedded `##' character98 and substituted expressions: (+ three 99) ==> #(+ three 99)99 (three is "#{three}")100 EOF101 )102103prints104105 This is a simple string with an embedded `#' character106 and substituted expressions: (+ three 99) ==> 102107 (three is "3")108109=== Foreign Declare110111<read>#></read>112113 #> ... <#114115Abbreviation for {{(foreign-declare " ... ")}}.116117=== String escape sequences118119String-literals may contain the following escape sequences:120121<table style="margin-top: 1em; max-width: 40em">122<tr><th>Escape sequence</th><th>Character</th></tr>123<tr><td>{{\n}}</td><td>line feed / newline</td></tr>124<tr><td>{{\t}}</td><td>tab</td></tr>125<tr><td>{{\r}}</td><td>carriage return</td></tr>126<tr><td>{{\b}}</td><td>backspace</td></tr>127<tr><td>{{\a}}</td><td>bell</td></tr>128<tr><td>{{\v}}</td><td>vertical tab</td></tr>129<tr><td>{{\f}}</td><td>form feed</td></tr>130<tr><td>{{\x}}''XX;''</td><td>hexadecimal 8-bit character code</td></tr>131<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>132<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>133<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>134<tr><td>{{\|}} {{\"}} {{\\}} {{\'}}</td><td>the escaped character</td></tr>135</table>136137138=== Bang139140<read>#!</read>141142 #!...143144Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.145146; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored147148; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned149150; 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 returned151152; 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 (see {{set-read-syntax!}}).153154=== Conditional Expansion155156<read>#+</read>157158 #+FEATURE EXPR159160Rewrites to161162 (cond-expand (FEATURE EXPR) (else))163164and performs the feature test at macroexpansion time. Therefore, it may not165work as expected when used within a macro form.166167---168Previous: [[Deviations from the standard]]169170Next: [[Interface to external functions and variables]]