- Core API
- def def name ¿parameters? body
- return ¿value?
- def global name ¿=? ¿value?
- def local name ¿=? ¿value?
- def include filename
- def import library
- def print *args
- def list *args
- def block ¿levels? body
- def sandbox
- List Type
- Sandbox Type
- $sandbox link component
- $sandbox global name ¿=? ¿value?
- $sandbox eval *args
- Standard Library
- Object Oriented Library
Core API
The core API contains the most basic functionality of the Cutlet interpreter.
def def name ¿parameters? body
Defines a new function in the global environment.
# A function without parameters. def get_number { return 10 } # A function with parameters. def max {value1 value2} { if {$value1 > $value2} then { return $value1 } return $value2 } # Parameter with a default value. def hello {{to_who "me"}} { print "Hello $to_who" } # Variadic parameters to a function. def to_everybody {*args} { print "Hello to [$args join]" }
return ¿value?
This finishes the current stack frame and optionally sets a return value. It’s typically used to return from a function or from the program itself if in the top stack frame.
def concat {val1 val2} { return "$val1 $val2" } # Return from the program with all is fine. return 0
def global name ¿=? ¿value?
Sets the value of a global variable in the current sandbox. If the variable doesn’t exist a new one is created. Also if the value is not give the variable is removed from the current sandbox.
global myvar = "Hello" global myvar "Hello" global myvar
def local name ¿=? ¿value?
Sets the value of a local variable in the current stack frame. If the variable doesn’t exist a new one is created. Also if the value is not give the variable is removed from the current frame.
local myvar = "Hello" local myvar "Hello" local myvar
def include filename
Reads in filename as a script in the current interpreter. If the file doesn’t exist or isn’t a valid Cutlet script an error will be raised.
def import libray
Imports a library found in the given library path list. A library can be a Cutlet script or a native system library.
The global variable $library.path is a list used as the library search path. When a new interpreter is created, it parses the environment variable CUTLET_PATH and adds each entry to the list. Each directory specified in CUTLET_PATH must be separated by a colon, “:”.
CUTLET_PATH="/home/me/libs:/usr/share/dev" cutlet myscript.cutlet
def print *args
Takes all the *args, converts them to text and prints them to the standard output.
print Hello "to" {all my} friends and to $you
def list *args
Creates and returns a new list variable populated from the *args provided.
def block ¿levels? body
def sandbox
Creates and returns a new sandbox.
global my_sandbox = [sandbox] $my_sandbox link print $my_sandbox eval { print "Hello from the sandbox" }
List Type
Sandbox Type
Sandboxes contain the global environment for the interpreter. By using sandboxes
$sandbox link component
$sandbox global name ¿=? ¿value?
$sandbox eval *args
The *args are joined together