Standard Features
A list of all the standard features that Sprig offers
Most programming languages offer a standard set of functionality - here's a list of Sprig offers:
Variables
Sprig allows you to declare variables in three different ways: const, var and let.
const name = "Amy"
name = "Allan"
// Error: Cannot reassign value of const variable 'name'
const name = "Allan"
// Error: Variable 'name' is already definedvar name = "Amy"
name = "Allan"
// No error, var variables can be reassigned
var name = "Allan"
// Error: Variable 'name' is already definedlet name = "Amy"
name = "Allan"
// No error, let variables can be reassigned
let name = "Allan"
// No error, let variables can be redefinedBranching
Sprig offers a familiar approach to branching logic.
Loops
Sprig offers multiple types of loops: for, loop, while.
for (<List>, [optional] value, [optional] index)
for (<List>, [optional] value, [optional] index)These are the most common loops found in Sprig code.
loop (<let decl>, <end check>, <expr>)
loop (<let decl>, <end check>, <expr>)These follow the traditional for loop approach.
while (<expr>)
while (<expr>)These follow the traditional while loop approach.
Objects
Sprig allows the construction of objects.
Objects can be merged together through addition.
Objects can be constructed using shorthand syntax.
Object properties can be deleted.
Lists
Sprig allows the construction of lists.
Sprig provides common list functionality to the global scope.
Lists can be created dynamically through the range operators.
Lists can be merged by either addition or through the spread operator.
Functional methods are also provided globally.
Functions
Sprig allows you to define your own functions.
Functions can have default parameters.
Functions can have a catch-all parameter. The arguments provided are turned into a List.
When calling functions, we can provide the parameter names to be more verbose.
Functions have an implicit return, meaning they return the last thing on the stack (unless a return is explicitly defined).
Coroutines
Sprig allows you to create coroutines. Coroutines are functions that can suspend their execution, yield a value and resume execution at a later point.
Any function that contains a yield statement is automatically identified as a coroutine.
Last updated