Kipper
Kipper copied to clipboard
[Feature] Implement support for built-in type identifiers such as `str`, `num`, `bool` etc.
Is there an existing proposal for this?
- [X] I have searched the existing issues
This feature does not exist in the latest version
- [X] I am using the latest version
Proposal
Implement support for type identifiers, which should be usable during runtime to compare types.
This includes the following types:
-
bool
-
str
-
num
But importantly excludes the following types, as they are constants and therefore have as the type themselves. This also means doing typeof(<value of type undefined>)
will simply return undefined
and therefore should be rather replaced with <value of type undefined> == undefined
(Same as with null
and void
, which is effectively a synonym for undefined
.
This extends proposal #369, which proposes support for the built-in typeof()
function allowing dynamic type checking.
Exact behaviour / changes you want
- [ ] Implement runtime type objects for the Kipper base primitive types
str
,num
andbool
. - [ ] Add support for comparisons using
typeof(EXP)
and the constant type identifiers. - [ ] Allow the identifiers to be assigned to variables using the type
type
, for example:
This also serves as the foundation for future custom types using custom type definitions with interfaces or unions.var reflectedType: type = num; if (typeof(someVariable) == reflectedType) { // It is of type 'num' ... }
Additional Notes
- #373 (Detailed implementation reference)
- #332 (Proof of concept for the runtime types)