| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| rl:primitives [2020/11/21 22:53] – Corrected error regarding NONE. sprowell | rl:primitives [2020/11/21 23:04] (current) – [Boolean Literals] sprowell |
|---|
| ===== The Root of the Type System ===== | ===== The Root of the Type System ===== |
| |
| Every term has an associated type. This potentially infinite regress is broken by the special term ''^ROOT'', which is the root of the type system and is its own type. Any term whose type is ''^ROOT'' is referred to as a **root term** or **root type**. Since types are just terms in RL, either usage is fine; it is also fine for the type theorists out there to refer to ''^ROOT'' as "bottom." | Every term has an associated type. This potentially infinite regress is broken by the special term ''^ROOT'', which is the root of the type system and is its own type. Any term whose type is ''^ROOT'' is referred to as a **root term** or **root type**. Since types are just terms in RL, either usage is fine. It is also fine for the type theorists out there to refer to ''^ROOT'' as "bottom." |
| |
| Many of the "usual" types are really just symbols whose declared type is ''^ROOT'', such as ''INTEGER: ^ROOT'', which is the usual type for integers: ''5: INTEGER''. | Many of the "usual" types are really just symbols whose declared type is ''^ROOT'', such as ''INTEGER: ^ROOT'', which is the usual type for integers: ''5: INTEGER''. |
| Note the unusual name. This is the only unquoted symbol that starts with a caret (''^''). | Note the unusual name. This is the only unquoted symbol that starts with a caret (''^''). |
| |
| Parsing is complicated by the existence of symbol root types. Without any additional context, ''INTEGER'' would be interpreted as ''INTEGER: SYMBOL'', but parsing requires that we instead interpret ''INTEGER'' as ''INTEGER: ^ROOT'' for things to work correctly. This is true for all the primitive root types: ''INTEGER'', ''FLOAT'', ''BITSTRING'', ''STRING'', and ''BOOLEAN'', and for the special patterns ''ANY'' and ''NONE''. | Parsing is complicated by the existence of symbol root types. Whenever an unquoted symbol without an explicit type is parsed, it is checked to see if it is a known root type. If so, it is converted to that type. Thus ''INTEGER'' by itself parses as the root type ''INTEGER: ^ROOT'', while '''INTEGER''' is explicitly a quoted symbol, and parses as ''INTEGER: SYMBOL''. In a similar vein, note the Boolean literals, described below. |
| |
| ===== Defined Root Terms ===== | ===== Defined Root Terms ===== |
| ===== The Wildcard and Nothing ===== | ===== The Wildcard and Nothing ===== |
| |
| There is a special root term ''ANY'' that, as a //pattern//, matches any //subject//. We may refer to ''ANY'' as the **wildcard**, and it may also be abbreviated ''_''. There is also a root term ''NONE'' that, as a //pattern//, does not match any //subject// except itself. We can summarize this as follows, where //t// and //u// are arbitrary terms that are neither ''NONE'' nor ''ANY''. | There is a special root term ''ANY'' that, as a //pattern//, matches any //subject//. We refer to ''ANY'' as the **wildcard**, and it may also be abbreviated by a single underscore ''_''. There is also a root term ''NONE'' that, as a //pattern//, does not match any //subject// except itself. We can summarize this as follows, where //t// and //u// are arbitrary terms that are neither ''NONE'' nor ''ANY''. |
| |
| ^ pattern ^ subject ^^^ | ^ pattern ^ subject ||^ |
| ^ ^ ''ANY'' ^ //t// ^ ''NONE'' ^ | ^ ^ ''ANY'' ^ //t// ^ ''NONE'' ^ |
| ^ ''ANY'' | match | match | match | | ^ ''ANY'' | match | match | match | |
| ^ //u// | no match | //u// ~ //t// | no match | | ^ //u// | no match | //u// ~ //t// | no match | |
| ^ ''NONE'' | no match | no match | match | | ^ ''NONE'' | no match | no match | match | |
| |
| The special term ''ANY'' is intended to be the only term that breaks the pattern matching "substitution rule." If pattern //p// matches term //u// with bindings //b//, then it must be the case that //b(p)// is equal to //u//, up to isomorphism. That cannot work for ''ANY'' since it contains no variables to be bound. | The special term ''ANY'' is intended to be the only term that breaks the pattern matching "substitution rule." If pattern //p// matches term //u// with bindings //b//, then it must be the case that //b(p)// is equal to //u//, up to isomorphism. That cannot work for ''ANY'' since it contains no variables to be bound. |
| ===== Boolean Literals ===== | ===== Boolean Literals ===== |
| |
| The Boolean literals ''TRUE'' and ''FALSE'' are parsed as ''TRUE: BOOLEAN'' and ''FALSE: BOOLEAN''. | The Boolean literals ''TRUE'' and ''FALSE'' are parsed as ''TRUE: BOOLEAN'' and ''FALSE: BOOLEAN''. As with root terms, if the symbol is intended and not the Boolean literal, it must be quoted or an explicit type given, as with '''TRUE' ''and ''FALSE: SYMBOL''. |
| |
| ===== The Map Type ===== | ===== The Map Type ===== |
| ===== Sequence Types ===== | ===== Sequence Types ===== |
| |
| Sequences are | Sequences are |
| |
| ===== Special Form Type ===== | ===== Special Form Type ===== |
| |
| The type of all special forms is the root type ''SPECIAL_FORM''. | The type of all special forms is the root type ''SPECIAL_FORM''. |
| | |
| |