Quick Navigation #

  • Functions - Built-in functions for I/O, iteration, and data transformation
  • Types - Built-in data types (Int, String, Bool, Any)
  • Operators - Arithmetic, comparison, and logical operators
  • Keywords - Language keywords (fn, let, type, match, import)

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 Checks if a string contains a substring.
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.
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.
input Reads a string from the user’s input.
join Joins a list of strings with a separator.
length Returns the length of a string.
map Transforms each element in an iterator using a function, returning a new iterator.
parseInt Parses a string to an integer, returns error if parsing fails.
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.
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!
substring Extracts a substring from start to end index, or returns an error if indices are invalid.
toString Converts a value to its string representation.
websocketClose ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String>. Closes the WebSocket connection and cleans up resources.
websocketConnect ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<WebSocketID, String> and takes string handler instead of function pointer. Establishes a WebSocket connection with a message handler callback.
websocketCreateServer ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<ServerID, String> and has critical runtime issues with port binding failures. Creates a WebSocket server bound to the specified port, address, and path.
websocketKeepAlive ⚠️ SPEC VIOLATION: Current implementation returns int instead of Unit. Keeps the WebSocket server running indefinitely until interrupted (blocking operation).
websocketSend ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String>. Sends a message through the WebSocket connection.
websocketServerBroadcast ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t (number of clients sent to) instead of Result<Success, String>. Broadcasts a message to all connected WebSocket clients.
websocketServerListen ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String> and currently returns -4 (bind failed) due to port binding issues. Starts the WebSocket server listening for connections.
websocketStopServer ⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String>. Stops the WebSocket server and closes all connections.
writeFile Writes content to a file. Creates the file if it doesn’t exist.

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.