🤖 Generated with [ECA](https://eca.dev) Co-Authored-By: eca-agent <git@eca.dev>
60 lines
5.8 KiB
Text
60 lines
5.8 KiB
Text
@section{The standard library}
|
|
|
|
A short tour of the standard library. Each module's full reference is its own page under @link["modules/index.html"]{Modules}.
|
|
|
|
@subsection{std/prelude}
|
|
|
|
The prelude is what every module has without importing anything: the collections and their functions, strings and characters, files and ports, Concurrent ML and scopes, and the macros the language is written with, such as @code{cond}, @code{if-let} and @code{type/derive}. Its reference also covers the builtins, the functions compiled into the runtime rather than written in Bjolang, since every program gets them with the prelude. At the REPL, @code{:show name} prints the same documentation.
|
|
For more details, see @link["modules/std/prelude.html"]{@code{(std prelude)}}.
|
|
|
|
@subsection{std/maths}
|
|
|
|
Numbers beyond the operators. Integer division has Racket's names: @code{quotient} and @code{remainder} are what @code{/} and @code{%} do, and @code{modulo} takes the sign of the divisor, so @code{(modulo -1 10)} is 9. There are @code{gcd}, @code{lcm}, an integer @code{expt} and an exact @code{integer-sqrt} at every integer type, the @code{exact-} roundings from a double to an int, and the rest of @code{System.Math} over doubles. The prelude has @code{abs}, @code{min}, @code{max} and @code{clamp} from here without an import.
|
|
For more details, see @link["modules/std/maths.html"]{@code{(std maths)}}.
|
|
|
|
@subsection{std/fmt}
|
|
|
|
Formatting in Bjolang is divided into two layers: interpolation and layout.
|
|
Interpolation provides a simple way to combine mixed scalar types into strings or print them directly using @code{println*} and @code{str*}.
|
|
The layout layer provides a composable block algebra for more complex text formatting, such as padding, aligning, wrapping paragraphs, and laying out tables.
|
|
For more details, see @link["modules/std/fmt.html"]{@code{(std fmt)}}.
|
|
|
|
@subsection{std/rx}
|
|
|
|
Bjolang provides a built-in regular expression engine. Unlike languages that use strings for regex (like @code{"[a-z]+"}), Bjolang uses structural S-expressions. This means you never have to double-escape characters, and the compiler validates your patterns at compile time. Built-in character sets and anchors are written as keywords (e.g., @code{:bos}, @code{:digit}), and operations that group or repeat patterns are function-like lists (e.g., @code{(seq ...)}).
|
|
For more details, see @link["modules/std/rx.html"]{@code{(std rx)}}.
|
|
|
|
@subsection{std/http}
|
|
|
|
The @code{std/http} module allows you to build and send HTTP requests. Sending a request three ways — blocking, suspending, or as an event — is the only thing that differs between the entry points. There is no C# in this module: @code{System.Net.Http} is reached with @code{import/extern}, and the response body is an ordinary @code{TextInputPort}.
|
|
For more details, see @link["modules/std/http.html"]{@code{(std http)}}.
|
|
|
|
@subsection{std/run}
|
|
|
|
The @code{std/run} module provides a way to run external programs. A form is one thing to run, written as a quoted literal, like @code{'(cat "hej.txt")}. You can connect programs in a pipe with @code{'(pipe (cat "a") (wc -l))}, and redirect input and output to files. Redirections can nest, and you can even splice computed arguments or write stages in Bjolang.
|
|
For more details, see @link["modules/std/run.html"]{@code{(std run)}}.
|
|
|
|
@subsection{std/random}
|
|
|
|
The random module provides a ChaCha20 generator, seeded with 256 bits from the OS CSPRNG, with one generator per thread. The default path locks nothing and shares nothing, making it safe and fast on a bjoroutine. The ambient source has no state to race on, so drawing from multiple threads is efficient. You can generate random integers and more.
|
|
For more details, see @link["modules/std/random.html"]{@code{(std random)}}.
|
|
|
|
@subsection{std/atomic}
|
|
|
|
An atomic is a cell that threads can read and write without a lock. @code{(make-atomic v)} makes one of any type, and @code{atomic-ref}, @code{atomic-set!}, @code{atomic-swap!}, @code{atomic-compare-and-swap!} and @code{atomic-update!} work on it. For @code{int}, @code{uint}, @code{long} and @code{ulong} there are also @code{atomic-increment!}, @code{atomic-decrement!}, @code{atomic-add!} and @code{atomic-sub!}, which compile to direct calls to @code{System.Threading.Interlocked} and wrap on overflow. Swap and compare-and-swap return the value from before the call; the other operations that change the atomic return the new value. The width of a counter comes from type inference, so write @code{(make-atomic 0L)} for a long counter: @code{(make-atomic 0)} is an int.
|
|
For more details, see @link["modules/std/atomic.html"]{@code{(std atomic)}}.
|
|
|
|
@subsection{std/datetime}
|
|
|
|
This module provides types and functions for handling time. The clock is an argument (with a default that a program can rebind), and the types refuse operations that mean nothing, such as adding a calendar day to an instant. The module separates @code{Date} (a calendar date without a timezone), @code{Time} (a time of day without a timezone), and @code{DateTime} (a date and time without a timezone), as well as handling timezones.
|
|
For more details, see @link["modules/std/datetime.html"]{@code{(std datetime)}}.
|
|
|
|
@subsection{text/bjodat}
|
|
|
|
bjodat is Bjolang's shapes read as data: no evaluation, no macro expansion, no environment. It is what a package manifest, a lockfile, or a config file is written in. You can parse text straight into a record using @code{bjodat-parse-<Name>}, which avoids intermediate trees and allocations.
|
|
For more details, see @link["modules/text/bjodat.html"]{@code{(text bjodat)}}.
|
|
|
|
@subsection{text/json}
|
|
|
|
The @code{text/json} module provides JSON parsing and generation capabilities. Like @code{bjodat}, it allows for working with structured data but using the standard JSON format, which is essential for web communication.
|
|
For more details, see @code{prelude.org} and related standard library documentation.
|