-
Notifications
You must be signed in to change notification settings - Fork 0
Types
Despite being dynamic, there are internally many types. Every native type is a sub-type of object, so the Shnap language treats them all the same.
Note: The 'identity' of an object is a hex string derived from it's storage in memory. It does not change for any object, but is always different for different objects.
Objects are the one true type. They are basically a map of fields. To implement a named function, a field must be set to a function. Their default string representation is object::<identity>
, but some sub types override that.
Scripts, or modules, are the top-level objects that are stored in a file. They can be imported with native::sys.import
. Their default string representation is script[<name>]::<identity>
Functions are objects which can be invoked. Their default string representation is function[requiredParams,defaultParams]::<identity>
Arrays are collections which exist as an array of values in memory. They have the following functions:
Function | Params | Action |
---|---|---|
remove | index | removes the element at the given index, shrinking the array in the process. Returns void if the array does not contain the given index, else returns the value previously at the given index. |
insert | index | inserts the element at the given index, expanding the array in the process. Returns void if the array does not contain the given index, else returns the value previously at the given index, or void if no value was at the given index (if the index = the length). |
append | object | adds the given value to the end of the array, expanding the array in the process. Returns void. |
get | index | returns the element at the given index. |
set | index,object | sets the element at the given index to the given object. |
len | none | returns the length of the array. |
resize | size | resizes the array, either truncating the end or adding nulls (depending on whether the new size is less than or greater than the current size). Returns the array. |
contains | object | returns true if the array contains the given object, using == as a check. |
iterator | none | returns an iterator for the array. |
Strings are similar to arrays, but are immutable and represent a sequence of characters. They have the following functions:
Function | Params | Action |
---|---|---|
get | index | returns the character at the given index, or void if the string does not contain the index. |
len | none | returns the length of the string. |
iterator | none | returns an iterator for the string. |
All number types implement every operator. The only difference between them is their string representations. Note that x/0
produces void
.
An integer number, represented in a string as the number itself.
A decimal number, represented in a string as the number itself.
A integer unicode codepoint, represented in a string by the character itself.
An integer valued 0 or 1, represented in a string as true
or false
By default, integer and decimal numbers have arbitrary precision. However, any number type can be converted to a static precision of integer-32 bits
, integer-64 bits
or `decimal-64 bits with the appropriate builtins.
Their are two absent types, null
and void
.
Home | New Issue | Contact Me