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:
- Add an entry to the
define_builtins!macro invocation - 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