pub enum StdLib {
Show 150 variants
Map,
Filter,
Fold,
Length,
Append,
Reverse,
Nth,
Take,
Drop,
Zip,
Member,
Assoc,
Range,
Compose,
Identity,
Constantly,
Flip,
Curry,
Cadr,
Caddr,
Cddr,
ForEach,
ListTail,
ListRef,
ListP,
ListCopy,
Memq,
Memv,
Assq,
Assv,
Caar,
Cdar,
Caaar,
Caadr,
Cadar,
Cdaar,
Cdadr,
Cddar,
Cdddr,
Cadddr,
Cddddr,
Sign,
MakeList,
ListSet,
LastPair,
Last,
MemberEqual,
AssocEqual,
Reduce,
FoldRight,
Any,
Every,
Find,
FilterMap,
Partition,
PartitionHelper,
Remove,
Delete,
BooleanEq,
GetPi,
GetE,
GetEpsilon,
SqrtIter,
Sqrt,
ExpIter,
Exp,
LogSeriesIter,
LogNewtonIter,
Log,
SinIter,
SinReduce,
Sin,
CosIter,
Cos,
Tan,
AsinIter,
Asin,
Acos,
AtanSeriesIter,
Atan1,
Atan2,
Sinh,
Cosh,
Tanh,
LogBase,
Log10,
Log2,
NanP,
InfiniteP,
FiniteP,
RealP,
RationalP,
ComplexP,
ExactGtInexact,
InexactGtExact,
CharAlphabeticP,
CharNumericP,
CharWhitespaceP,
CharUpperCaseP,
CharLowerCaseP,
DigitValue,
CharFoldcase,
CharCiEqP,
CharCiLtP,
CharCiGtP,
CharCiLtEqP,
CharCiGtEqP,
StringCiEqP,
StringCiCompareHelper,
StringUpcase,
StringDowncase,
StringFoldcase,
Iota1,
Iota2,
Iota3,
IotaHelper,
ListTabulate,
ListTabulateHelper,
First,
Second,
Third,
Fourth,
Fifth,
Sixth,
Seventh,
Eighth,
Ninth,
Tenth,
TakeRight,
DropRight,
SplitAt,
Concatenate,
Flatten,
Count,
StringForEach,
StringMap,
StringNullP,
StringReverse,
StringContains,
StringContainsHelper,
StringPrefixP,
StringPrefixHelper,
StringJoin,
StringSplit,
StringSplitHelper,
StringTrim,
DropWhileWs,
Sum,
Product,
Average,
}Expand description
Standard library functions (stored in static memory, not arena)
These functions are defined as Lisp code in static strings and are parsed on-demand when called. This provides:
- Zero arena cost for function definitions (static strings)
- Easy maintenance (just add entries to the
define_stdlib!macro) - Simple implementation (no build scripts needed)
The parsing overhead is minimal since:
- Standard library functions are typically called frequently (can optimize)
- Parsing is fast (simple recursive descent)
- Parsed AST is temporary and GC’d after evaluation
§Memory Layout
Each StdLib variant stores references to static data:
- Function name (for lookup and debugging)
- Parameter names (static slice)
- Body source code (static string, parsed on each call)
§Adding New Functions
To add a new stdlib function, add an entry to the define_stdlib! macro
invocation. No other code changes are needed.
Variants§
Map
Scheme Standard Library
Filter
(filter pred lst) - Return elements where pred is true
Fold
(fold f acc lst) - Left fold over lst
Length
(length lst) - Return length of lst
Append
(append a b) - Concatenate two lists
Reverse
(reverse lst) - Reverse a list
Nth
(nth n lst) - Get nth element (0-indexed)
Take
(take n lst) - Take first n elements
Drop
(drop n lst) - Drop first n elements
Zip
(zip a b) - Zip two lists into list of pairs
Member
(member x lst) - Check if x is in lst using eq?
Assoc
(assoc key alist) - Look up key in association list using eq?
Range
(range start end) - Generate list of integers [start, end)
Compose
(compose f g) - Return function that applies g then f
Identity
(identity x) - Return x unchanged
Constantly
(constantly x) - Return function that always returns x
Flip
(flip f) - Flip argument order of binary function
Curry
(curry f x) - Partial application
Cadr
(cadr lst) - (car (cdr lst))
Caddr
(caddr lst) - (car (cdr (cdr lst)))
Cddr
(cddr lst) - (cdr (cdr lst))
ForEach
============================================================
ListTail
(list-tail lst k) - Return sublist starting at k-th element
ListRef
(list-ref lst k) - Return k-th element of lst (0-indexed)
ListP
(list? obj) - Check if obj is a proper list
ListCopy
(list-copy lst) - Create a shallow copy of a list
Memq
(memq obj lst) - Find obj in lst using eq?, return sublist or #f
Memv
(memv obj lst) - Find obj in lst using eqv?, return sublist or #f
Assq
(assq key alist) - Look up key in alist using eq?
Assv
(assv key alist) - Look up key in alist using eqv?
Caar
============================================================
Cdar
(cdar lst) - (cdr (car lst))
Caaar
(caaar lst) - (car (car (car lst)))
Caadr
(caadr lst) - (car (car (cdr lst)))
Cadar
(cadar lst) - (car (cdr (car lst)))
Cdaar
(cdaar lst) - (cdr (car (car lst)))
Cdadr
(cdadr lst) - (cdr (car (cdr lst)))
Cddar
(cddar lst) - (cdr (cdr (car lst)))
Cdddr
(cdddr lst) - (cdr (cdr (cdr lst)))
Cadddr
(cadddr lst) - (car (cdr (cdr (cdr lst))))
Cddddr
(cddddr lst) - (cdr (cdr (cdr (cdr lst))))
Sign
============================================================
MakeList
============================================================
ListSet
(list-set! lst k obj) - Store obj in element k of lst
LastPair
(last-pair lst) - Return the last pair in a non-empty list
Last
(last lst) - Return the last element of a non-empty list
MemberEqual
============================================================
AssocEqual
(assoc-equal key alist) - Look up key in alist using equal?
Reduce
============================================================
FoldRight
(fold-right f init lst) - Right fold, R7RS name
Any
(any pred lst) - Return #t if pred is true for any element
Every
(every pred lst) - Return #t if pred is true for all elements
Find
(find pred lst) - Return first element where pred is true, or #f
FilterMap
(filter-map f lst) - Map f over lst, keeping only non-#f results
Partition
(partition pred lst) - Split lst into pair of two lists: (matching . non-matching)
PartitionHelper
Remove
(remove pred lst) - Return lst with elements where pred is true removed
Delete
(delete x lst) - Remove all occurrences of x from lst using equal?
BooleanEq
============================================================
GetPi
============================================================
GetE
(get-e) - Returns Euler’s number e, the base of natural logarithms
GetEpsilon
(get-epsilon) - Returns accuracy threshold for iterative algorithms
SqrtIter
============================================================
Sqrt
(sqrt x) - Square root using Newton-Raphson iteration
ExpIter
============================================================
Exp
(exp x) - Exponential function e^x using Taylor series
LogSeriesIter
(log-series-iter z term sum n sign) - Helper for log series
LogNewtonIter
(log-newton-iter x guess) - Helper for log Newton iteration
Log
(log x) - Natural logarithm using Newton’s method and series
SinIter
============================================================
SinReduce
(sin-reduce x) - Reduce angle to [-pi, pi]
Sin
(sin x) - Sine using Taylor series
CosIter
(cos-iter x term sum n) - Helper for cos Taylor series
Cos
(cos x) - Cosine using Taylor series
Tan
(tan x) - Tangent as sin/cos
AsinIter
============================================================
Asin
(asin x) - Inverse sine using Newton’s method
Acos
(acos x) - Inverse cosine
AtanSeriesIter
(atan-series-iter y y2 term sum n) - Helper for atan series
Atan1
(atan1 y) - Arctangent of single argument
Atan2
(atan2 y x) - Arctangent of two arguments
Sinh
============================================================
Cosh
(cosh x) - Hyperbolic cosine
Tanh
(tanh x) - Hyperbolic tangent
LogBase
============================================================
Log10
(log10 x) - Base-10 logarithm
Log2
(log2 x) - Base-2 logarithm
NanP
============================================================
InfiniteP
(infinite? x) - Check if x is infinite
FiniteP
(finite? x) - Check if x is a finite number
RealP
(real? x) - Check if x is a real number (same as number? in our implementation)
RationalP
(rational? x) - Check if x is a rational number (floats are approximate rationals)
ComplexP
(complex? x) - Check if x is a complex number (same as number? - no complex support)
ExactGtInexact
============================================================
InexactGtExact
(inexact->exact x) - Convert inexact to exact (float to int, truncates)
CharAlphabeticP
============================================================
CharNumericP
(char-numeric? char) - Check if char is a decimal digit (0-9)
CharWhitespaceP
(char-whitespace? char) - Check if char is whitespace
CharUpperCaseP
(char-upper-case? char) - Check if char is uppercase (A-Z)
CharLowerCaseP
(char-lower-case? char) - Check if char is lowercase (a-z)
DigitValue
(digit-value char) - Return numeric value (0-9) of a digit character, or #f
CharFoldcase
(char-foldcase char) - Unicode simple case-folding (lowercase for ASCII)
CharCiEqP
Case-insensitive character comparisons
CharCiLtP
(char-ci<? char1 char2) - Case-insensitive char<?
CharCiGtP
(char-ci>? char1 char2) - Case-insensitive char>?
CharCiLtEqP
(char-ci<=? char1 char2) - Case-insensitive char<=?
CharCiGtEqP
(char-ci>=? char1 char2) - Case-insensitive char>=?
StringCiEqP
============================================================
StringCiCompareHelper
StringUpcase
(string-upcase s) - Convert string to uppercase
StringDowncase
(string-downcase s) - Convert string to lowercase
StringFoldcase
(string-foldcase s) - Convert string using case folding
Iota1
============================================================
Iota2
(iota2 count start) - Generate list of integers [start, start+count)
Iota3
(iota3 count start step) - Generate arithmetic sequence
IotaHelper
ListTabulate
(list-tabulate n proc) - Create list by applying proc to 0..n-1
ListTabulateHelper
First
(circular-list x …) - Create a circular list (infinite)
Second
(second lst) - Return second element
Third
(third lst) - Return third element
Fourth
(fourth lst) - Return fourth element
Fifth
(fifth lst) - Return fifth element
Sixth
(sixth lst) - Return sixth element
Seventh
(seventh lst) - Return seventh element
Eighth
(eighth lst) - Return eighth element
Ninth
(ninth lst) - Return ninth element
Tenth
(tenth lst) - Return tenth element
TakeRight
(take-right lst k) - Return the last k elements of lst
DropRight
(drop-right lst k) - Return all but the last k elements
SplitAt
(split-at lst k) - Split list at position k, returns (take . drop)
Concatenate
(concatenate lsts) - Append all lists in lsts
Flatten
(flatten lst) - Flatten a nested list structure
Count
(count pred lst) - Count elements satisfying predicate
StringForEach
============================================================
StringMap
(string-map proc s) - Map proc over characters, return new string
StringNullP
(string-null? s) - Check if string is empty
StringReverse
(string-reverse s) - Reverse a string
StringContains
(string-contains s1 s2) - Check if s2 is a substring of s1
StringContainsHelper
StringPrefixP
StringPrefixHelper
StringJoin
(string-join lst sep) - Join list of strings with separator
StringSplit
(string-split s sep) - Split string by separator character
StringSplitHelper
StringTrim
(string-trim s) - Remove leading and trailing whitespace
DropWhileWs
Sum
============================================================
Product
(product lst) - Product of a list of numbers
Average
(average lst) - Average of a list of numbers