Skip to main content

Builtin

Enum Builtin 

Source
pub enum Builtin {
Show 97 variants Car, Cdr, Cons, List, Null, Pairp, Numberp, Booleanp, Procedurep, Symbolp, EqP, EqvP, EqualP, Add, Sub, Mul, Div, Modulo, Remainder, Quotient, Abs, Max, Min, Gcd, Lcm, Expt, Square, Zerop, Positivep, Negativep, Oddp, Evenp, Integerp, Exactp, Inexactp, ExactIntegerp, Floor, Ceiling, Truncate, Round, Lt, Gt, Le, Ge, NumEq, Not, Newline, Display, Error, SetCar, SetCdr, MakeArray, ArrayRef, ArraySet, ArrayLength, Arrayp, Vectorp, MakeVector, Vector, VectorLength, VectorRef, VectorSet, VectorToList, ListToVector, VectorFill, VectorCopy, Charp, CharEq, CharLt, CharGt, CharLe, CharGe, CharToInteger, IntegerToChar, CharUpcase, CharDowncase, Stringp, MakeString, String, StringLength, StringRef, StringSet, StringEq, StringLt, StringGt, StringLe, StringGe, StringAppend, StringToList, ListToString, Substring, StringCopy, Gc, GcEnable, GcDisable, GcEnabledP, ArenaStats,
}
Expand description

Built-in functions (optimization to avoid symbol lookup)

NOTE: This Lisp supports mutation via set!, set-car!, and set-cdr!

  • Mutation operations break referential transparency
  • All evaluation is call-by-value (strict)

§Adding New Builtins

To add a new builtin:

  1. Add an entry to the define_builtins! macro invocation
  2. Implement its evaluation logic in grift_eval

Variants§

§

Car

car - Get first element of pair

§

Cdr

cdr - Get second element of pair

§

Cons

cons - Create a pair

§

List

list - Create a list from arguments

§

Null

null? - Check if value is the empty list

§

Pairp

pair? - Check if value is a pair

§

Numberp

number? - Check if value is a number

§

Booleanp

boolean? - Check if value is a boolean

§

Procedurep

procedure? - Check if value is a procedure

§

Symbolp

symbol? - Check if value is a symbol

§

EqP

eq? - Scheme-compliant identity equality

§

EqvP

eqv? - Scheme-compliant value equality

§

EqualP

equal? - Scheme-compliant recursive structural equality

§

Add

    • Addition
§

Sub

    • Subtraction
§

Mul

    • Multiplication
§

Div

/ - Division

§

Modulo

modulo - Scheme modulo (result has sign of divisor)

§

Remainder

remainder - Scheme remainder (result has sign of dividend)

§

Quotient

quotient - Integer quotient (truncated towards zero)

§

Abs

abs - Absolute value

§

Max

max - Maximum of numbers

§

Min

min - Minimum of numbers

§

Gcd

gcd - Greatest common divisor

§

Lcm

lcm - Least common multiple

§

Expt

expt - Exponentiation

§

Square

square - Square of a number

§

Zerop

zero? - Check if number is zero

§

Positivep

positive? - Check if number is positive

§

Negativep

negative? - Check if number is negative

§

Oddp

odd? - Check if number is odd

§

Evenp

even? - Check if number is even

§

Integerp

integer? - Check if value is an integer

§

Exactp

exact? - Check if number is exact (always true for integers)

§

Inexactp

inexact? - Check if number is inexact (always false for integers)

§

ExactIntegerp

exact-integer? - Check if value is an exact integer

§

Floor

floor - Largest integer not greater than x (identity for integers)

§

Ceiling

ceiling - Smallest integer not less than x (identity for integers)

§

Truncate

truncate - Integer closest to x whose absolute value is not larger (identity for integers)

§

Round

round - Closest integer to x, rounding to even when x is halfway (identity for integers)

§

Lt

< - Less than

§

Gt

  • Greater than
§

Le

<= - Less than or equal

§

Ge

= - Greater than or equal

§

NumEq

= - Numeric equality

§

Not

not - Boolean negation

§

Newline

newline - Print a newline

§

Display

display - Print value without quotes

§

Error

error - Raise an error

§

SetCar

set-car! - Mutate car of pair

§

SetCdr

set-cdr! - Mutate cdr of pair

§

MakeArray

make-array - Create an array with given length and initial value

§

ArrayRef

array-ref - Get element at index (O(1))

§

ArraySet

array-set! - Set element at index (O(1))

§

ArrayLength

array-length - Get array length (O(1))

§

Arrayp

array? - Check if value is an array

§

Vectorp

vector? - Check if value is a vector

§

MakeVector

make-vector - Create a vector with optional fill value

§

Vector

vector - Create vector from arguments

§

VectorLength

vector-length - Get length of vector

§

VectorRef

vector-ref - Get element at index

§

VectorSet

vector-set! - Set element at index

§

VectorToList

vector->list - Convert vector to list

§

ListToVector

list->vector - Convert list to vector

§

VectorFill

vector-fill! - Fill vector with value

§

VectorCopy

vector-copy - Copy a vector

§

Charp

char? - Check if value is a character

§

CharEq

char=? - Character equality

§

CharLt

char<? - Character less than

§

CharGt

char>? - Character greater than

§

CharLe

char<=? - Character less than or equal

§

CharGe

char>=? - Character greater than or equal

§

CharToInteger

char->integer - Convert character to its Unicode code point

§

IntegerToChar

integer->char - Convert Unicode code point to character

§

CharUpcase

char-upcase - Convert character to uppercase

§

CharDowncase

char-downcase - Convert character to lowercase

§

Stringp

string? - Check if value is a string

§

MakeString

make-string - Create a string of given length

§

String

string - Create string from characters

§

StringLength

string-length - Get length of string

§

StringRef

string-ref - Get character at index

§

StringSet

string-set! - Set character at index

§

StringEq

string=? - String equality

§

StringLt

string<? - String less than

§

StringGt

string>? - String greater than

§

StringLe

string<=? - String less than or equal

§

StringGe

string>=? - String greater than or equal

§

StringAppend

string-append - Concatenate strings

§

StringToList

string->list - Convert string to list of characters

§

ListToString

list->string - Convert list of characters to string

§

Substring

substring - Extract a substring

§

StringCopy

string-copy - Copy a string

§

Gc

gc - Manually trigger garbage collection

§

GcEnable

gc-enable - Enable automatic garbage collection

§

GcDisable

gc-disable - Disable automatic garbage collection

§

GcEnabledP

gc-enabled? - Check if GC is enabled

§

ArenaStats

arena-stats - Get arena statistics as a list

Implementations§

Source§

impl Builtin

Source

pub const ALL: &'static [Builtin]

All builtins for initialization

Source

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

Get the symbol name for this builtin

Trait Implementations§

Source§

impl Clone for Builtin

Source§

fn clone(&self) -> Builtin

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 Builtin

Source§

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

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

impl PartialEq for Builtin

Source§

fn eq(&self, other: &Builtin) -> 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 Builtin

Source§

impl Eq for Builtin

Source§

impl StructuralPartialEq for Builtin

Auto Trait Implementations§

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.