6.6.6.5 Extended Read Syntax for Symbols

The read syntax for a symbol is a sequence of letters, digits, and extended alphabetic characters, beginning with a character that cannot begin a number. In addition, the special cases of +, -, and ... are read as symbols even though numbers can begin with +, - or ..

Extended alphabetic characters may be used within identifiers as if they were letters. The set of extended alphabetic characters is:

! $ % & * + - . / : < = > ? @ ^ _ ~

In addition to the standard read syntax defined above (which is taken from R5RS (see Formal syntax in The Revised^5 Report on Scheme)), Guile provides an extended symbol read syntax that allows the inclusion of unusual characters such as space characters, newlines and parentheses. If (for whatever reason) you need to write a symbol containing characters not mentioned above, you can do so as follows.

Here are a few examples of this form of read syntax. The first symbol needs to use extended syntax because it contains a space character, the second because it contains a line break, and the last because it looks like a number.

#{foo bar}#

#{what
ever}#

#{4242}#

Although Guile provides this extended read syntax for symbols, widespread usage of it is discouraged because it is not portable and not very readable.

Alternatively, if you enable the r7rs-symbols read option (see see Reading Scheme Code), you can write arbitrary symbols using the same notation used for strings, except delimited by vertical bars instead of double quotes.

|foo bar|
|\x3BB; is a greek lambda|
|\| is a vertical bar|

Note that there’s also an r7rs-symbols print option (see Writing Scheme Values). To enable the use of this notation, evaluate one or both of the following expressions:

(read-enable  'r7rs-symbols)
(print-enable 'r7rs-symbols)