Basic Types
Table of Contents
- Basic Types
- bool: Booleans
- str: Strings
- dec: Decimal numbers
- int: Integer numbers
- list: Lists of simple types
- dict: Key-value objects (dictionary)
- function: A function
- none: Nil-value
- datetime: Date time object
- Casting Types
- Type Hints
- Syntax
- Supported Types
- Example Script
sneq has the following basic types for data:
Basic Types
bool: Booleans
TrueorFalse
str: Strings
- Unicode characters are permitted.
dec: Decimal numbers
- All untyped numbers are decimals by default
- Emin = 9999, Emax = 9999
- Precision = 28
- Rounds down
int: Integer numbers
- Maximum integer value is 9223372036854775807
- Minimum integer value is -9223372036854775807
list: Lists of simple types
- Immutable
- You can expand lists by creating a new list via concatenation (
+), but you can not mutate a list by index i.e.foo[3] = 10 - Reference indexes in the list with square brackets e.g.
a_list[0] - Although lists do not have to be of the same type, some operators will fail if they are not
- Maximum number of elements allowed is 99999
dict: Key-value objects ("dictionary")
- Immutable
- You can expand dicts by creating a new dict via merge (
+), but you can not mutate a dict by index (foo['bar'] = 10will not work) - Key collisions on merge (
+) create a new dictionary with the old value replaced - You can approximate a dictionary update mutation by merging with colliding keys:
foo['bar'] = 10will not work but:
# The merge will approximate the update foo['bar'] = 10
foo = { 'bar': 5, 'val': 23 }
foo = foo + {'bar': 10}
# Now foo == { 'bar': 10, 'val': 23 }
- Ordered
- Reference values in the dict with square brackets e.g.
a_dict['foo'] - Keys must be strings
- Maximum number of keys allowed is 99999
function: A function
- User declared functions only take keyword arguments, e.g.
foo(bar="Hello World"). - Functions are the only data type passed by reference rather than value, but the referenced data is considered immutable.
- Dicts and lists passed to functions are copy by value.
- Functions do not have access to contextual constant memory like
formandreservation. - All user declared functions are pure.
- All functions must return a value.
- All invocation of functions must assign a value, if you want to throw that away use
_, e.g._ = foo().
none: Nil-value
- Accessed via
None
datetime: Date time object
- Localized to your site timezone.
- Except for comparisons, can only be meaningfully accessed via the
datetimelibrary.
All data types with the exception of functions are passed by value, not by reference. This includes lists and dictionaries!
Casting Types
Values can be cast to other types by using their types and parentheses, e.g. bool(1) == True. If a type can not be cast as a different type, a DSLTypeError exception will be raised.
Type Hints
sneq supports static type checking to help catch errors before your script runs. You can add type hints to variables and function definitions. The static analyzer will verify these types and alert you to mismatches (e.g., assigning a string to an integer variable).
Syntax
- Variables:
name: type = value - Functions:
def name(arg: type = default) -> return_type:
Supported Types
- Primitives:
int,dec,str,bool,none,datetime,function - Generics:
list[type]: A list containing elements of a specific type (e.g.,list[int]).dict[value_type]: A dictionary with a specific value type (e.g.,dict[int]). Dict keys are always strings.
- Callable generics:
function[[param: type, ...], return_type]: A function with typed parameters and return type (e.g.,function[[x: int, y: str], bool]). Plainfunction(without generics) is also valid for opaque function references. - Unions:
type1 | type2: A value that can be one of multiple types (e.g.,int | none). - Any:
any: Disables type checking for a specific variable.
Example Script
# Typed variable assignment
count: int = int(5)
price: dec = 3.23
user_name: str = "Alice"
# Generic types for lists and dicts
scores: list[dec] = [1.5, 2.5, 3.0]
inventory: dict[dec] = {"apples": 10, "oranges": 5}
# Union types (useful for optional values)
result: int | none = None
# Typed function definition
def calculate_total(price: dec = 0.0, tax_rate: dec = 0.13) -> dec:
return price + (price * tax_rate)
# Calling the function
total: dec = calculate_total(price=10.0)
# Callable generics — typed function references
def is_positive(x: dec = 0) -> bool:
return x > 0
check: function[[x: dec], bool] = is_positive