Keys are global primitive values without intrinsic semantics.
Discussion
Keys are values whose implementations are hidden.
.WATER; % a key
.FIRE; % another key
Key names are programmer-defined identifiers, and always follow a dot. They’re conventionally written in MACRO_CASE, but sometimes also in snake_case.
The values of Keys are the only of their kind, and their implementations are unexposed. Keys can be thought of as integers or strings, but can’t be operated on as such and do not take up as much space. Keys are also not assignable to the int or str types. Like all values, keys can be assigned to types obj and unknown.
let greet: obj = .hello_world;
Key names may be any keyword or identifier, starting with a letter or underscore, and subsequently containing letters, underscores, and/or digits. Key names may also be Unicode names, but this is not recommended as it hinders readability. As with Unicode identifiers, there are no escapes.
let greet: unknown = .'¡héllö wòrld!';
.'\u{24}3.99' != .'$3.99';
Other than obj and unknown, Keys are assignable to their unit types. (Unit types are types containing only one value — also referred to as “constant types”.)
let earth: .EARTH = .EARTH;
Key unit types can be unioned to form an enumeration of values.
type Element = .WATER | .EARTH | .FIRE | .AIR;
let unfixed el: Element = .FIRE;
set el = .AIR;
set el = .AETHER; %> TypeError
All Key unit types are disjoint, so their intersection is always never.
type Impossible = .WATER & .EARTH; % type `never`
Counterpoint has a designated key type, which is conceptually the infinite union of all Key values. Any Key value is assignable to the key type, and only Key values are assignable to this type.
let unfixed el: key = .FIRE;
set el = .AIR;
set el = .AETHER;
set el = 42; %> TypeError
set el = "a string"; %> TypeError
Key values are always truthy and always nonempty.
!(.WATER) == false; % `!.WATER` is a parse error
?(.FIRE) == false; % `?.FIRE` is a parse error
.EARTH || .AIR == .EARTH;
.EARTH && .AIR == .AIR;
(Note: The Keys above must be wrapped in parentheses, because the tokens !. and ?. are accessor operators. Or we could use whitespace to separate the operator from the Key.)
! .WATER == false; % also acceptable, but maybe less readable
? .FIRE == false; % also acceptable, but maybe less readable
Keys are equal if and only if their names are exactly the same. Keys are identical if and only if they are equal.
-SemanticConstant[value: Null | Boolean | Number | String]
+SemanticConstant[value: Null | Boolean | Key | Number | String]
::= ();
Data Types
- [Never](#never)
- [Void](#void)
- [Null](#null)
- [Boolean](#boolean)
+- [Key](#key)
- [Integer](#integer)
- [Float](#float)
- [String](#string)
- [Object](#object)
- [Unknown](#unknown)
+#### Key
+The **Key** type contains programmer-defined values whose implementations are hidden.
+They may only be referred to by name.
+The meaning of each Key value may be specified by the programmer.
Keys are global primitive values without intrinsic semantics.
Discussion
Keys are values whose implementations are hidden.
Key names are programmer-defined identifiers, and always follow a dot. They’re conventionally written in MACRO_CASE, but sometimes also in snake_case.
The values of Keys are the only of their kind, and their implementations are unexposed. Keys can be thought of as integers or strings, but can’t be operated on as such and do not take up as much space. Keys are also not assignable to the
int
orstr
types. Like all values, keys can be assigned to typesobj
andunknown
.Key names may be any keyword or identifier, starting with a letter or underscore, and subsequently containing letters, underscores, and/or digits. Key names may also be Unicode names, but this is not recommended as it hinders readability. As with Unicode identifiers, there are no escapes.
Other than
obj
andunknown
, Keys are assignable to their unit types. (Unit types are types containing only one value — also referred to as “constant types”.)Key unit types can be unioned to form an enumeration of values.
All Key unit types are disjoint, so their intersection is always
never
.Counterpoint has a designated
key
type, which is conceptually the infinite union of all Key values. Any Key value is assignable to thekey
type, and only Key values are assignable to this type.Key values are always truthy and always nonempty.
(Note: The Keys above must be wrapped in parentheses, because the tokens
!.
and?.
are accessor operators. Or we could use whitespace to separate the operator from the Key.)Keys are equal if and only if their names are exactly the same. Keys are identical if and only if they are equal.
As primitive values, Key values are value objects rather than reference objects.
Specification
Lexicon
Syntax
Decorate
Semantics
Data Types
ValueOf
Build
Note: Keys will be implemented as int32 values in the virtual machine.