Skip to main content

Builtin

Enum Builtin 

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

  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

§

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)

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

Source

pub fn from_usize(n: usize) -> Builtin

Convert from usize discriminant (for continuation data stack encoding) Returns the first builtin if out of range.

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.