Skip to content
Socratic_Phoenix edited this page Aug 21, 2017 · 8 revisions

<-- Back | Next -->


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

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

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

Functions are objects which can be invoked. Their default string representation is function[requiredParams,defaultParams]::<identity>

Array

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.

String

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.

Number

All number types implement every operator. The only difference between them is their string representations. Note that x/0 produces void.

Integer

An integer number, represented in a string as the number itself.

Decimal

A decimal number, represented in a string as the number itself.

Character

A integer unicode codepoint, represented in a string by the character itself.

Boolean

An integer valued 0 or 1, represented in a string as true or false

Bounded Types

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.

Absent

Their are two absent types, null and void.

Clone this wiki locally