Rye Function Reference: Batteries ( Updated: "2026-10-05" )

Browse by source file and section. Examples are generated from builtin tests.

Email

Email Message

Creating and configuring email messages

email-message

Creates a new empty email message object that can be configured with headers, body, and attachments.

(none)

returns native gomail-message object for building email content

msg: email-message
equal { msg |type? } 'native

gomail-message//Set-header

Sets a standard email header field such as Subject, To, From, Cc, or Bcc with the specified value.

Args: 3

message Native gomail-message object

field String or Tagword representing header name (e.g., "Subject", 'to, 'from)

value String or Email containing the header value

returns the message object for method chaining

msg: email-message
msg .Set-header "Subject" "Test Email"
msg .Set-header 'to "user@example.com"
error { msg .Set-header "Subject" 123 }

gomail-message//Set-address-header

Sets an email address header with both email address and display name, commonly used for From, To, Cc, and Bcc fields.

Args: 4

message Native gomail-message object

field String header field name (e.g., "From", "To", "Cc", "Bcc")

address String email address

name String display name for the email address

returns the message object for method chaining

gomail-message//Set-body

Sets the main body content of the email with the specified MIME content type, supporting plain text and HTML formats.

Args: 3

message Native gomail-message object

contentType String MIME content type (e.g., "text/plain", "text/html")

content String containing the email body content

returns the message object for method chaining

gomail-message//Attach

Attaches a file to the email message using a file URI, making the file available as an email attachment.

Args: 2

message Native gomail-message object

file Uri pointing to the file to attach (must use file

returns the message object for method chaining

gomail-message//Add-alternative

Adds alternative content to the email (e.g., HTML version alongside plain text), allowing email clients to choose their preferred format.

Args: 3

message Native gomail-message object

contentType String MIME content type for the alternative content

content String containing the alternative body content

returns the message object for method chaining

new-email-dialer

Creates a new SMTP dialer configured with server details and authentication credentials for sending emails.

Args: 4

server String SMTP server hostname (e.g., "smtp.gmail.com", "mail.example.com")

port Integer SMTP port number (commonly 25, 465, 587, or 2525)

username String username for SMTP authentication

password String password for SMTP authentication

returns native gomail-dialer object configured for sending emails

gomail-dialer//Dial-and-send

Connects to the SMTP server and sends the specified email message, handling authentication and delivery.

Args: 2

dialer Native gomail-dialer object configured with SMTP settings

message Native gomail-message object containing the email to send

returns the dialer object on success, or error object if sending fails

Mail

Mail

Email parsing functions

reader//Parse-email

Parses email data from a reader.

Args: 1

reader native reader object containing email data

returns native parsed-email object

equal { reader %email.eml |parse-email |type? } 'native
equal { reader %email.eml |parse-email |kind? } 'parsed-email

parsed-email//Subject?

Gets the subject from a parsed email.

Args: 1

email native parsed-email object

returns string containing the email subject

equal { reader %email.eml |parse-email |subject? |type? } 'string

parsed-email//Message-id?

Gets the message ID from a parsed email.

Args: 1

email native parsed-email object

returns string containing the email message ID

equal { reader %email.eml |parse-email |message-id? |type? } 'string

parsed-email//Html-body?

Gets the HTML body from a parsed email.

Args: 1

email native parsed-email object

returns string containing the HTML body of the email

equal { reader %email.eml |parse-email |html-body? |type? } 'string

parsed-email//Text-body?

Gets the plain text body from a parsed email.

Args: 1

email native parsed-email object

returns string containing the plain text body of the email

equal { Reader %email.eml |parse-email |text-body? |type? } 'string

parsed-email//Attachments?

Gets the attachments from a parsed email.

Args: 1

email native parsed-email object

returns native object containing email attachments

parsed-email//Embedded-files?

Gets the embedded files from a parsed email.

Args: 1

email native parsed-email object

returns native object containing embedded files from the email

SMTP

SMTP Server Functions

Creating and running SMTP mail servers.

smtp-server

Creates a new SMTP server that can receive incoming email messages on the specified address.

Args: 1

address String containing the server address (e.g., "

returns native smtpd object configured to listen on the specified address

smtp-server ":2525" |kind?
; returns smtpd

smtpd//Serve

Starts the SMTP server listening for incoming emails and calls the handler function for each received message.

Args: 4

server Native smtpd object created by smtp-server

handler Function that processes incoming emails (reader from to origin -> ...)

appname String name for the SMTP server application

password String password for SMTP authentication (empty string for no auth)

returns the server object after starting to listen, or error if unable to serve

handler: fn { reader from to origin } { print "Got email from:" from }
smtp-server ":2525"
|Serve handler "TestSMTP" ""

MQTT

MQTT Client Functions

mqtt-uri//Open

Opens a connection to an MQTT broker.

Args: 1

uri MQTT broker URI (format

returns native MQTT client connection (type: "mqtt-client")error if connection fails

; Connect to MQTT broker and subscribe to topics
client: Open mqtt://localhost:1883/my-client
client .Subscribe "sensors/+" 1 fn { payload msg } {
print "Topic: " + msg -> "topic"
print "Data: " + payload
}

; Publish messages
client .Publish-simple "sensors/temperature" "23.5"
client .Publish "sensors/humidity" "65" 1 0

; Clean up
client .Disconnect


mqtt-client//Disconnect

Disconnects from the MQTT broker.

Args: 1

client MQTT client connection (type

returns integer 1 for successerror if disconnection fails

mqtt-client//Close

Closes the MQTT client connection (alias for Disconnect).

Args: 1

client MQTT client connection (type

returns integer 1 for successerror if close fails

mqtt-client//Publish

Publishes a message to an MQTT topic with specified QoS and retain flag.

Args: 5

client MQTT client connection (type

topic Topic to publish to (string)

payload Message payload (string)

qos Quality of Service level (integer 0, 1, or 2)

retain Whether message should be retained (boolean)

returns integer 1 for successerror if publish fails

mqtt-client//Publish-simple

Publishes a message to an MQTT topic with default settings (QoS 0, no retain).

Args: 3

client MQTT client connection (type

topic Topic to publish to (string)

payload Message payload (string)

returns integer 1 for success (uses QoS 0, no retain)error if publish fails

mqtt-client//Subscribe

Subscribes to an MQTT topic with a message handler function.

Args: 4

client MQTT client connection (type

topic Topic pattern to subscribe to (string, can include wildcards)

qos Quality of Service level (integer 0, 1, or 2)

handler Callback function to handle received messages

returns integer 1 for successerror if subscription fails

mqtt-client//Subscribe-simple

Subscribes to an MQTT topic with default QoS 0 and a message handler function.

Args: 3

client MQTT client connection (type

topic Topic pattern to subscribe to (string)

handler Callback function to handle received messages

returns integer 1 for success (uses QoS 0)error if subscription fails

mqtt-client//Unsubscribe

Unsubscribes from an MQTT topic.

Args: 2

client MQTT client connection (type

topic Topic to unsubscribe from (string)

returns integer 1 for successerror if unsubscription fails

mqtt-client//Is-connected

Checks if the MQTT client is currently connected to the broker.

Args: 1

client MQTT client connection (type

returns integer 1 if connected, 0 if not connected

mqtt-options

Creates a new MQTT client options object for advanced configuration.

returns new MQTT client options object (type: "mqtt-options")

mqtt-options//Set-broker

Sets the MQTT broker address in the options.

Args: 2

options MQTT options object (type

broker Broker URI string

returns the same options object (for method chaining)

mqtt-options//Set-client-id

Sets the client ID in the MQTT options.

Args: 2

options MQTT options object (type

client-id Client identifier string

returns the same options object (for method chaining)

mqtt-options//Set-keep-alive

Sets the keep alive interval in seconds.

Args: 2

options MQTT options object (type

seconds Keep alive interval in seconds (integer)

returns the same options object (for method chaining)

mqtt-options//Set-username

Sets the username for MQTT authentication.

Args: 2

options MQTT options object (type

username Username string for MQTT authentication

returns the same options object (for method chaining)

mqtt-options//Set-password

Sets the password for MQTT authentication.

Args: 2

options MQTT options object (type

password Password string for MQTT authentication

returns the same options object (for method chaining)

mqtt-options//Set-will

Sets the Last Will and Testament message with QoS and retain flag.

Args: 5

options MQTT options object (type

topic Will topic string

payload Will message payload string

qos Quality of Service level for will message (integer 0, 1, or 2)

retain Whether will message should be retained (integer 0 = false, 1 = true)

returns the same options object (for method chaining)

mqtt-options//Connect-with-options

Creates and connects an MQTT client using the configured options.

Args: 1

options MQTT options object (type

returns native MQTT client connection (type: "mqtt-client")error if connection fails

Regexp

Regexp

Go like Regular expressions

regexp

Creates a compiled regular expression object from a pattern string.

Args: 1

pattern String containing a regular expression pattern

returns native regexp object or error if pattern is invalid

regexp "[0-9]" |kind?
; returns regexp

re

Creates a compiled regular expression object from a pattern string.

Args: 1

pattern String containing a regular expression pattern

returns native regexp object or error if pattern is invalid

re "[0-9]" |kind?
; returns regexp

regexp//Is-match

Tests if a string matches the regular expression pattern.

Args: 2

regexp Native regexp object

input String to test against the pattern

returns boolean true if the string matches the pattern, false otherwise

regexp "[0-9]" |Is-match "5"
; returns true
regexp "[0-9]" |Is-match "a"
; returns false

regexp//Submatch?

Extracts the first captured group from a string using the regular expression.

Args: 2

regexp Regular expression with capturing groups

input String to search in

returns string containing the first captured group or error if no submatch found

regexp "x([0-9]+)y" |Submatch? "x123y"
; returns "123"

regexp//Submatches?

Extracts all captured groups from the first match as a block of strings.

Args: 2

regexp Regular expression with capturing groups

input String to search in

returns block containing all captured groups from the first match or error if no match found

regexp "x([0-9]+)y" |Submatches? "x123y x234y"
; returns { "123" }

regexp//Submatches\all?

Extracts all captured groups from all matches as a nested block structure.

Args: 2

regexp Regular expression with capturing groups

input String to search in

returns block of blocks, each inner block containing the captured groups from one match

regexp "x([0-9]+)(y+)?" |Submatches\all? "x11yy x22"
; returns { { "11" "yy" } { "22" "" } }

regexp//Find-all

Finds all substrings matching the regular expression and returns them as a block.

Args: 2

regexp Regular expression pattern

input String to search in

returns block containing all matching substrings or error if no matches found

regexp "[0-9]+" |Find-all "x123y x234y"
; returns { "123" "234" }

regexp//Match?

Finds the first substring matching the regular expression.

Args: 2

regexp Regular expression pattern

input String to search in

returns string containing the first match or empty string if no match found

regexp "[0-9]+c+" |Match? "aa33bb55cc"
; returns "55cc"

regexp//Replace-all

Replaces all occurrences of the regular expression pattern with the specified replacement string.

Args: 3

regexp Regular expression pattern

input String to modify

replacement String to replace matches with

returns string with all matches replaced by the replacement string

regexp "[0-9]+" |Replace-all "x123y x234y" "XXX"
; returns "xXXXy xXXXy"

JSON

JSON

Parsing and generating JSON

parse-json

Parses JSON string into Rye values.

Args: 1

json string containing JSON data

returns parsed Rye value (list, dict, string, integer, etc.)

"[ 1, 2, 3 ]" |parse-json |length?
; returns 3
"{"name": "John", "age": 30}" |parse-json -> "name"
; returns "John"

parse-json\lines

Parses JSON string into Rye values.

Args: 1

json string containing consecutive JSON values

returns list of parsed Rye values

"{"a": 2, "b": "x"} 
{"a": 3, "b": "y"} 
" |parse-json\lines |to-table
; returns table { "a" "b" } [ 2 "x" 3 "y" ]

to-json

Converts a Rye value to a JSON string. Supports block (like list) and context (like dict).

Args: 1

value any Rye value to encode (block, list, dict, context, string, integer, etc.)

returns string containing the JSON representation

dict { a: 1 b: 2 c: 3 } |to-json |parse-json |-> "b"
; returns 2
context { a: 1 b: 2 } |to-json |parse-json |-> "a"
; returns 1
true |to-json
; returns "true"
false |to-json
; returns "false"

to-json\lines

Converts a table to JSON with each row on a separate line.

Args: 1

table table value to encode

returns string containing the JSON representation with each row on a new line

BSON

BSON

BSON encoding and decoding

from-bson

Decodes BSON data into Rye values.

Args: 1

bytes native bytes object containing BSON data

returns decoded Rye value (string, integer, decimal, block, etc.)

"abc" |to-bson |from-bson
; returns "abc"
123 |to-bson |from-bson
; returns 123
{ 123 "asd" } |to-bson |from-bson
; returns { 123 "asd" }

to-bson

Encodes a Rye value into BSON format.

Args: 1

value any Rye value to encode (string, integer, decimal, block, etc.)

returns native bytes object containing the BSON-encoded data

SXML

SXML

Streaming, SAX-like XML processing

reader//Do-sxml

Processes XML using a streaming SAX-like approach with tag handlers.

Args: 2

reader XML reader object

block SXML processing block with tag handlers

returns result of processing the XML

"<scene><bot>C3PO</bot><bot>R2D2</bot><jedi>Luke</jedi></scene>" |reader |Do-sxml { bot { _ [ .prns ] } }
; prints "C3PO R2D2 "
"<scene><ship>XWing</ship><bot>R2D2</bot><jedi>Luke</jedi></scene>" |reader |Do-sxml { bot jedi { _ [ .prns ] } }
; prints "R2D2 Luke "
"<scene><xwing><bot>R2D2</bot><person>Luke</person></xwing><destroyer><person>Vader</person></destroyer></scene>" |reader |Do-sxml { xwing { person { _ [ .prns ] } } }
; prints "Luke "

rye-sxml-start//Attr?

Retrieves an attribute by index or name from an XML start element.

Args: 2

element XML start element

index Integer index of the Attribute to retrieve

returns list [ namespace tag value ] of the attribute or void if not found

rye-sxml-start//Attrs?

Returns a dict of all attributes from an XML start element.

Args: 1

element XML start element

returns dict with all attributes where keys are "attrname" or "namespace:attrname"

rye-sxml-start//Name?

Returns the name of an XML start element.

Args: 1

element XML start element

returns string name of the XML element

HTML

HTML

HTML processing functions

unescape\html

Converts HTML entities to their character equivalents.

Args: 1

text HTML-escaped string

returns string with HTML entities converted to their character equivalents

unescape\html "&gt;hello&lt;"
; returns ">hello<"

escape\html

Converts special characters to HTML entities.

Args: 1

text String containing HTML special characters

returns string with special characters converted to HTML entities

escape\html "<hello>"
; returns "&lt;hello&gt;"

html->markdown

Converts HTML text to markdown format.

Args: 1

html HTML string to convert

returns string containing markdown equivalent of the HTML

html->markdown "<h1>title</h1><p>para</p>"
; returns "# title
; 
; para"

reader//Parse-html

Parses HTML using a streaming approach with tag handlers.

Args: 2

reader HTML reader object

block HTML processing block with tag handlers

returns result of processing the HTML

rye-html-start//Attr?

Retrieves an attribute value by name or index from an HTML element.

Args: 2

element HTML token element

name-or-index Attribute name (as word or string) or index (as integer)

returns string value of the attribute or void if not found

rye-html-start//Attrs?

Returns a dict of all attributes from an HTML element.

Args: 1

element HTML token element

returns dict with all attributes where keys are attribute names

rye-html-start//Name?

Returns the name of an HTML element.

Args: 1

element HTML token element

returns string name of the HTML element

Markdown

Markdown

Functions for processing and converting Markdown documents

reader//do-markdown

Processes Markdown using a streaming approach with section handlers.

Args: 2

reader File reader or similar object to read markdown from

handlers Block containing section handlers (h1, h2, paragraph, code, etc.)

returns the result of processing the markdown document

markdown->html

Converts Markdown text to HTML.

Args: 1

text Markdown source string

returns string containing HTML

markdown->html "# Title" |contains "<h"
; returns true

markdown

Creates a Markdown value from a string.

Args: 1

text String or Markdown value

returns Markdown value

text

Gets the raw markdown text from a Markdown value.

Args: 1

md Markdown value

returns raw markdown text as string

markdown "Hello" |text
; returns "Hello"

to-html

Converts a Markdown value to HTML.

Args: 1

md Markdown value

returns string containing HTML

markdown "# T" |to-html |contains "<h"
; returns true

headings

Extracts all headings from markdown text as a list of strings.

Args: 1

md Markdown value

returns list of strings with headings

paragraphs

Extracts all paragraphs from markdown text as a list of strings.

Args: 1

md Markdown value

returns list of strings with paragraphs

links

Extracts all links from markdown text as a list of dictionaries with 'text' and 'url' keys.

Args: 1

md Markdown value

returns list of dicts with 'text and 'url keys

Conversion

Conversion

Functions for converting between different types and kinds

convert

Converts value from one kind to another based on a conversion specification block.

Args: 2

value Dict or RyeCtx to convert

spec Block specifying the conversion rules

returns converted value based on the specification

converter

Registers a converter between two kinds of objects.

Args: 3

source-kind Kind to convert from

target-kind Kind to convert to

spec Block specifying conversion rules

returns the target kind with the converter registered

Encoding

Default

decode\hex-string

Decodes a hexadecimal string to a UTF-8 string.

Args: 1

pure

hex-string hexadecimal string to decode

returns string containing the decoded bytes as a UTF-8 string

"48656c6c6f20576f726c64" |decode\hex-string
; returns "Hello World"

encode\hex-string

Encodes a string to its hexadecimal representation.

Args: 1

pure

string string to encode

returns hexadecimal string representation

"Hello World" |encode\hex-string
; returns "48656c6c6f20576f726c64"
"" |encode\hex-string
; returns ""

clean\hex-string

Removes all whitespace from a hex string and ensures even length.

Args: 1

pure

hex-string raw hex string with possible whitespace

returns cleaned hex string with whitespace removed and even length

"  70 44 01 4b  
  55 50 4e 51  " |clean\hex-string
; returns "7044014b55504e51"
"70 44 01 4b	55 50 4e 51
52 0a" |clean\hex-string
; returns "7044014b55504e51520a"
"7044014b55504e51520a" |clean\hex-string
; returns "7044014b55504e51520a"

charmap\windows-1250

Returns the Windows-1250 (CP1250) character encoding for Central European languages.

pure

no arguments

returns Windows-1250 encoding as a native value

charmap\windows-1250 |kind?
; returns charmap-encoding

charmap\iso-8859-1

Returns the ISO-8859-1 (Latin-1) character encoding.

pure

no arguments

returns ISO-8859-1 encoding as a native value

charmap\iso-8859-1 |kind?
; returns charmap-encoding

charmap\iso-8859-2

Returns the ISO-8859-2 (Latin-2) character encoding for Central European languages.

pure

no arguments

returns ISO-8859-2 encoding as a native value

charmap\iso-8859-2 |kind?
; returns charmap-encoding

charmap\windows-1252

Returns the Windows-1252 character encoding for Western European languages.

pure

no arguments

returns Windows-1252 encoding as a native value

charmap\windows-1252 |kind?
; returns charmap-encoding

charmap\code-page-437

Returns the Code Page 437 (DOS/IBM PC) character encoding.

pure

no arguments

returns Code Page 437 encoding as a native value

charmap\code-page-437 |kind?
; returns charmap-encoding

charmap\code-page-850

Returns the Code Page 850 (DOS Latin-1) character encoding.

pure

no arguments

returns Code Page 850 encoding as a native value

charmap\code-page-850 |kind?
; returns charmap-encoding

charmap\koi8r

Returns the KOI8-R character encoding for Russian.

pure

no arguments

returns KOI8-R encoding as a native value

charmap\koi8r |kind?
; returns charmap-encoding

charmap-encoding//Decoder

Creates a new text decoder for the given character encoding.

Args: 1

pure

encoding charmap encoding as a native value

returns text decoder as a native value

charmap\windows-1250 |Decoder |kind?
; returns text-decoder

charmap-encoding//Encoder

Creates a new text encoder for the given character encoding.

Args: 1

pure

encoding charmap encoding as a native value

returns text encoder as a native value

charmap\windows-1250 |Encoder |kind?
; returns text-encoder

text-decoder//Decode

Decodes a string using the given text decoder.

Args: 2

pure

decoder text decoder as a native value

input string to decode

returns decoded string

charmap\windows-1250 |Decoder |Decode "Hello"
; returns "Hello"
charmap\windows-1250 |Decoder |Decode ""
; returns ""

text-encoder//Encode

Encodes a string using the given text encoder.

Args: 2

pure

encoder text encoder as a native value

input string to encode

returns encoded string

charmap\windows-1250 |Encoder |Encode "Hello"
; returns "Hello"
charmap\windows-1250 |Encoder |Encode "Plačilo" |encode\hex-string
; returns "506c61e8696c6f"

is-space

Checks if a single character string is a whitespace character.

Args: 1

pure

input string to check (should be single character)

returns boolean true if character is whitespace, false otherwise

" " |is-space
; returns true
"	" |is-space
; returns true
"
" |is-space
; returns true
"
" |is-space
; returns true
"a" |is-space
; returns false
"A" |is-space
; returns false
"1" |is-space
; returns false

remove-all-space

Removes all whitespace characters from a string.

Args: 1

pure

input string to process

returns string with all whitespace characters removed

"Hello World" |remove-all-space
; returns "HelloWorld"
"  Hello  World  " |remove-all-space
; returns "HelloWorld"
"	
 Hello 
 World 	" |remove-all-space
; returns "HelloWorld"
"" |remove-all-space
; returns ""

SQLite

SQLite

SQLite database functions

sqlite-uri//Open

Opens a connection to a SQLite database file.

Args: 1

uri path to SQLite database file

returns native SQLite database connection

db: Open sqlite://mydata.db
db .Exec "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)"
db .Exec { INSERT INTO users ( name , age ) VALUES ( "Alice" , 30 ) }
db .Query { SELECT * FROM users WHERE age > 25 } |print
name: "Bob"
db .Exec { INSERT INTO users ( name , age ) VALUES ( ?name , 42 ) }


htmlize

Converts a table to HTML format.

Args: 1

table table to convert to HTML

returns string containing HTML representation of the table

Rye-sqlite//Exec

Executes a SQL statement that doesn't return rows.

Args: 2

db SQLite database connection

sql SQL statement as string or block

returns database connection

Rye-sqlite//Query

Executes a SQL query and returns results as a table.

Args: 2

db SQLite database connection

sql SQL query as string, SQL-DSL block, or a block where first value is SQL string and the rest are parameters

returns table containing query results

Rye-sqlite//Show-SQL

Generates and returns the SQL string without executing it.

Args: 2

db SQLite database connection

sql SQL query as string or block

returns string containing the generated SQL with parameters

Rye-sqlite//Close

Closes the SQLite database connection.

Args: 1

db SQLite database connection

returns integer 1 on successful close, error otherwise

PostgreSQL

PostgreSQL

postgres-uri//Open

Opens a connection to a PostgreSQL database.

Args: 1

uri PostgreSQL connection string URI (format

returns native PostgreSQL database connection (type: "Rye-psql")error if connection fails

Rye-psql//Exec

Executes a SQL statement that modifies data (INSERT, UPDATE, DELETE).

Args: 2

db PostgreSQL database connection (type

sql SQL statement as string or block (for data modification

returns integer number of rows affectederror if execution fails

Open postgres://user:pass@localhost:5432/dbname
|Exec { INSERT INTO test VALUES ( 1 , "test" ) }
; mind the mandatory spacing in SQL dialect

Rye-psql//Query

Executes a SQL query and returns results as a table.

Args: 2

db PostgreSQL database connection (type

sql SQL query as string or block (SELECT statements)

returns table containing query results (SQL NULL values converted to Void{})error if query fails or returns no data

db: Open postgres://user:pass@localhost:5432/dbname
db .Query "SELECT * FROM test"

Rye-psql//Show-SQL

Generates and returns the SQL string without executing it.

Args: 2

db PostgreSQL database connection (type

sql SQL query as string or block (for debugging/inspection)

returns string containing the generated SQL with parameters (includes parameter comments if present)error if SQL is empty

name: "Bob"
Open postgres://user:pass@localhost:5432/dbname
|Show-SQL {  SELECT * FROM users WHERE first_name = ?name}

Rye-psql//Close

Closes the PostgreSQL database connection.

Args: 1

db PostgreSQL database connection

returns integer 1 on successful close, error otherwise

MySQL

MySQL

MySQL database functions

mysql-uri//Open

Opens a connection to a MySQL database.

Args: 1

uri MySQL connection string URI

returns native MySQL database connection

Open mysql://user:pass@tcp(localhost)/dbname

mysql-uri//Open\pwd

Opens a connection to a MySQL database with separate password parameter.

Args: 2

uri MySQL connection string URI without password

password Password for the database connection

returns native MySQL database connection

equal { Open\pwd mysql://user@tcp(localhost:3306)/dbname" "password"

Rye-mysql//Exec

Executes a SQL statement that modifies data (INSERT, UPDATE, DELETE).

Args: 2

db MySQL database connection

sql SQL statement as string or block

returns integer 1 if rows were affected, error otherwise

Open mysql://user:pass@tcp(localhost:3306)/dbname" ,
|Exec { INSERT INTO test VALUES ( 1 , "test" ) }

Rye-mysql//Query

Executes a SQL query and returns results as a table.

Args: 2

db MySQL database connection

sql SQL query as string or block

returns table containing query results

id: 101
db: Open mysql://user:pass@tcp(localhost:3306)/dbname
db .Query { SELECT * FROM test where id = ?id }

Rye-mysql//Close

Closes the MySQL database connection.

Args: 1

db MySQL database connection

returns integer 1 on successful close, error otherwise

equal { db: Open mysql://user:pass@tcp(localhost:3306)/dbname db .Close |type? } 'integer

Crypto

Basic Cryptographic Operations

Hashing, encoding, and basic cryptographic functions

decode\hex

Decodes a hexadecimal string to a bytes native value.

Args: 1

hex-string hexadecimal encoded string to decode

returns native bytes object containing the decoded data

encode-to\hex

Encodes a bytes native value to a hexadecimal string.

Args: 1

bytes native bytes object to encode

returns string containing the hexadecimal representation of the bytes

cc crypto "48656c6c6f20776f726c64" |decode\hex |encode-to\hex
; returns "48656c6c6f20776f726c64"

Ed25519-pub-key//To-string

Converts an Ed25519 public key to its hexadecimal string representation.

Args: 1

key Ed25519 public key as a native value

returns string containing the hexadecimal representation of the public key

Ed25519-priv-key//To-string

Converts an Ed25519 private key to its hexadecimal string representation.

Args: 1

key Ed25519 private key as a native value

returns string containing the hexadecimal representation of the private key

ed25519-generate-keys

Generates a new Ed25519 key pair and returns them in a block with public key first, then private key.

no arguments

returns block containing [public-key, private-key] as native values

cc crypto ed25519-generate-keys |length?
; returns 2
cc crypto ed25519-generate-keys |first |kind?
; returns Ed25519-pub-key
cc crypto ed25519-generate-keys |second |kind?
; returns Ed25519-priv-key

ed25519-private-key

Creates an Ed25519 private key from a hexadecimal string or bytes value.

Args: 1

key-data string containing hexadecimal representation of the key or bytes native value

returns Ed25519 private key as a native value

ed25519-public-key

Creates an Ed25519 public key from a hexadecimal string or bytes value.

Args: 1

key-data string containing hexadecimal representation of the key or bytes native value

returns Ed25519 public key as a native value

Ed25519-priv-key//Sign

Signs a string message with an Ed25519 private key and returns the signature as bytes.

Args: 2

key Ed25519 private key as a native value

message string to sign

returns signature as a native bytes value

sha512

Calculates the SHA-512 hash of a string and returns the result as a hexadecimal string.

Args: 1

input string to hash

returns string containing the hexadecimal representation of the SHA-512 hash

cc crypto "Hello world" |sha512 |length?
; returns 128
cc crypto "" |sha512
; returns "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"

Age

Age encryption/decryption and key generation

age-generate-keys

Generates a new age key pair (identity and recipient).

cc crypto age-generate-keys |first |kind?
; returns age-identity
cc crypto age-generate-keys |second |kind?
; returns age-recipient

age-identity

Creates an age identity from a string or bytes.

Args: 1

cc crypto age-identity "AGE-SECRET-KEY-1UMNMNLE5ADV4V0X8LRMG4GVWM3WJ7GVH6JP3J2XSRDFENLJVVX4SDLWXML" |kind?
; returns age-identity

age-recipient

Creates an age recipient from a string or bytes.

Args: 1

cc crypto age-recipient "age1zwya0qq8c824n5ncxppekrm4egk6gnvfhag6dmr87xjqaeuwlsgq68mqj4" |kind?
; returns age-recipient

age-encrypt

Encrypts a reader with age for the provided age recipient or string password and returns a reader.

Args: 2

cc crypto age-generate-keys |set { identity recipient } "SUPER SECRET" |reader |age-encrypt recipient |age-decrypt identity |Read\string
; returns "SUPER SECRET"
cc crypto "SUPER SECRET" |reader |age-encrypt "password" |age-decrypt "password" |Read\string
; returns "SUPER SECRET"

age-decrypt

Decrypts a reader with age using the provided age identity or string password and returns a reader with the decrypted content.

Args: 2

reader encrypted data as a reader native value

identity-or-password age identity native value or password string

returns decrypted data as a reader native value

cc crypto age-generate-keys |set { identity recipient } "SUPER SECRET" |reader |age-encrypt recipient |age-decrypt identity |Read\string
; returns "SUPER SECRET"
cc crypto "SUPER SECRET" |reader |age-encrypt "password" |age-decrypt "password" |Read\string
; returns "SUPER SECRET"

pkcs12-to-pem

Converts a PKCS#12 (.p12) file bytes to PEM blocks using the provided password. Returns a block of pem-block native values.

Args: 2

p12-data PKCS#12 file content as bytes native value

password string password for the PKCS#12 file

returns block containing PEM blocks as native values

pkcs12-decode

Decodes a PKCS#12 (.p12) file bytes into private key and certificates using the provided password. Returns a block with [private-key, certificates, ca-certificates].

Args: 2

p12-data PKCS#12 file content as bytes native value

password string password for the PKCS#12 file

returns block containing [private-key, certificates-block, ca-certificates-block] as native values

PEM Operations

PEM format encoding and decoding operations

pem-block//Block-type?

Returns the type of a PEM block as a string (e.g., 'CERTIFICATE', 'RSA PRIVATE KEY').

Args: 1

pem-block PEM block as a native value

returns string containing the block type (e.g., "CERTIFICATE", "RSA PRIVATE KEY")

pem-block//Headers?

Returns the headers of a PEM block as a dictionary.

Args: 1

pem-block PEM block as a native value

returns dictionary containing the PEM block headers

x509-parse-certificate

Parses a PEM block into an X.509 certificate native value.

Args: 1

pem-block PEM block as a native value containing a certificate

returns X.509 certificate as a native value

x509-certificate//Not-after?

Returns the expiration date (NotAfter) of an X.509 certificate as a time value.

Args: 1

certificate X.509 certificate as a native value

returns time value representing the certificate's expiration date

x509-certificate//Not-before?

Returns the start date (NotBefore) of an X.509 certificate as a time value.

Args: 1

certificate X.509 certificate as a native value

returns time value representing the certificate's start date

x509-certificate//Is-expired

Checks if an X.509 certificate has expired. Returns 1 if expired, 0 otherwise.

Args: 1

certificate X.509 certificate as a native value

returns integer 1 if the certificate has expired, 0 otherwise

generate-self-signed-certificate

Generates a self-signed X.509 certificate with a new RSA key pair.

Args: 2

key-size integer, must be at least 2048 bits

subject dictionary with fields like "CommonName" and "Organization"

returns block containing [certificate, private-key] as native values

encode-to-pem

Encodes a certificate and private key as PEM-formatted data.

Args: 2

certificate X.509 certificate as a native value

private-key RSA private key as a native value

returns block with [cert-bytes, key-bytes] as Go-bytes native values

encode-to-p12

Encodes a certificate and private key into a PKCS#12 (.p12) file with password protection.

Args: 3

certificate X.509 certificate as a native value

private-key RSA private key as a native value

password string password to protect the PKCS#12 file

returns PKCS#12 encoded data as Go-bytes native value

x509-certificate//Subject?

Returns the subject Distinguished Name (DN) of an X.509 certificate as a string.

Args: 1

certificate X.509 certificate as a native value

returns string containing the certificate's subject DN

x509-certificate//Issuer?

Returns the issuer Distinguished Name (DN) of an X.509 certificate as a string.

Args: 1

certificate X.509 certificate as a native value

returns string containing the certificate's issuer DN

x509-certificate//Serial-number?

Returns the serial number of an X.509 certificate as a string.

Args: 1

certificate X.509 certificate as a native value

returns string containing the certificate's serial number

x509-certificate//Signature-algorithm?

Returns the signature algorithm of an X.509 certificate as a string.

Args: 1

certificate X.509 certificate as a native value

returns string containing the certificate's signature algorithm

x509-certificate//Public-key-algorithm?

Returns the public key algorithm of an X.509 certificate as a string.

Args: 1

certificate X.509 certificate as a native value

returns string containing the certificate's public key algorithm

x509-certificate//Key-usage?

Returns the key usage flags of an X.509 certificate as a block of strings.

Args: 1

certificate X.509 certificate as a native value

returns block containing strings of key usage flags

x509-certificate//Extended-key-usage?

Returns the extended key usage flags of an X.509 certificate as a block of strings.

Args: 1

certificate X.509 certificate as a native value

returns block containing strings of extended key usage flags

x509-certificate//Dns-names?

Returns the DNS names from Subject Alternative Names of an X.509 certificate as a block of strings.

Args: 1

certificate X.509 certificate as a native value

returns block containing DNS names from Subject Alternative Names

x509-certificate//Ip-addresses?

Returns the IP addresses from Subject Alternative Names of an X.509 certificate as a block of strings.

Args: 1

certificate X.509 certificate as a native value

returns block containing IP addresses from Subject Alternative Names

x509-certificate//Email-addresses?

Returns the email addresses from Subject Alternative Names of an X.509 certificate as a block of strings.

Args: 1

certificate X.509 certificate as a native value

returns block containing email addresses from Subject Alternative Names

x509-certificate//To-pem

Converts an X.509 certificate to PEM-encoded string format.

Args: 1

certificate X.509 certificate as a native value

returns string containing the PEM-encoded certificate

private-key//Type?

Returns the type of a private key as a string.

Args: 1

private-key private key as a native value

returns string containing the type of the private key (e.g., "*rsa.PrivateKey", "*ecdsa.PrivateKey")

x509-certificate//To-dict

Converts an X.509 certificate to a dictionary containing all certificate information for easy display and manipulation.

Args: 1

certificate X.509 certificate as a native value

returns dictionary containing all certificate information

Bcrypt

Bcrypt

Functions for bcrypt password hashing and token generation

bcrypt-hash

Generates a bcrypt hash from a password string.

Args: 1

password String to hash

password String to hash

returns string containing the bcrypt hash of the passwordstring containing the bcrypt hash of the password

bcrypt-check

Compares a bcrypt hash with a plain text password.

Args: 2

hash String containing the bcrypt hash

password Plain text password to compare

hash String containing the bcrypt hash

password Plain text password to compare

returns integer 1 if the password matches the hash, 0 otherwiseinteger 1 if the password matches the hash, 0 otherwise

bcrypt-check "$2a$10$N9qo8uLOickgx2ZMRZo4e.PFTlCOKQOLawQy5AdYyZuG7JC2rA9e." "wrong"
; returns 0

generate-token

Generates a cryptographically secure random token of the specified length in bytes.

Args: 1

length Integer number of random bytes to generate

length Integer number of random bytes to generate

returns string containing the hex-encoded random tokenstring containing the hex-encoded random token

generate-token 4 |length?
; returns 8

Math

Math context and dialect

Mathematical context and dialect (calc)

mod

Returns the remainder of dividing x by y.

Args: 2

x integer or decimal value

y integer or decimal value

returns decimal remainder of x/y

mod 10 3
; returns 1

pow

Returns base raised to the power of exponent.

Args: 2

base integer, decimal, or complex value

exponent integer, decimal, or complex value

returns decimal result of base raised to the power of exponent for integer/decimal inputs, complex result for complex inputs

pow 2 3
; returns 8
pow complex 2 0 complex 3 0 |prn
; prints "8.000000+0.000000i"
pow complex 0 1 complex 2 0 |prn
; prints "-1.000000+0.000000i"

log2

Returns the binary logarithm (base-2) of x.

Args: 1

x integer or decimal value

returns decimal binary logarithm of x

log2 8
; returns 3
log2 1
; returns 0

log10

Returns the decimal logarithm (base-10) of x.

Args: 1

x integer or decimal value

returns decimal base-10 logarithm of x

log10 100
; returns 2

log

Returns the natural logarithm of x.

Args: 1

x integer, decimal, complex, vector or matrix value

returns natural logarithm of x (element-wise for vector/matrix)

log 1
; returns 0
log 2.718281828459045
; returns 1
log complex 1 0 |prn
; prints "0.000000+0.000000i"
log complex 2.718281828459045 0 |prn
; prints "1.000000+0.000000i"
log vector { 1 2.718281828459045 } |vec-to-block |first
; returns 0
log matrix { 1 2 } { 1 2.718281828459045 } |mat-get 0 0
; returns 0

log1p

Returns the natural logarithm of 1 plus its argument x.

Args: 1

x integer or decimal value

returns decimal natural logarithm of (1 + x)

log1p 0
; returns 0

logb

Returns the binary exponent of x.

Args: 1

x integer or decimal value

returns decimal binary exponent of x

logb 8
; returns 3

sq

Returns the square of x.

Args: 1

x integer or decimal value

returns decimal square of x

sq 4
; returns 16
sq -3
; returns 9

sin

Returns the sine of the radian argument.

Args: 1

x integer, decimal, or complex value in radians

returns decimal sine of x for integer/decimal input, complex sine for complex input

sin 0
; returns 0
round\to sin pi 10
; returns 0
sin complex 0 0 |prn
; prints "0.000000+0.000000i"
sin complex 1.570796326794897 0 |prn
; prints "1.000000+-0.000000i"

cos

Returns the cosine of the radian argument.

Args: 1

x integer, decimal, or complex value in radians

returns decimal cosine of x for integer/decimal input, complex cosine for complex input

cos 0
; returns 1
cos complex 0 0 |prn
; prints "1.000000+-0.000000i"
cos complex 3.141592653589793 0 |prn
; prints "-1.000000+-0.000000i"

tan

Returns the tangent of the radian argument.

Args: 1

x integer, decimal, or complex value in radians

returns decimal tangent of x for integer/decimal input, complex tangent for complex input

tan 0
; returns 0
tan complex 0 0 |prn
; prints "0.000000+0.000000i"
tan complex 0.7853981633974483 0 |prn
; prints "1.000000+0.000000i"

sqrt

Returns the square root of x.

Args: 1

x integer, decimal, complex, vector or matrix value

returns square root of x (element-wise for vector/matrix)

sqrt 9
; returns 3
sqrt 2 |round\to 4
; returns 1.4142
sqrt complex -1 0 |prn
; prints "0.000000+1.000000i"
sqrt vector { 4 9 16 } |vec-to-block |first
; returns 2
sqrt matrix { 2 2 } { 4 9 16 25 } |mat-get 1 1
; returns 5

abs

Returns the absolute value of a number.

Args: 1

x integer, decimal, complex, vector or matrix value

returns absolute value of x (element-wise for vector/matrix)

abs -5
; returns 5
abs 5
; returns 5
abs complex 3 4
; returns 5
abs vector { -1 2 -3 } |vec-to-block |first
; returns 1
abs matrix { 2 2 } { -1 2 -3 4 } |mat-get 1 0
; returns 3

acos

Returns the arccosine (inverse cosine) in radians.

Args: 1

x integer or decimal value between -1 and 1

returns decimal arccosine of x in radians

acos 1
; returns 0

acosh

Returns the inverse hyperbolic cosine.

Args: 1

x integer or decimal value >= 1

returns decimal inverse hyperbolic cosine of x

acosh 1
; returns 0

asin

Returns the arcsine (inverse sine) in radians.

Args: 1

x integer or decimal value between -1 and 1

returns decimal arcsine of x in radians

asin 0
; returns 0

asinh

Returns the inverse hyperbolic sine.

Args: 1

x integer or decimal value

returns decimal inverse hyperbolic sine of x

asinh 0
; returns 0

atan

Returns the arctangent (inverse tangent) in radians.

Args: 1

x integer or decimal value

returns decimal arctangent of x in radians

atan 0
; returns 0

atan2

Returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.

Args: 2

y integer or decimal value

x integer or decimal value

returns decimal arctangent of y/x in radians, using signs to determine quadrant

atan2 0 1
; returns 0

atanh

Returns the inverse hyperbolic tangent.

Args: 1

x integer or decimal value between -1 and 1

returns decimal inverse hyperbolic tangent of x

atanh 0
; returns 0

ceil

Returns the least integer value greater than or equal to x.

Args: 1

x integer or decimal value

returns decimal ceiling of x (smallest integer >= x)

ceil 3.1
; returns 4

cbrt

Returns the cube root of x.

Args: 1

x integer or decimal value

returns decimal cube root of x

cbrt 8
; returns 2

copysign

Returns a value with the magnitude of x and the sign of y.

Args: 2

x integer or decimal value

y integer or decimal value

returns decimal with magnitude of x and sign of y

copysign 1 -2
; returns -1

dim

Returns the maximum of x-y or 0.

Args: 2

x integer or decimal value

y integer or decimal value

returns decimal max(x-y, 0)

dim 5 3
; returns 2
dim 3 5
; returns 0

round\to

Rounds a decimal to the specified number of decimal places.

Args: 2

x decimal value to round

digits integer number of decimal places to round to

returns decimal rounded to specified number of decimal places

round\to 3.14159 2
; returns 3.14
round\to 2.71828 3
; returns 2.718

round

Rounds a decimal to the nearest integer.

Args: 1

x decimal value

returns decimal rounded to nearest integer

round 3.7
; returns 4
round 3.2
; returns 3

roundtoeven

Returns the nearest integer, rounding ties to even.

Args: 1

x integer or decimal value

returns decimal rounded to nearest integer, with ties rounded to even

roundtoeven 3.5
; returns 4
roundtoeven 2.5
; returns 2

erf

Returns the error function of value.

Args: 1

x integer or decimal value

returns decimal error function value of x

erf 0
; returns 0

erfc

Returns the complementary error function of value.

Args: 1

x integer or decimal value

returns decimal complementary error function value of x

erfc 0
; returns 1

erfcinv

Returns the inverse of erfc(x) function.

Args: 1

x integer or decimal value between 0 and 2

returns decimal inverse complementary error function value of x

erfcinv 1
; returns 0

erfinv

Returns the inverse error function of value.

Args: 1

x integer or decimal value between -1 and 1

returns decimal inverse error function value of x

erfinv 0
; returns 0

exp

Returns e**x, the base-e exponential of x.

Args: 1

x integer, decimal, complex, vector or matrix value

returns e^x (element-wise for vector/matrix)

exp 0
; returns 1
exp 1
; returns 2.718281828459045
exp complex 0 0 |prn
; prints "1.000000+0.000000i"
exp complex 0 3.141592653589793 |prn
; prints "-1.000000+0.000000i"
exp vector { 0 1 } |vec-to-block |first
; returns 1
exp matrix { 1 2 } { 0 1 } |mat-get 0 0
; returns 1

exp2

Returns 2**x, the base-2 exponential of x.

Args: 1

x integer or decimal value

returns decimal 2^x

exp2 3
; returns 8

expm1

Returns e**x - 1, the base-e exponential of x minus 1. It is more accurate than exp(x) - 1 when x is near zero.

Args: 1

x integer or decimal value

returns decimal e^x - 1

expm1 0
; returns 0

fma

Returns x * y + z, computed with only one rounding. (That is, FMA returns the fused multiply-add of x, y, and z.)

Args: 3

x integer or decimal value

y integer or decimal value

z integer or decimal value

returns decimal (x * y) + z computed with only one rounding

fma 2 3 4
; returns 10

j0

Returns the order-zero Bessel function of the first kind.

Args: 1

x integer or decimal value

returns decimal order-zero Bessel function of the first kind

j0 0
; returns 1

j1

Returns the order-one Bessel function of the first kind.

Args: 1

x integer or decimal value

returns decimal order-one Bessel function of the first kind

j1 0
; returns 0

y0

Returns the order-zero Bessel function of the second kind.

Args: 1

x integer or decimal value

returns decimal order-zero Bessel function of the second kind

y0 1
; returns 0.08825696421567697

y1

Returns the order-one Bessel function of the second kind.

Args: 1

x integer or decimal value

returns decimal order-one Bessel function of the second kind

y1 1
; returns -0.7812128213002887

yn

Returns the order-n Bessel function of the second kind.

Args: 2

n integer order

x integer or decimal value

returns decimal order-n Bessel function of the second kind

yn 2 1
; returns -1.6506826068162543

jn

Returns the order-n Bessel function of the first kind.

Args: 2

n integer order

x integer or decimal value

returns decimal order-n Bessel function of the first kind

jn 2 1
; returns 0.11490348493190049

trunc

Returns the integer value of input.

Args: 1

x integer or decimal value

returns decimal integer value of x (truncated toward zero)

trunc 3.7
; returns 3

pi

Returns the mathematical constant π (pi).

no arguments

returns decimal value of π (pi)

round\to pi 5
; returns 3.14159

deg->rad

Converts degrees to radians.

Args: 1

degrees integer or decimal value in degrees

returns decimal value in radians

deg->rad 180
; returns 3.141592653589793

is-near

Returns true if two decimals are close.

Args: 2

x integer or decimal value

y integer or decimal value

returns boolean true if values are very close, false otherwise

is-near 0.0000000000001 0
; returns true
is-near 0.1 0
; returns false

near-zero

Returns true if a decimal is close to zero.

Args: 1

x integer or decimal value

returns boolean true if value is very close to zero, false otherwise

near-zero 0.0000000000001
; returns true
near-zero 0.1
; returns false

is-prime

Returns true if the integer is a prime number.

Args: 1

n integer value to check

returns integer 1 if n is prime, 0 otherwise

is-prime 7
; returns true
is-prime 10
; returns false

to-eyr

Converts math dialect to Eyr dialect.

Args: 1

block block containing math expressions

returns block converted to Eyr dialect

calc

Evaluates expressions in math dialect.

Args: 1

block block containing math expressions with proper operator precedence and parentheses support

returns result of evaluating the math expressions following standard mathematical order of operations

calc { 1 + 2 * 3 }
; returns 7
calc { 2 + 3 * 4 }
; returns 14
calc { 10 - 6 / 2 }
; returns 7
calc { 2 * 3 + 4 }
; returns 10
calc { 8 / 2 - 1 }
; returns 3
calc { ( 1 + 2 ) * 3 }
; returns 9
calc { 2 * ( 3 + 4 ) }
; returns 14
calc { ( 10 - 6 ) / 2 }
; returns 2
calc { ( 2 + 3 ) * ( 4 - 1 ) }
; returns 15
calc { 2 + ( 3 * ( 4 + 1 ) ) }
; returns 17
calc { ( ( 2 + 3 ) * 4 ) - 1 }
; returns 19

gcd

Returns the greatest common divisor of two integers using Euclidean algorithm.

Args: 2

a integer value

b integer value

returns integer greatest common divisor of a and b

gcd 48 18
; returns 6
gcd 17 13
; returns 1
gcd 100 25
; returns 25
gcd 0 5
; returns 5
gcd 7 0
; returns 7

outer-product

Computes the outer product of two vectors (blocks), returning a matrix (block of blocks) where each element [i,j] = a[i] * b[j]. Similar to numpy.outer().

Args: 2

a block of integers or decimals (first vector)

b block of integers or decimals (second vector)

returns block of blocks (matrix) where element [i,j] = a[i] * b[j], similar to numpy.outer()

outer-product { 1 2 3 } { 10 20 }
; returns { { 10 20 } { 20 40 } { 30 60 } }
outer-product { 1 2 } { 1 2 3 }
; returns { { 1 2 3 } { 2 4 6 } }
outer-product { 2 3 } { 4 5 }
; returns { { 8 10 } { 12 15 } }
outer-product { } { 1 2 }
; returns { }

Match

Match dialect

pattern matching and deconstruction

match-block

Tries to match and deconstruct a value into multiple values, with support for literal values, type checking, get-words, code evaluation, and nested blocks. First argument can be any value. If it doesn't match, returns failure.

Args: 2

block Block to match and deconstruct

pattern Block containing

- Words to bind values to

- Literal values to match

- Opwords to check value types (e.g., , )

- Get-words to match against values in the current context (e.g., ?x)

- Square brackets [ ] to evaluate code with the value injected

- Nested blocks for recursive matching

returns Integer 1 if successful, or failure if the match fails

match-block { 1 2 3 } { a b c } a
; returns 1
match-block { 1 2 3 } { a b c } b
; returns 2
match-block { 1 2 3 } { a b c } c
; returns 3
match-block { 1 "test" 3 } { a "test" b } a
; returns 1
match-block { 1 "test" 3 } { a "test" b } b
; returns 3
match-block { 123 { "hi" 44 } 789 } { a { b c } d } a
; returns 123
match-block { 123 { "hi" 44 } 789 } { a { b c } d } b
; returns "hi"
match-block { 123 { "hi" 44 } 789 } { a { b c } d } c
; returns 44
match-block { 123 { "hi" 44 } 789 } { a { b c } d } d
; returns 789
match-block { 1 { 2 { 3 4 } 5 } 6 } { x { y { z w } v } u } z
; returns 3
match-block { 1 { 2 { 3 4 } 5 } 6 } { x { y { z w } v } u } w
; returns 4
x: 234 match-block { 123 234 } { 123 ?x }
; returns true

match

Matches a value against a series of pattern/action pairs. Pattern can be a single element or block. Returns the result of the first matching action, or failure if none match.

Args: 2

value Any value to match against patterns (can be a block or any other value)

patterns Block containing pairs

- First element pattern (can be a single element like or a block like { a b })

- Second element code block to evaluate if pattern matches

returns The result of evaluating the code block of the first matching pattern, or failure if no pattern matches

match { 1 2 } { { a b } { a + b } { x } { x * 2 } }
; returns 3
match { 101 202 } { { } { 0 } { a b } { a + b } }
; returns 303
match { 10 20 30 } { { x y z } { x + y + z } }
; returns 60
match 100 { 50 { "fifty" } 100 { "hundred" } 200 { "two hundred" } }
; returns "hundred"
match { 100 } { { 50 } { "fifty" } { 100 } { "hundred" } { 200 } { "two hundred" } }
; returns "hundred"
match { 10 20 } { { a 20 } { a * 2 } { 10 b } { b + 5 } }
; returns 20
match { 10 20 } { { 10 b } { b + 5 } { a 20 } { a * 2 } }
; returns 25
match { } { { } { 'no-data } { a b } { 'has-data } }
; returns no-data
match { 200 { "OK" 30 } } { { code { "OK" result } } { result } { code { "ERR" } } { 0 } }
; returns 30
match { 404 { "ERR" } } { { code { "OK" result } } { result } { code { "ERR" } } { code } }
; returns 404
match { "user" { "John" "Doe" 30 } } { { "user" { first last age } } { first } }
; returns "John"
match { 11 22 33 } { { a : bb } { a } }
; returns 11
match { 11 22 33 } { { a : bb } { bb } }
; returns { 22 33 }
match { 11 22 33 } { { a b : cc } { a + b } }
; returns 33
match { 11 22 33 44 } { { a b : cc } { cc } }
; returns { 33 44 }
match { { 12 23 } { 23 34 } { 34 45 } } { { { a b } : more } { a + b } }
; returns 35

Eyr

EYR Dialect

Stack based evaluator / dialect

eyr

Evaluates Rye block as Eyr (postfix) stack based code.

Args: 1

block Block of code to evaluate in EYR (postfix) mode

returns result of evaluating the block as postfix stack-based code

eyr { 1 2  }
; returns 3
eyr { 5 3  }
; returns 2
eyr { 4 2  }
; returns 8
eyr { 6 2  }
; returns 3
eyr { 10 3  }
; returns 1
eyr { 1 2 3 }
; returns 3

rye0

Evaluates Rye block as Rye0 dialect.

Args: 1

block Block of code to evaluate in RYE0 dialect

returns result of evaluating the block in RYE0 dialect

rye00

Evaluates Rye block as Rye00 dialect (builtins and integers only).

Args: 1

block Block of code to evaluate in RYE00 dialect (builtins and integers only)

returns result of evaluating the block in RYE00 dialect (minimal feature set)

eyr\clear

Clears the EYR stack.

no arguments

returns void

eyr { 1 2 3  }
; returns false
eyr { 1 2  3 }
; returns 3

eyr\full

Evaluates Rye block as Eyr (postfix) stack based code.

Args: 1

block Block of code to evaluate in EYR mode returning full stack as block

returns block containing all values from the EYR evaluation stack

eyr\clear eyr\full { 1 2 3 } |length?
; returns 3
eyr\clear eyr\full { 1 2  3 4  } |length?
; returns 2
eyr\clear eyr\full { 10 5  } |first
; returns 5

eyr\loop

Evaluates Rye block in loop as Eyr code (postfix stack based) N times.

Args: 2

count Integer number of times to loop

block Block of EYR code to execute in each iteration

returns result of the final EYR evaluation

to-eyr

Evaluates Rye block as Eyr (postfix) stack based code.

Args: 1

block Rye block to compile/convert to EYR format

returns block containing the EYR-compiled version of the input block

to-eyr { 5 * 3 } |length? |> 0
; returns true

SSH

SSH

SSH server functions

ssh-server

Creates a new SSH server that listens on the specified address.

Args: 1

address String containing host

returns native SSH server object

server: ssh-server "localhost:2222"
server |Password-auth { pass = "secret123" }
server |Handle fn { session } {
session .Write "Welcome to Rye SSH server!
"
session .Write "Type 'exit' to quit.
"
}
server |Serve


ssh-server//Handle

Sets a handler function for SSH sessions on the server.

Args: 2

server SSH server object

handler Function that receives an SSH session object

returns the SSH server object

ssh-server//Password-auth

Sets a password authentication handler for the SSH server.

Args: 2

server SSH server object

handler Function that receives a password string and returns true/false

returns the SSH server object

ssh-server//Serve

Starts the SSH server, listening for connections.

Args: 1

server SSH server object

returns the SSH server object, or error if unable to serve

ssh-session//Write

Writes a string to an SSH session.

Args: 2

session SSH session object

text String to write to the session

returns the SSH session object

Goroutines

Default

go-with

Executes a function in a separate goroutine, passing the specified value as an argument.

Args: 2

value Object to pass to the goroutine function

function Function to execute in a separate goroutine, receives the value as argument

returns the original value that was passed to the goroutine

x:: 0 , go-with 5 fn { v } { change! v 'x } , sleep 100 , x
; returns 5
y:: 0 , go-with "test" fn { v } { change! length? v 'y } , sleep 100 , y
; returns 4
; Simple goroutine with channel communication
ch: channel 1
go fn { } { ch .Send "Hello from goroutine" }
print ch .Read

; Using waitgroup to coordinate multiple goroutines
wg: waitgroup
results: channel 10
loop 5 { i |
wg .Add 1
go-with i fn { n } { results .Send n * 2 , wg .Done }
}
wg .Wait
results .Close

; Mutex for safe shared state
counter:: 0
mtx: mutex
go fn { } { mtx .Lock , change! counter + 1 'counter , mtx .Unlock }


go

Executes a function in a separate goroutine without passing any arguments.

Args: 1

function Function to execute in a separate goroutine (takes no arguments)

returns the function that was executed

x:: 0 , go fn { } { change! 42 'x } , sleep 100 , x
; returns 42
y:: "unchanged" , go fn { } { change! "changed" 'y } , sleep 100 , y
; returns "changed"

channel

Creates a new channel with the specified buffer size for goroutine communication.

Args: 1

buffer-size Integer specifying the channel buffer size (0 for unbuffered)

returns a new channel native object with the specified buffer size

[Native of kind Rye-channel] Methods (Rye-channel): Close [Builtin(1): Closes a channel, preventing further sends and causing pending/future reads to return an error. (goroutines) (Rye-channel//Close)] Read [Builtin(1): Reads the next value from a channel, blocking until a value is available or the channel is closed. (goroutines) (Rye-channel//Read)] Send [Builtin(2): Sends a value through a channel, blocking if the channel is unbuffered or full. (goroutines) (Rye-channel//Send)]
ch: channel 1 , ch .probe .lg .Send 42 , ch .Read
; returns 42
ch: channel 2 , ch .Send 1 , ch .Send 2 , ch .Read
; returns 1

Rye-channel//Read

Reads the next value from a channel, blocking until a value is available or the channel is closed.

Args: 1

channel Channel to read from

returns the next value from the channel, or an error if the channel is closed

ch: channel 1 , ch .Send 123 , ch .Read
; returns 123
ch: channel 1 , ch .Send "test" , ch .Read
; returns "test"

Rye-channel//Send

Sends a value through a channel, blocking if the channel is unbuffered or full.

Args: 2

channel Channel to send the value to

value Value to send through the channel

returns the channel object

ch: channel 1 , ch .Send 42 , ch .Read
; returns 42
ch: channel 3 , ch .Send "A" , ch .Send "B" , ch .Read
; returns "A"

Rye-channel//Close

Closes a channel, preventing further sends and causing pending/future reads to return an error.

Args: 1

channel Channel to close

returns the closed channel object

mutex

Creates a new mutex for synchronizing access to shared resources between goroutines.

(none)

returns a new mutex native object for synchronization

waitgroup

Creates a new waitgroup for coordinating multiple goroutines to wait for completion.

(none)

returns a new waitgroup native object for coordinating goroutines

Rye-mutex//Lock

Acquires the lock on a mutex, blocking until the lock becomes available.

Args: 1

mutex Mutex to acquire the lock on

returns the mutex object

Rye-mutex//Unlock

Releases the lock on a mutex, allowing other goroutines to acquire it.

Args: 1

mutex Mutex to release the lock from

returns the mutex object, or error if unlocking an unlocked mutex

Rye-waitgroup//Add

Adds the specified count to the waitgroup counter, indicating how many goroutines to wait for.

Args: 2

waitgroup Waitgroup to add goroutines to

count Number of goroutines to add to the wait counter

returns the waitgroup object

Rye-waitgroup//Done

Decrements the waitgroup counter by one, indicating that a goroutine has completed.

Args: 1

waitgroup Waitgroup to decrement the counter for

returns the waitgroup object

Rye-waitgroup//Wait

Blocks until the waitgroup counter reaches zero, meaning all goroutines have completed.

Args: 1

waitgroup Waitgroup to wait on

returns the waitgroup object after all goroutines have completed

select\fn

Performs a select operation on multiple channels, executing functions when channels are ready or a default function.

Args: 1

block Block containing channel-function pairs and optional default function

returns the original block argument

ch1: channel 1 , ch2: channel 1 , ch1 .Send 42 , select\fn { ch1 fn { v } { v } ch2 fn { v } { v + 1 } }
; returns 42
ch: channel 1 , select\fn { ch fn { v } { v * 2 } fn { } { 999 } }
; returns 999

Complex

Complex numbers

Functions for working with complex numbers

complex

Creates a complex number from real and imaginary parts.

Args: 2

pure

real Real part of the complex number (integer or decimal)

imag Imaginary part of the complex number (integer or decimal)

returns a new complex number with the given real and imaginary parts

complex?

Checks if a value is a complex number.

Args: 1

pure

value Value to check

returns boolean true if the value is a complex number, false otherwise

complex? complex 3 4
; returns true
complex? 5
; returns false
complex? "hello"
; returns false

real

Returns the real part of a complex number.

Args: 1

pure

value Complex number

returns decimal value representing the real part of the complex number

real complex 3 4
; returns 3
real complex -1.5 2.5
; returns -1.5

imag

Returns the imaginary part of a complex number.

Args: 1

pure

value Complex number

returns decimal value representing the imaginary part of the complex number

imag complex 3 4
; returns 4
imag complex -1.5 2.5
; returns 2.5

complex-conj

Returns the complex conjugate of a complex number.

Args: 1

pure

z Complex number

returns complex number representing the complex conjugate of z

complex-phase

Returns the phase (argument) of a complex number.

Args: 1

pure

z Complex number

returns decimal value representing the phase (argument) of the complex number

complex-phase complex 1 1
; returns 0.7853981633974483
complex-phase complex -1 0
; returns 3.141592653589793

Structures

Structures

Functions for converting between Rye and Go data structures

dict->struct

Converts a Rye Dict to a Go struct using reflection. Takes a Dict and a Native containing a pointer to a struct.

Args: 2

dict Rye Dict containing field names and values

struct-ptr Native containing a pointer to a Go struct

returns native containing the populated struct

dict->new-struct

Creates a new Go struct type at runtime based on a Rye Dict and populates it with values. Takes a Dict and a string for the struct name.

Args: 2

dict Rye Dict containing field names and values

name String name for the new struct type

returns native containing the dynamically created struct

struct->dict

Converts a Go struct to a Rye Dict using reflection. Takes a Native containing a struct or pointer to a struct.

Args: 1

struct Native containing a Go struct or pointer to struct

returns dict with struct field names as keys and field values as values

Vector

Vector

Vector operations

vector

Creates a vector from a block of numbers.

Args: 1

block block of numbers to convert to a vector

returns vector object

vector [ 1 2 3 ] |length?
; returns 3

normalize

Calculates the L2 norm (Euclidean length) of a vector.

Args: 1

vector vector object to normalize

returns decimal representing the L2 norm (Euclidean length) of the vector

vector [ 3 4 ] |normalize
; returns 5

std-deviation

Calculates the standard deviation of a vector's elements.

Args: 1

vector vector object

returns decimal representing the standard deviation of the vector elements

cc math , vector [ 1 2 3 4 5 ] |std-deviation |round\to 2
; returns 1.58

cosine-similarity

Calculates the cosine similarity between two vectors.

Args: 2

vector1 first vector object

vector2 second vector object

returns decimal representing the cosine similarity between the two vectors

cosine-similarity vector [ 1 0 ] vector [ 0 1 ]
; returns 0
cosine-similarity vector [ 1 1 ] vector [ 1 1 ]
; returns 0.9999999999999998

correlation

Calculates the correlation coefficient between two vectors.

Args: 2

vector1 first vector object

vector2 second vector object

returns decimal representing the correlation coefficient between the two vectors

correlation vector [ 1 2 3 4 5 ] vector [ 1 2 3 4 5 ]
; returns 0.9999999999999998
correlation vector [ 1 2 3 4 5 ] vector [ 5 4 3 2 1 ]
; returns -0.9999999999999998

dot-product

Calculates the dot product between two vectors.

Args: 2

vector1 first vector object

vector2 second vector object

returns decimal representing the dot product of the two vectors

dot-product vector [ 1 2 3 ] vector [ 4 5 6 ]
; returns 32

euclidean-distance

Calculates the Euclidean distance between two vectors. Useful for K-Means clustering.

Args: 2

vector1 first vector object

vector2 second vector object

returns decimal representing the Euclidean distance between the two vectors

euclidean-distance vector [ 0 0 ] vector [ 3 4 ]
; returns 5
euclidean-distance vector [ 1 2 3 ] vector [ 1 2 3 ]
; returns 0

mean-vectors

Calculates the element-wise mean of multiple vectors. Useful for creating 'Master Anchors'.

Args: 1

block block of vectors to average

returns new vector representing the element-wise mean of all input vectors

mean-vectors [ vector [ 1 2 ] vector [ 3 4 ] ] |block
; returns { 2 3 }

unit-vector

Returns a new normalized vector (length = 1). Essential for consistent dot products and overlays.

Args: 1

vector vector object to normalize

returns new vector with length 1 (unit vector)

vector [ 3 4 ] |unit-vector |normalize
; returns 1

project-vector

Projects vector onto another vector. Answers: 'How much of this vector is in the direction of another?'

Args: 2

vector1 vector to project

vector2 vector to project onto

returns new vector representing the projection of vector1 onto vector2

vector [ 3 4 ] |project-vector vector [ 1 0 ] |block
; returns { 3 0 }

reject-vector

Removes projection from vector. Use this to 'subtract' a concept direction from a vector.

Args: 2

vector1 vector to reject from

vector2 vector representing the direction to remove

returns new vector with the projection onto vector2 removed

vector [ 3 4 ] |reject-vector vector [ 1 0 ] |block
; returns { 0 4 }

Matrix

Matrix

Matrix operations for 2D numerical data

matrix\zeros

Creates a new matrix with the given dimensions, initialized to zeros.

Args: 2

rows number of rows

cols number of columns

returns a new zero-initialized matrix

matrix\zeros 2 3 |rows?
; returns 2
matrix\zeros 2 3 |cols?
; returns 3

matrix

Creates a matrix from a shape block and a data block.

Args: 2

shape block with { rows cols }

data block of decimal values in row-major order

returns a new matrix with the given data

matrix { 2 3 } { 1 2 3 4 5 6 } |mat-get 1 2
; returns 6

matrix\randn

Creates a matrix with random normal values (mean 0, std 1).

Args: 2

rows number of rows

cols number of columns

returns a new matrix with random normal values (mean 0, std 1)

matrix\randn 3 4 |rows?
; returns 3
matrix\randn 3 4 |cols?
; returns 4

matrix\ones

Creates a matrix filled with ones.

Args: 2

rows number of rows

cols number of columns

returns a new matrix filled with ones

matrix\ones 2 3 |mat-get 0 0
; returns 1
matrix\ones 2 3 |mat-get 1 2
; returns 1

matrix\eye

Creates an identity matrix of size n×n.

Args: 1

n size of the identity matrix

returns an n×n identity matrix

matrix\eye 3 |mat-get 0 0
; returns 1
matrix\eye 3 |mat-get 0 1
; returns 0
matrix\eye 3 |mat-get 1 1
; returns 1

shape?

Returns the shape of a matrix as { rows cols }.

Args: 1

mat matrix

returns block with { rows cols }

matrix\zeros 3 4 |shape?
; returns { 3 4 }

rows?

Returns the number of rows in a matrix.

Args: 1

mat matrix

returns number of rows

matrix\zeros 3 4 |rows?
; returns 3

cols?

Returns the number of columns in a matrix.

Args: 1

mat matrix

returns number of columns

matrix\zeros 3 4 |cols?
; returns 4

mat-get

Gets the element at the specified row and column (0-indexed).

Args: 3

mat matrix

row row index (0-based)

col column index (0-based)

returns the element at (row, col)

matrix { 2 3 } { 1 2 3 4 5 6 } |mat-get 0 1
; returns 2
matrix { 2 3 } { 1 2 3 4 5 6 } |mat-get 1 0
; returns 4

mat-set!

Sets the element at the specified row and column (0-indexed). Modifies matrix in place.

Args: 4

mat matrix (modified in place)

row row index (0-based)

col column index (0-based)

val value to set

returns the modified matrix

m: matrix\zeros 2 2 , mat-set! m 0 1 5 , mat-get m 0 1
; returns 5

mat-row

Returns a row of the matrix as a vector.

Args: 2

mat matrix

row row index (0-based)

returns the row as a vector

mat-col

Returns a column of the matrix as a vector.

Args: 2

mat matrix

col column index (0-based)

returns the column as a vector

mat-transpose

Returns the transpose of a matrix.

Args: 1

mat matrix

returns transposed matrix

matrix { 2 3 } { 1 2 3 4 5 6 } |mat-transpose |shape?
; returns { 3 2 }
matrix { 2 3 } { 1 2 3 4 5 6 } |mat-transpose |mat-get 0 1
; returns 4

mat-mul

Matrix multiplication. A (m×n) × B (n×p) = C (m×p).

Args: 2

A left matrix (m×n)

B right matrix (n×p)

returns result matrix (m×p)

A: matrix { 2 3 } { 1 2 3 4 5 6 } , B: matrix { 3 2 } { 1 2 3 4 5 6 } , mat-mul A B |shape?
; returns { 2 2 }
A: matrix { 2 3 } { 1 2 3 4 5 6 } , B: matrix { 3 2 } { 1 2 3 4 5 6 } , mat-mul A B |mat-get 0 0
; returns 22

mat-hadamard

Element-wise (Hadamard) multiplication of two matrices. In the future, could have a dedicated .* operator.

Args: 2

A first matrix

B second matrix (same dimensions)

returns element-wise product

A: matrix\ones 2 2 , B: matrix\ones 2 2 , mat-hadamard A B |mat-get 0 0
; returns 1

mat-add

Element-wise addition of two matrices. In the future, could have a dedicated .+ operator.

Args: 2

A first matrix

B second matrix (same dimensions)

returns element-wise sum

A: matrix\ones 2 2 , B: matrix\ones 2 2 , mat-add A B |mat-get 0 0
; returns 2

mat-sub

Element-wise subtraction of two matrices. In the future, could have a dedicated .- operator.

Args: 2

A first matrix

B second matrix (same dimensions)

returns element-wise difference

A: matrix\ones 2 2 , B: matrix\ones 2 2 , mat-sub A B |mat-get 0 0
; returns 0

mat-scale

Multiplies all elements of a matrix by a scalar.

Args: 2

mat matrix

scalar number to multiply by

returns scaled matrix

matrix\ones 2 2 |mat-scale 3 |mat-get 0 0
; returns 3

mat-sum-rows

Returns a vector containing the sum of each row.

Args: 1

mat matrix

returns vector with sum of each row

mat-sum-cols

Returns a vector containing the sum of each column.

Args: 1

mat matrix

returns vector with sum of each column

mat-max-rows

Returns a vector containing the maximum of each row.

Args: 1

mat matrix

returns vector with max of each row

mat-max-cols

Returns a vector containing the maximum of each column.

Args: 1

mat matrix

returns vector with max of each column

mat-to-block

Converts a matrix to a block of blocks (each row is a block).

Args: 1

mat matrix

returns block of blocks (each inner block is a row)

matrix { 2 2 } { 1 2 3 4 } |mat-to-block |length?
; returns 2

block-to-mat

Converts a block of blocks (rows) to a matrix.

Args: 1

block block of blocks (each inner block is a row)

returns matrix

{ { 1 2 } { 3 4 } } |block-to-mat |shape?
; returns { 2 2 }

vector-to-mat

Converts a vector to a matrix. Use 'row for 1×n or 'col for n×1.

Args: 2

vec vector

orientation 'row or 'col

returns matrix (1×n or n×1)

vector { 1 2 3 } |vector-to-mat 'row |shape?
; returns { 1 3 }
vector { 1 2 3 } |vector-to-mat 'col |shape?
; returns { 3 1 }

mat-slice

Extracts a sub-matrix. Row and column ranges are { start end } (inclusive, 0-indexed).

Args: 3

mat matrix

row-range { start end } (inclusive)

col-range { start end } (inclusive)

returns sub-matrix

matrix { 2 3 } { 1 2 3 4 5 6 } |mat-slice { 0 1 } { 1 2 } |shape?
; returns { 2 2 }

mat-softmax

Applies softmax to each column of the matrix. Returns a new matrix.

Args: 1

matrix input matrix

returns a new matrix with softmax applied to each column

matrix { 2 2 } { 1 2 3 4 } |mat-softmax |mat-get 0 0 |> 0.1
; returns true

mat-set-col!

Sets a column of the matrix from a vector or block. Mutates in place.

Args: 3

matrix matrix to modify

col column index (0-based)

values vector or block of values

returns the modified matrix

m: matrix\zeros 3 2 , mat-set-col! m 0 vector { 1 2 3 } , mat-get m 1 0
; returns 2

vec-add

Adds two vectors element-wise. Returns a new vector.

Args: 2

v1 first vector

v2 second vector

returns a new vector with element-wise sum

vec-add vector { 1 2 } vector { 3 4 } |first
; returns 4

vec-sub

Subtracts two vectors element-wise (v1 - v2). Returns a new vector.

Args: 2

v1 first vector

v2 second vector

returns a new vector with element-wise difference (v1 - v2)

vec-sub vector { 5 3 } vector { 1 2 } |first
; returns 4

vec-to-block

Converts a vector to a block of decimal values.

Args: 1

v vector to convert

returns a block containing the vector values as decimals

vec-to-block vector { 1 2 3 } |second
; returns 2