Skip to main content

StdLib

Enum StdLib 

Source
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:

  1. Standard library functions are typically called frequently (can optimize)
  2. Parsing is fast (simple recursive descent)
  3. 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

Implementations§

Source§

impl StdLib

Source

pub const ALL: &'static [StdLib]

All standard library functions for initialization

Source

pub const fn name(&self) -> &'static str

Get the function name

Source

pub const fn params(&self) -> &'static [&'static str]

Get the parameter names for this function

Source

pub const fn body(&self) -> &'static str

Get the body source code (Lisp expression as static string)

This string is parsed on each call to the function. The parsed AST is temporary and GC’d after evaluation.

Trait Implementations§

Source§

impl Clone for StdLib

Source§

fn clone(&self) -> StdLib

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StdLib

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for StdLib

Source§

fn eq(&self, other: &StdLib) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for StdLib

Source§

impl Eq for StdLib

Source§

impl StructuralPartialEq for StdLib

Auto Trait Implementations§

§

impl Freeze for StdLib

§

impl RefUnwindSafe for StdLib

§

impl Send for StdLib

§

impl Sync for StdLib

§

impl Unpin for StdLib

§

impl UnwindSafe for StdLib

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.