Primitive Types
Stof's primitive value types.
Every value in Stof is of a certain data type, which lets Stof know how to work with that data. There are two data types: scalar and compound. Stof also has a Box concept to allow passing values by reference and an "unknown" type to allow functions to accept many different value types.
Scalar Types
A scalar type represents a single value. Stof has 5 primary scalar types: integers, floating-point numbers, booleans, strings, and blobs.
Integers
An integer is a number without a fractional component. Stof has one integer type (currently), which is an "int". This is implemented as an i64, which is a signed 64-bit integer and is very practical for how Stof is used.
Floating-point Numbers
A floating-point number is a number with decimal points. Stof has one floating-point type (currently), which is a "float". This is implemented as an f64, which on modern CPUs is roughly the same speed as a 32-bit floating-point number with more precision.
Operations
Stof supports the basic operations for number types: addition, subtraction, multiplication, division, and remainder.
Units
A variant of a floating-point number exists in Stof with units attached. Stof performs unit conversions when you cast a units scalar to a different units type. For comparisons, Stof finds a common base unit to compare with. For operations, Stof will convert differing units to the same units.
Take a look at the Units page for an overview of available units in Stof.
Booleans
Booleans can have one of two possible values: true or false.
Strings
Strings are Stof's most primitive alphabetic type. String literals can be declared using double or single quotes, can be multi-line, and are very versatile. Stof also has template strings, which expand into a string using expressions and unions.
Blobs
Blobs are Uint8Arrays in JavaScript or Vec<u8> in Rust. They represent a binary blob of data and can be converted to and from Stof vectors if needed. Stof has blobs because it is a nice catch-all for data that isn't in a form Stof understands yet or isn't necessary for Stof to work with. An example might be speech data in a talk-to-text LLM transaction. Stof in that case might just be the messenger.
Blobs are a scalar type because Stof treats blobs as a singular value, it is not a compound type that contains multiple Stof values.
Default casting between blobs and strings is UTF-8.
Another common scenario is in messaging systems, where data often travels as blobs. Stof can import blobs just like text through the document "header_import", which takes a format and/or content type. More on this later, but a very practical use of the blob type.
Compound Types
Compound types group multiple values into one type. Stof has four compound types: tuples, vectors, maps, and sets. In other languages or formats, vectors are called arrays or lists. Vectors in Stof are not typed and, therefore are compatible with JSON (and other formats) arrays. The same goes for maps and sets.
Tuples
A tuple is a general way of grouping multiple values of different types into a single compound type. Tuples are fixed in length and cannot grow or shrink once declared. They can, however, be cast to vectors for manipulation (values are copied).
Vectors
Vectors, unlike tuples, are able to grow and shrink in size. Unlike many other languages, vectors in Stof can contain values of many different types.
Sets
Sets are similar to vectors, however, are always ordered in Stof, and are more efficient for performing contains checks, unions, intersections, etc...
Maps
Just like in other languages, maps are useful for associating keys with values. Maps in Stof are ordered just like sets and accept any Stof type as key or value.
Box Types
By default, every value in Stof is passed around by value, meaning values are copied often. In a lot of situations, this is just fine. To pass values by reference, however, Stof also offers the Box type, which wraps any other Stof value and places it on the heap.
A boxed value will be passed by reference and can be created with a cast or the standard library "box" function. Boxed values in Stof dereference themselves when needed, for example here in the equality check.
For scalar types, boxing doesn't always make sense. However, for compound types, it often does when they are passed between functions. Or, when you'd like to manipulate values within compound types.
Unknown Type
Every value in Stof always has a type, however, there are certain times (especially with imported data) that you want to accept a type into a value or function but aren't sure what it is. This is where the "unknown" type comes in handy.
The "unknown" type is just syntactic sugar to accept any type of value.
Last updated