Literals

RL provides the following literals.

  • Symbols
  • Strings
  • Numbers
  • Bit Strings

An odd property of the literals is that, while each has a default type, you can override the type if you wish.

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 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'

+%7B+symbol+%3D+usual_symbol+%7C+quoted_symbol+.+usual_symbol+%3D+%22%5Ba-zA-Z%5D%5Ba-zA-Z0-9_%5D%2A%22+%7C+%22_%5Ba-zA-Z0-9_%5D%2B%22+.+quoted_symbol+%3D+%22%27%22+%7B+%27%5B%5E%5C%5C%5C%5C%22%5D%27+%7C+ESCAPE+%7D+%22%27%22+.+ESCAPE+%3D+%27%5C%5C%5C%5Cn%27+%7C+%27%5C%5C%5C%5Cr%27+%7C+%27%5C%5C%5C%5Ct%27+%7C+%27%5C%5C%5C%5C%5C%5C%5C%5C%27+%7C+%27%5C%5C%5C%5C%22%27+%7C+%22%5C%5C%5C%5C%27%22+%7C+UNICODE+.+UNICODE+%3D+%27%5C%5C%5C%5Cu%7B%27+%22%5B0-9a-fA-F%5D%2B%22+%27%7D%27+.+%7D+

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”.

  • rl/literals.txt
  • Last modified: 2019/01/09 22:37
  • by sprowell