Quick Navigation

Function Reference

Function Description
Channel Creates a new channel with the specified capacity.
List Creates a new empty list.
Map Creates a new empty map.
awaitProcess Waits for a spawned process to complete and returns its exit code. Blocks until the process finishes.
cleanupProcess Cleans up resources associated with a completed process. Should be called after awaitProcess.
contains True if needle appears anywhere in s. Empty needle returns true.
drop Returns s without its first n bytes. Clamps; never fails.
endsWith True if s ends with suffix.
fiber_await Waits for a fiber to complete and returns its result.
fiber_spawn Spawns a new fiber to execute the given function concurrently.
fiber_yield Yields control to the fiber scheduler with an optional value.
filter Filters elements in an iterator based on a predicate function.
fold Reduces an iterator to a single value by repeatedly applying a function.
forEach Applies a function to each element in an iterator.
forEachList Apply function to every element of list. Phase 7 of collections plan.
httpCloseClient Closes the HTTP client and cleans up resources.
httpCreateClient Creates an HTTP client for making requests to a base URL.
httpCreateServer Creates an HTTP server bound to the specified port and address.
httpDelete Makes an HTTP DELETE request to the specified path.
httpGet Makes an HTTP GET request to the specified path.
httpListen Starts the HTTP server listening for requests with a handler function.
httpPost Makes an HTTP POST request with a request body.
httpPut Makes an HTTP PUT request with a request body.
httpRequest Makes a generic HTTP request with any method.
httpStopServer Stops the HTTP server and closes all connections.
indexOf Returns byte-index of first occurrence of needle, or Error(NotFound).
input Reads a string from the user's input.
isEmpty True if string has zero length.
join Concatenates parts with separator between each pair.
length Returns the byte length of a string. Total — never fails.
lines Splits on '\n'. A trailing newline does not produce an empty entry.
listAppend Returns a new list with value at the end. O(log32 n) amortised.
listConcat Returns left ++ right. Same as left + right.
listContains True iff some element equals value. O(n).
listLength Returns the number of elements in a list. O(1).
listPrepend Returns a new list with value at the front. O(n).
listReverse Returns a new list in reverse order.
map Transforms each element in an iterator using a function, returning a new iterator.
mapContains True iff key is present in map.
mapKeys All keys of the map as a list. Order unspecified.
mapLength Returns the number of entries in a map. O(1).
mapMerge Right-biased union. Same as left + right.
mapRemove Returns a new map without key. No-op if key is absent.
mapSet Returns a new map with key bound to value (replaces prior binding).
mapValues All values of the map as a list. Order matches mapKeys.
padEnd Pads s on the right with copies of fill to reach targetLength bytes.
padStart Pads s on the left with copies of fill to reach targetLength bytes.
parseFloat Strict base-10 floating-point parser. No whitespace tolerance.
parseInt Strict base-10 signed-int parser. No whitespace tolerance.
print Prints a value to the console. Automatically converts the value to a string representation.
range Creates an iterator that generates numbers from start to end (exclusive).
readFile Reads the entire contents of a file as a string.
recv Receives a value from a channel.
repeat Concatenates s with itself n times. Error(InvalidArgument) on negative n.
replace Replaces every occurrence of needle. Error(InvalidArgument) on empty needle.
reverse Reverses byte order. Grapheme-cluster reversal is future work.
send Sends a value to a channel. Returns 1 for success, 0 for failure.
sleep Pauses execution for the specified number of milliseconds.
spawnProcess Spawns an external async process with MANDATORY callback for stdout/stderr capture. The callback function receives (processID: int, eventType: int, data: string) and is called for stdout (1), stderr (2), and exit (3) events. Returns a handle for the running process. CALLBACK IS REQUIRED - NO FUNCTION OVERLOADING!
split Splits s on separator. Error(InvalidArgument) on empty separator.
startsWith True if s begins with prefix.
substring Extracts s[start, end). Returns Error(IndexOutOfRange) if start<0, end>len, or start>end.
take Returns at most the first n bytes of s. Clamps; never fails.
toLowerCase ASCII-aware lowercase.
toString Converts a value to its string representation.
toUpperCase ASCII-aware uppercase. Unicode simple case mapping is a future addition.
trim Removes leading and trailing whitespace.
trimEnd Removes trailing whitespace.
trimStart Removes leading whitespace.
websocketClose Closes the WebSocket connection and cleans up resources.
websocketConnect Establishes a WebSocket connection with a message handler callback.
websocketCreateServer Creates a WebSocket server bound to the specified port, address, and path.
websocketKeepAlive Keeps the WebSocket server running indefinitely until interrupted (blocking operation).
websocketSend Sends a message through the WebSocket connection.
websocketServerBroadcast Broadcasts a message to all connected WebSocket clients.
websocketServerListen Starts the WebSocket server listening for connections.
websocketStopServer Stops the WebSocket server and closes all connections.
words Splits on runs of whitespace; empty results dropped.
writeFile Writes content to a file. Creates the file if it doesn't exist. Returns number of bytes written.

Type Reference

Type Description
Any A type that can represent any value. Useful for generic programming but should be used carefully as it bypasses type checking.
Bool A boolean type that can be either true or false. Used for logical operations and conditionals.
HttpResponse A built-in type representing an HTTP response with status code, headers, content type, body, and streaming capabilities. Used by HTTP server handlers to return structured responses to clients.
Int A 64-bit signed integer type. Can represent whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
ProcessHandle A handle to a spawned async process. Contains the process ID and allows waiting for completion and cleanup. Process output is delivered via callbacks registered with the runtime.
String A sequence of characters representing text. Supports string interpolation and escape sequences.

Operator Reference

Operator Name Description
!= Inequality Compares two values for inequality.
% Modulo Returns the remainder of dividing the first number by the second.
* Multiplication Multiplies two numbers.
+ Addition Adds two numbers together.
- Subtraction Subtracts the second number from the first.
/ Division Divides the first number by the second.
< Less Than Checks if the first value is less than the second.
<= Less Than or Equal Checks if the first value is less than or equal to the second.
== Equality Compares two values for equality.
> Greater Than Checks if the first value is greater than the second.
>= Greater Than or Equal Checks if the first value is greater than or equal to the second.
[ >](operators/pipe-operator/) Pipe Operator

Keyword Reference

Keyword Description
false Boolean literal representing the logical value false.
fn Function declaration keyword. Used to define functions with parameters and return types.
import Import declaration keyword. Used to bring modules and their exports into the current scope.
let Variable declaration keyword. Used to bind values to identifiers. Variables are immutable by default in Osprey.
match Pattern matching expression. Used for destructuring values and control flow based on patterns.
true Boolean literal representing the logical value true.
type Type declaration keyword. Used to define custom types and type aliases.