Environment Functions¶
RayforceDB provides functions for managing variables and the execution environment. These functions enable variable assignment, scoping, and environment introspection.
Variable Assignment¶
Set¶
Assigns a value to a variable in the global environment or saves data to disk. Can be used to define new variables or update existing variables.
When the first argument is a symbol, sets a global variable.
set creates or updates global variables that persist across the session. For local variables within functions, use let instead.
Let¶
Creates a local variable scoped to the current block or function. The variable is only available within the scope where it's defined.
(set add (fn [a b] (let c (+ a b)) c))
(add 1 2)
3
(set calculate-total (fn [price quantity]
(let total (* price quantity))
(let tax (* total 0.1))
(+ total tax)))
(calculate-total 150.25 100)
16527.50
Unlike set, variables created with let are not accessible outside their defining scope. This is useful for temporary variables within functions or blocks.
let is a special form that restricts variable scope. Use let inside functions to avoid polluting the global environment.
Variable Retrieval¶
Get¶
Retrieves a variable value by symbol or loads a serialized object from disk.
When given a symbol, returns the value of that variable from the environment.
Environment Introspection¶
Env¶
Returns a Dictionary containing all global variables in the current environment.
(set add (fn [a b] (return (+ a b)) 77))
(set a 1)
(set b [1 2 3 4])
(set price 150.25)
(env)
{
add: @add
a: 1
b: [1 2 3 4]
price: 150.25
}
Returns a dictionary mapping variable names (as symbols) to their values.