pub enum Builtin {
Show 129 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,
Portp,
InputPortp,
OutputPortp,
CurrentInputPort,
CurrentOutputPort,
CurrentErrorPort,
ClosePort,
CloseInputPort,
CloseOutputPort,
ReadChar,
WriteChar,
PeekChar,
CharReadyp,
Write,
Read,
EofObject,
EofObjectp,
OpenInputString,
OpenOutputString,
GetOutputString,
Error,
ErrorObjectP,
ErrorObjectMessage,
ErrorObjectIrritants,
ErrorObjectType,
SetCar,
SetCdr,
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,
Identifierp,
BoundIdentifierEq,
FreeIdentifierEq,
SyntaxToDatum,
SyntaxE,
DatumToSyntax,
DatumToSyntaxObject,
SyntaxObjectToDatum,
GenerateTemporaries,
SymbolToString,
StringToSymbol,
NumberToString,
StringToNumber,
}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
Portp
port? - Check if value is a port
InputPortp
input-port? - Check if value is an input port
OutputPortp
output-port? - Check if value is an output port
CurrentInputPort
current-input-port - Get current input port
CurrentOutputPort
current-output-port - Get current output port
CurrentErrorPort
current-error-port - Get current error port
ClosePort
close-port - Close a port
CloseInputPort
close-input-port - Close an input port
CloseOutputPort
close-output-port - Close an output port
ReadChar
read-char - Read a character from a port
WriteChar
write-char - Write a character to a port
PeekChar
peek-char - Peek at next character without consuming it
CharReadyp
char-ready? - Check if a character is available
Write
write - Write value with machine-readable representation
Read
read - Read an S-expression from a port
EofObject
eof-object - Return the EOF object
EofObjectp
eof-object? - Check if value is the EOF object
OpenInputString
open-input-string - Create an input port from a string
OpenOutputString
open-output-string - Create an output string port
GetOutputString
get-output-string - Get accumulated string from an output string port
Error
error - Raise an error
ErrorObjectP
error-object? - Check if value is an error object
ErrorObjectMessage
error-object-message - Get message from error object
ErrorObjectIrritants
error-object-irritants - Get irritants from error object
ErrorObjectType
error-object-type - Get type from error object
SetCar
set-car! - Mutate car of pair
SetCdr
set-cdr! - Mutate cdr of pair
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
Identifierp
identifier? - Check if value is an identifier (symbol or syntax-wrapped symbol)
BoundIdentifierEq
bound-identifier=? - Check if two identifiers have the same name and marks
FreeIdentifierEq
free-identifier=? - Check if two identifiers resolve to the same binding
SyntaxToDatum
syntax->datum - Strip syntax wrapper to get the underlying datum
SyntaxE
syntax-e - Racket-style alias for syntax->datum, extract the datum from a syntax object
DatumToSyntax
datum->syntax - Wrap a datum with syntax context from a template identifier
DatumToSyntaxObject
datum->syntax-object - R6RS alias for datum->syntax
SyntaxObjectToDatum
syntax-object->datum - R6RS alias for syntax->datum
GenerateTemporaries
generate-temporaries - Generate a list of fresh identifiers
SymbolToString
symbol->string - Convert symbol to string
StringToSymbol
string->symbol - Convert string to symbol
NumberToString
number->string - Convert number to string
StringToNumber
string->number - Convert string to number (or #f if invalid)