====== Literals ====== RL provides the following literals. * Symbols * Strings * Numbers * Bit Strings Note that [[rl:termliterals|term literals]] are described elsewhere. An odd property of the literals is that, while each has a default type, you can //override// the type if you wish. ===== Symbols ===== A **symbol** has two forms. * A "usual" symbol starts with either a letter or an underscore followed by letters, underscores, or digits, with the exception that the lone underscore is not permitted to avoid conflict with the wildcard (see [[rl:primitives|Primitives]]). * A "quoted" symbol is any sequence of characters enclosed in single quotation marks (''%%'..'%%''), including the special escape sequences ''\n'' (newline), ''\r'' (carriage return), ''\t'' (tab), ''\\'' (backslash), ''\"'' (double quotation mark), ''%%\'%%'' (single quotation mark), and ''\\u{N}'' where ''N'' is a hexadecimal number of up to six characters specifying a Unicode code point. While you don't really need to escape double quotation marks in a symbol, the choice to allow the escape makes this consistent with strings. The following are examples of symbols. fred _primary_ '' '5' '$ 9\'-' Set_3 The default type for all symbols is the root type ''SYMBOL'', but the type of a symbol can be given explicitly. This allows distinguishing between root types (like ''STRING:^ROOT'') and symbols with the same name (like ''STRING:SYMBOL''). The following are legal symbols. |''%%'_'%%'' |Would otherwise conflict with the wildcard '_' | |''%%'^ROOT'%%'' |Would otherwise conflict with the root term | |''%%'ANY'%%'' and ''ANY:SYMBOL'' |Would otherwise conflict with the wildcard 'ANY' | |''%%'NONE'%%'' and ''NONE:SYMBOL'' |Would otherwise conflict with the wildcard 'NONE' | |''%%'INTEGER'%%'' and ''INTEGER:SYMBOL'' |Would otherwise conflict with the root type 'INTEGER' | { symbol = usual_symbol | quoted_symbol . usual_symbol = "[a-zA-Z][a-zA-Z0-9_]*" | "_[a-zA-Z0-9_]+" . quoted_symbol = "'" { '[^\\\\"]' | ESCAPE } "'" . ESCAPE = '\\\\n' | '\\\\r' | '\\\\t' | '\\\\\\\\' | '\\\\"' | "\\\\'" | UNICODE . UNICODE = '\\\\u{' "[0-9a-fA-F]+" '}' . } ===== Strings ===== A **string** has two forms. * A "usual" string is any sequence of characters enclosed in double quotation marks (''%%".."%%''), including the special escape sequences ''\n'' (newline), ''\r'' (carriage return), ''\t'' (tab), ''\\'' (backslash), ''\"'' (double quotation mark), ''%%\'%%'' (single quotation mark), and ''\\u{N}'' where ''N'' is a hexadecimal number of up to six characters specifying a Unicode code point. * A "long" string is any sequence of characters enclosed in triple quotation marks (''""".."""''). Character escapes are not interpreted; all characters are preserved as-is. As we will see later, strings can be composed with the //applicative dot//, so ''"Hello "."""world"""'' becomes the string ''"Hello world"''.