core

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package core provides the essential primitives required for Scheme to function.

This package registers primitives that are always included in any Wile engine:

Primitives

  • Type predicates: null?, pair?, list?, number?, string?, symbol?, etc.
  • Equality: eq?, eqv?, equal?, boolean=?, symbol=?
  • Pairs and lists: cons, car, cdr, list, append, reverse, member, assoc
  • Arithmetic: +, -, *, /, comparisons, min, max, gcd, lcm
  • Vectors: make-vector, vector-ref, vector-set!, vector->list
  • Strings: string-length, string-ref, string-append, string comparisons
  • Characters: char->integer, integer->char, char comparisons
  • Bytevectors: make-bytevector, bytevector-u8-ref, utf8->string
  • Control: apply, call/cc, values, call-with-values
  • Syntax: identifier?, syntax->datum, datum->syntax

Bootstrap Macros

The package also defines essential derived forms as syntax-rules macros: and, or, let, let*, letrec, cond, case, when, unless, guard, do, define-record-type, let-values, define-values, map, for-each.

Registration

Use Extension or AddToRegistry to register all core primitives:

reg := registry.NewRegistry()
core.AddToRegistry(reg)

Package core provides the core primitives required for Scheme to function. These primitives are always included and cannot be omitted.

Index

Constants

This section is empty.

Variables

View Source
var AddToRegistry = Builder.AddToRegistry

AddToRegistry registers all core primitives.

View Source
var Builder = registry.NewRegistryBuilder(
	addSpecialForms,
	addPredicates,
	addEquality,
	addBoolean,
	addPairs,
	addLists,
	addArithmetic,
	addControl,
	addVectors,
	addStrings,
	addCharacters,
	addBytevectors,
	addSyntax,
	addParameters,
	addPrompts,
	addBoxes,
	addHashtables,
	addBootstrapMacros,
)

Builder aggregates all core registration functions.

View Source
var Extension = registry.NewExtension("core", AddToRegistry)

Extension is the core extension containing required primitives.

View Source
var PrimBooleanQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*values.Boolean)
	return ok
})

PrimBooleanQ implements the boolean? predicate.

View Source
var PrimBytevectorQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*values.ByteVector)
	return ok
})

PrimBytevectorQ implements the bytevector? predicate.

View Source
var PrimCharQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*values.Character)
	return ok
})

PrimCharQ implements the char? predicate.

View Source
var PrimComplexQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(values.Number)
	return ok
})

PrimComplexQ implements the complex? predicate. In Scheme, all numbers are complex (complex is the top of the numeric tower).

View Source
var PrimNumberQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(values.Number)
	return ok
})

PrimNumberQ implements the number? predicate.

View Source
var PrimParameterQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*machine.Parameter)
	return ok
})

PrimParameterQ implements the parameter? predicate. Returns #t if the argument is a parameter object.

View Source
var PrimProcedureQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	switch o.(type) {
	case *machine.MachineClosure, *machine.CaseLambdaClosure:
		return true
	default:
		return false
	}
})

PrimProcedureQ implements the procedure? predicate. R7RS §6.1: Returns #t for all procedure types including case-lambda closures.

View Source
var PrimStringQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*values.String)
	return ok
})

PrimStringQ implements the string? predicate.

View Source
var PrimSymbolQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*values.Symbol)
	return ok
})

PrimSymbolQ implements the symbol? predicate.

View Source
var PrimVectorQ = helpers.MakeTypePredicate(func(o values.Value) bool {
	_, ok := o.(*values.Vector)
	return ok
})

PrimVectorQ implements the vector? predicate.

Functions

func PrimAbortCurrentContinuation

func PrimAbortCurrentContinuation(_ context.Context, mc *machine.MachineContext) error

PrimAbortCurrentContinuation aborts to the nearest prompt with the given tag.

(abort-current-continuation tag v ...)

Returns an ErrPromptAbort that propagates up through Run() to the enclosing call-with-continuation-prompt or RunWithEscapeHandling.

func PrimAbs

func PrimAbs(_ context.Context, mc *machine.MachineContext) error

PrimAbs implements the abs primitive. R7RS §6.2.6: For a complex number, abs returns its magnitude.

func PrimAdd

func PrimAdd(_ context.Context, mc *machine.MachineContext) error

PrimAdd implements the + primitive.

func PrimAppend

func PrimAppend(_ context.Context, mc *machine.MachineContext) error

PrimAppend implements (append list ...) per R7RS. Returns a list consisting of the elements of the first list followed by the elements of the other lists. The last argument may be any object.

Algorithm overview:

  1. Collect all argument lists into a vector for random access
  2. Build result from right to left, starting with the last argument as the tail
  3. For each preceding list, collect its elements into a vector, then prepend them to the result in reverse order to preserve original ordering

Why use a vector for intermediate storage (lines 1276-1290)? Lists are singly-linked and can only be efficiently traversed forward. To prepend list elements while preserving order, we need to process them in reverse. We collect elements into a vector (O(1) append), then iterate backward through the vector to prepend each element to the result. This achieves O(n) time complexity where n is total elements across all lists.

Example: (append '(a b) '(c d) '(e)) - lists vector: ['(a b), '(c d), '(e)] - Start with result = '(e) (last element) - Process '(c d): collect [c, d], prepend d then c → result = '(c d e) - Process '(a b): collect [a, b], prepend b then a → result = '(a b c d e)

func PrimApply

func PrimApply(ctx context.Context, mc *machine.MachineContext) error

PrimApply implements the apply primitive. Applies a procedure to a list of arguments.

func PrimAssoc

func PrimAssoc(_ context.Context, mc *machine.MachineContext) error

PrimAssoc implements the assoc primitive. R7RS §6.4: (assoc obj alist [compare]) Finds an entry in an alist using equal? for comparison, or a custom compare procedure.

func PrimAssq

func PrimAssq(_ context.Context, mc *machine.MachineContext) error

PrimAssq implements the assq primitive.

func PrimAssv

func PrimAssv(_ context.Context, mc *machine.MachineContext) error

PrimAssv implements the assv primitive.

func PrimBooleanEq

func PrimBooleanEq(_ context.Context, mc *machine.MachineContext) error

PrimBooleanEq implements the boolean=? primitive. R7RS §6.3: (boolean=? boolean1 boolean2 boolean3 ...) Returns #t if all arguments are booleans and all are the same value.

func PrimBoundIdentifierEqualQ

func PrimBoundIdentifierEqualQ(_ context.Context, mc *machine.MachineContext) error

PrimBoundIdentifierEqualQ implements the bound-identifier=? predicate (R7RS). Returns #t if two identifiers have the same name AND the same scope sets, meaning they would create the same binding if used as binding occurrences.

func PrimBox

func PrimBox(_ context.Context, mc *machine.MachineContext) error

PrimBox implements the box primitive. Creates a new box containing the given value.

func PrimBoxQ

func PrimBoxQ(_ context.Context, mc *machine.MachineContext) error

PrimBoxQ implements the box? predicate. Returns #t if the argument is a box, #f otherwise.

func PrimBytevector

func PrimBytevector(_ context.Context, mc *machine.MachineContext) error

PrimBytevector implements the bytevector primitive. Creates bytevector from byte arguments.

func PrimBytevectorAppend

func PrimBytevectorAppend(_ context.Context, mc *machine.MachineContext) error

PrimBytevectorAppend implements the bytevector-append primitive. Concatenates bytevectors.

func PrimBytevectorCopy

func PrimBytevectorCopy(_ context.Context, mc *machine.MachineContext) error

PrimBytevectorCopy implements the bytevector-copy primitive. Returns a copy of a bytevector.

func PrimBytevectorCopyBang

func PrimBytevectorCopyBang(_ context.Context, mc *machine.MachineContext) error

PrimBytevectorCopyBang implements the bytevector-copy! primitive. Copies bytes between bytevectors.

func PrimBytevectorLength

func PrimBytevectorLength(_ context.Context, mc *machine.MachineContext) error

PrimBytevectorLength implements the bytevector-length primitive. Returns length of bytevector.

func PrimBytevectorU8Ref

func PrimBytevectorU8Ref(_ context.Context, mc *machine.MachineContext) error

PrimBytevectorU8Ref implements the bytevector-u8-ref primitive. Returns byte at index.

func PrimBytevectorU8Set

func PrimBytevectorU8Set(_ context.Context, mc *machine.MachineContext) error

PrimBytevectorU8Set implements the bytevector-u8-set! primitive. Sets byte at index.

func PrimCaaaar

func PrimCaaaar(_ context.Context, mc *machine.MachineContext) error

PrimCaaaar implements the caaaar primitive.

func PrimCaaadr

func PrimCaaadr(_ context.Context, mc *machine.MachineContext) error

PrimCaaadr implements the caaadr primitive.

func PrimCaaar

func PrimCaaar(_ context.Context, mc *machine.MachineContext) error

PrimCaaar implements the caaar primitive.

func PrimCaadar

func PrimCaadar(_ context.Context, mc *machine.MachineContext) error

PrimCaadar implements the caadar primitive.

func PrimCaaddr

func PrimCaaddr(_ context.Context, mc *machine.MachineContext) error

PrimCaaddr implements the caaddr primitive.

func PrimCaadr

func PrimCaadr(_ context.Context, mc *machine.MachineContext) error

PrimCaadr implements the caadr primitive.

func PrimCaar

func PrimCaar(_ context.Context, mc *machine.MachineContext) error

PrimCaar implements the caar primitive.

func PrimCadaar

func PrimCadaar(_ context.Context, mc *machine.MachineContext) error

PrimCadaar implements the cadaar primitive.

func PrimCadadr

func PrimCadadr(_ context.Context, mc *machine.MachineContext) error

PrimCadadr implements the cadadr primitive.

func PrimCadar

func PrimCadar(_ context.Context, mc *machine.MachineContext) error

PrimCadar implements the cadar primitive.

func PrimCaddar

func PrimCaddar(_ context.Context, mc *machine.MachineContext) error

PrimCaddar implements the caddar primitive.

func PrimCadddr

func PrimCadddr(_ context.Context, mc *machine.MachineContext) error

PrimCadddr implements the cadddr primitive.

func PrimCaddr

func PrimCaddr(_ context.Context, mc *machine.MachineContext) error

PrimCaddr implements the caddr primitive.

func PrimCadr

func PrimCadr(_ context.Context, mc *machine.MachineContext) error

PrimCadr implements the cadr primitive.

func PrimCallCC

func PrimCallCC(ctx context.Context, mc *machine.MachineContext) error

PrimCallCC implements the call/cc primitive. Captures current continuation and passes to procedure.

R7RS §6.10: call-with-current-continuation packages the current continuation as an "escape procedure" and passes it as an argument to proc.

Two execution modes:

Inline mode (mc.Parent() != nil): The lambda runs directly in the current VM context. This preserves the full continuation chain, ensuring continuations captured inside the lambda include the complete call stack back to the top level. This is critical for cooperative coroutines and other patterns that capture/invoke multiple continuations.

Sub-context mode (mc.Parent() == nil): Falls back to running the lambda in an isolated sub-context. Used when call/cc is invoked inside another foreign function's sub-context (e.g., inside apply or dynamic-wind) where there's no saved continuation to return to.

func PrimCallWithComposableContinuation

func PrimCallWithComposableContinuation(ctx context.Context, mc *machine.MachineContext) error

PrimCallWithComposableContinuation captures a composable (delimited) continuation up to the nearest prompt with the given tag, then invokes proc with that continuation as its argument.

(call-with-composable-continuation proc tag)

The captured continuation is a ComposableContinuation value that, when applied, splices its frames onto the current continuation chain.

Follows Racket's call-with-composable-continuation.

func PrimCallWithContinuationPrompt

func PrimCallWithContinuationPrompt(ctx context.Context, mc *machine.MachineContext) error

PrimCallWithContinuationPrompt installs a continuation prompt and runs the thunk.

(call-with-continuation-prompt thunk tag handler)

The prompt frame is pushed onto the continuation chain. If the thunk aborts to this prompt's tag, the handler is invoked with the abort values. If the thunk returns normally, its value is the result.

Follows Racket's call-with-continuation-prompt.

func PrimCallWithValues

func PrimCallWithValues(ctx context.Context, mc *machine.MachineContext) error

PrimCallWithValues implements the call-with-values primitive. Calls producer, passes results to consumer.

func PrimCar

func PrimCar(_ context.Context, mc *machine.MachineContext) error

PrimCar implements the car primitive. Returns the first element of a pair.

R7RS §6.4: It is an error to take the car of the empty list.

func PrimCdaaar

func PrimCdaaar(_ context.Context, mc *machine.MachineContext) error

PrimCdaaar implements the cdaaar primitive.

func PrimCdaadr

func PrimCdaadr(_ context.Context, mc *machine.MachineContext) error

PrimCdaadr implements the cdaadr primitive.

func PrimCdaar

func PrimCdaar(_ context.Context, mc *machine.MachineContext) error

PrimCdaar implements the cdaar primitive.

func PrimCdadar

func PrimCdadar(_ context.Context, mc *machine.MachineContext) error

PrimCdadar implements the cdadar primitive.

func PrimCdaddr

func PrimCdaddr(_ context.Context, mc *machine.MachineContext) error

PrimCdaddr implements the cdaddr primitive.

func PrimCdadr

func PrimCdadr(_ context.Context, mc *machine.MachineContext) error

PrimCdadr implements the cdadr primitive.

func PrimCdar

func PrimCdar(_ context.Context, mc *machine.MachineContext) error

PrimCdar implements the cdar primitive.

func PrimCddaar

func PrimCddaar(_ context.Context, mc *machine.MachineContext) error

PrimCddaar implements the cddaar primitive.

func PrimCddadr

func PrimCddadr(_ context.Context, mc *machine.MachineContext) error

PrimCddadr implements the cddadr primitive.

func PrimCddar

func PrimCddar(_ context.Context, mc *machine.MachineContext) error

PrimCddar implements the cddar primitive.

func PrimCdddar

func PrimCdddar(_ context.Context, mc *machine.MachineContext) error

PrimCdddar implements the cdddar primitive.

func PrimCddddr

func PrimCddddr(_ context.Context, mc *machine.MachineContext) error

PrimCddddr implements the cddddr primitive.

func PrimCdddr

func PrimCdddr(_ context.Context, mc *machine.MachineContext) error

PrimCdddr implements the cdddr primitive.

func PrimCddr

func PrimCddr(_ context.Context, mc *machine.MachineContext) error

PrimCddr implements the cddr primitive.

func PrimCdr

func PrimCdr(_ context.Context, mc *machine.MachineContext) error

PrimCdr implements the cdr primitive. Returns the second element of a pair.

R7RS §6.4: It is an error to take the cdr of the empty list.

func PrimCharEqVariadic

func PrimCharEqVariadic(_ context.Context, mc *machine.MachineContext) error

PrimCharEqVariadic implements the variadic char=? primitive.

func PrimCharGeVariadic

func PrimCharGeVariadic(_ context.Context, mc *machine.MachineContext) error

PrimCharGeVariadic implements the variadic char>=? primitive.

func PrimCharGtVariadic

func PrimCharGtVariadic(_ context.Context, mc *machine.MachineContext) error

PrimCharGtVariadic implements the variadic char>? primitive.

func PrimCharLeVariadic

func PrimCharLeVariadic(_ context.Context, mc *machine.MachineContext) error

PrimCharLeVariadic implements the variadic char<=? primitive.

func PrimCharLtVariadic

func PrimCharLtVariadic(_ context.Context, mc *machine.MachineContext) error

PrimCharLtVariadic implements the variadic char<? primitive.

func PrimCharToInteger

func PrimCharToInteger(_ context.Context, mc *machine.MachineContext) error

PrimCharToInteger implements the (char->integer) primitive. Returns the Unicode code point of the character as an integer.

func PrimCons

func PrimCons(_ context.Context, mc *machine.MachineContext) error

PrimCons implements the cons primitive. Creates a new pair from the car and cdr arguments.

func PrimContinuationPromptTagQ

func PrimContinuationPromptTagQ(_ context.Context, mc *machine.MachineContext) error

PrimContinuationPromptTagQ tests whether a value is a continuation prompt tag.

func PrimDatumToSyntax

func PrimDatumToSyntax(_ context.Context, mc *machine.MachineContext) error

PrimDatumToSyntax implements the datum->syntax procedure (R6RS). Converts a datum to a syntax object using the lexical context from template-id. If template-id is #f, the datum has no lexical context.

(datum->syntax template-id datum) -> syntax-object

func PrimDefaultContinuationPromptTag

func PrimDefaultContinuationPromptTag(_ context.Context, mc *machine.MachineContext) error

PrimDefaultContinuationPromptTag returns the default continuation prompt tag.

func PrimDiv

func PrimDiv(_ context.Context, mc *machine.MachineContext) error

PrimDiv implements the / primitive.

func PrimDynamicWind

func PrimDynamicWind(ctx context.Context, mc *machine.MachineContext) error

PrimDynamicWind implements the (dynamic-wind) primitive. Calls a thunk with before and after handlers that execute on entry and exit.

R7RS §6.10: dynamic-wind calls thunk without arguments, returning the result(s). Before is called whenever execution enters the dynamic extent of the call to thunk, and after is called whenever it exits.

func PrimEqQ

func PrimEqQ(_ context.Context, mc *machine.MachineContext) error

PrimEqQ implements the eq? predicate for object identity. Returns #t if both arguments are the same object (pointer equality).

func PrimEqualQ

func PrimEqualQ(_ context.Context, mc *machine.MachineContext) error

PrimEqualQ implements the equal? predicate for structural equality. Returns #t if both arguments have the same structure and values.

func PrimEqvQ

func PrimEqvQ(_ context.Context, mc *machine.MachineContext) error

PrimEqvQ implements the eqv? predicate (R7RS). Returns #t if both arguments are operationally equivalent: - Same object (pointer equality), OR - Both are numbers of the same type with the same value, OR - Both are characters with the same value Unlike eq?, eqv? treats equivalent numbers/characters as equal even if they are different objects. Unlike equal?, eqv? does not recurse into pairs, vectors, or strings.

func PrimEvenQ

func PrimEvenQ(_ context.Context, mc *machine.MachineContext) error

PrimEvenQ implements the even? predicate.

R7RS §6.2.6: Returns #t if the integer is even, #f otherwise. Accepts any integer, including inexact integers (e.g., 4.0).

func PrimExact

func PrimExact(_ context.Context, mc *machine.MachineContext) error

PrimExact implements the (exact) primitive. Converts an inexact number to an exact representation.

R7RS §6.2.6: The exact procedure returns an exact representation of z that is numerically closest to the argument.

func PrimExactIntegerQ

func PrimExactIntegerQ(_ context.Context, mc *machine.MachineContext) error

PrimExactIntegerQ implements the exact-integer? predicate.

R7RS §6.2.6: Returns #t if the argument is both exact and an integer.

func PrimExactQ

func PrimExactQ(_ context.Context, mc *machine.MachineContext) error

PrimExactQ implements the exact? predicate.

R7RS §6.2.6: Returns #t if the number is exact, #f otherwise.

func PrimFreeIdentifierEqualQ

func PrimFreeIdentifierEqualQ(_ context.Context, mc *machine.MachineContext) error

PrimFreeIdentifierEqualQ implements the free-identifier=? predicate (R7RS). Returns #t if two identifiers would resolve to the same binding in the current environment. For unbound identifiers, returns #t if they have the same name.

func PrimGcd

func PrimGcd(_ context.Context, mc *machine.MachineContext) error

PrimGcd implements the gcd primitive.

func PrimGenerateTemporaries

func PrimGenerateTemporaries(_ context.Context, mc *machine.MachineContext) error

PrimGenerateTemporaries implements the generate-temporaries procedure (R6RS). Takes a list (or syntax list) and returns a list of fresh identifiers with the same length. Each identifier is guaranteed to be unique.

(generate-temporaries stx-list) -> list of identifiers

func PrimHashtableClear

func PrimHashtableClear(_ context.Context, mc *machine.MachineContext) error

PrimHashtableClear implements the hashtable-clear! primitive. Removes all entries from the hash table.

func PrimHashtableCopy

func PrimHashtableCopy(_ context.Context, mc *machine.MachineContext) error

PrimHashtableCopy implements the hashtable-copy primitive. Returns a shallow copy of the hash table.

func PrimHashtableDelete

func PrimHashtableDelete(_ context.Context, mc *machine.MachineContext) error

PrimHashtableDelete implements the hashtable-delete! primitive. (hashtable-delete! ht key)

func PrimHashtableKeys

func PrimHashtableKeys(_ context.Context, mc *machine.MachineContext) error

PrimHashtableKeys implements the hashtable-keys primitive. Returns a list of all keys in the hash table.

func PrimHashtableQ

func PrimHashtableQ(_ context.Context, mc *machine.MachineContext) error

PrimHashtableQ implements the hashtable? predicate. Returns #t if the argument is a hash table, #f otherwise.

func PrimHashtableRef

func PrimHashtableRef(_ context.Context, mc *machine.MachineContext) error

PrimHashtableRef implements the hashtable-ref primitive. (hashtable-ref ht key) — errors if key is missing. (hashtable-ref ht key default) — returns default if key is missing.

func PrimHashtableSet

func PrimHashtableSet(_ context.Context, mc *machine.MachineContext) error

PrimHashtableSet implements the hashtable-set! primitive. (hashtable-set! ht key value)

func PrimHashtableSize

func PrimHashtableSize(_ context.Context, mc *machine.MachineContext) error

PrimHashtableSize implements the hashtable-size primitive. Returns the number of entries in the hash table.

func PrimHashtableValues

func PrimHashtableValues(_ context.Context, mc *machine.MachineContext) error

PrimHashtableValues implements the hashtable-values primitive. Returns a list of all values in the hash table.

func PrimIdentifierQ

func PrimIdentifierQ(_ context.Context, mc *machine.MachineContext) error

PrimIdentifierQ implements the identifier? predicate (R6RS). Returns #t if the argument is a syntax object representing an identifier.

func PrimInexact

func PrimInexact(_ context.Context, mc *machine.MachineContext) error

PrimInexact implements the (inexact) primitive. Converts exact number to inexact.

R7RS §6.2.6: The inexact procedure returns an inexact representation of z that is numerically closest to the argument.

func PrimInexactQ

func PrimInexactQ(_ context.Context, mc *machine.MachineContext) error

PrimInexactQ implements the inexact? predicate.

R7RS §6.2.6: Returns #t if the number is inexact, #f otherwise.

func PrimIntegerQ

func PrimIntegerQ(_ context.Context, mc *machine.MachineContext) error

PrimIntegerQ implements the integer? predicate.

R7RS §6.2.6: Returns #t if the argument is an integer (exact or inexact). Inexact integers are floating-point numbers with zero fractional part.

func PrimIntegerToChar

func PrimIntegerToChar(_ context.Context, mc *machine.MachineContext) error

PrimIntegerToChar implements the (integer->char) primitive. Converts a Unicode code point (integer) to a character.

R7RS §6.6: The argument must be a valid Unicode scalar value, i.e., an integer in [0, #xD7FF] ∪ [#xE000, #x10FFFF].

func PrimLcm

func PrimLcm(_ context.Context, mc *machine.MachineContext) error

PrimLcm implements the lcm primitive.

func PrimLength

func PrimLength(_ context.Context, mc *machine.MachineContext) error

PrimLength implements the (length) primitive. Returns the length of a proper list.

func PrimList

func PrimList(_ context.Context, mc *machine.MachineContext) error

PrimList implements the (list) primitive. Creates a list from the given arguments.

func PrimListCopy

func PrimListCopy(_ context.Context, mc *machine.MachineContext) error

PrimListCopy implements the list-copy primitive. R7RS §6.4: (list-copy obj) Returns a newly allocated copy of obj if it is a list. Only the pairs are copied; the car elements are shared.

func PrimListQ

func PrimListQ(_ context.Context, mc *machine.MachineContext) error

PrimListQ implements the list? predicate. Returns #t if the argument is a proper list, #f otherwise.

func PrimListRef

func PrimListRef(_ context.Context, mc *machine.MachineContext) error

PrimListRef implements the (list-ref) primitive. Returns the element at the given index in a list. R7RS §6.4: The index must be an exact non-negative integer.

func PrimListSet

func PrimListSet(_ context.Context, mc *machine.MachineContext) error

PrimListSet implements the Scheme list-set! primitive. R7RS §6.4: The index must be an exact non-negative integer.

func PrimListTail

func PrimListTail(_ context.Context, mc *machine.MachineContext) error

PrimListTail implements the (list-tail) primitive. Returns the sublist starting at the given index. R7RS §6.4: The index must be an exact non-negative integer.

func PrimListToString

func PrimListToString(_ context.Context, mc *machine.MachineContext) error

PrimListToString implements the (list->string) primitive. Converts a list of characters to a string.

func PrimListToVector

func PrimListToVector(_ context.Context, mc *machine.MachineContext) error

PrimListToVector implements the list->vector primitive.

func PrimMakeBytevector

func PrimMakeBytevector(_ context.Context, mc *machine.MachineContext) error

PrimMakeBytevector implements the (make-bytevector) primitive. Creates a bytevector of the given size, optionally filled with a specified byte value.

func PrimMakeContinuationPromptTag

func PrimMakeContinuationPromptTag(_ context.Context, mc *machine.MachineContext) error

PrimMakeContinuationPromptTag creates a new continuation prompt tag. With no arguments, creates an anonymous tag. With one argument (a symbol), creates a named tag for debugging purposes.

Follows Racket's make-continuation-prompt-tag.

func PrimMakeHashtable

func PrimMakeHashtable(_ context.Context, mc *machine.MachineContext) error

PrimMakeHashtable implements the make-hashtable primitive. Creates a new empty hash table.

func PrimMakeList

func PrimMakeList(_ context.Context, mc *machine.MachineContext) error

PrimMakeList implements the Scheme make-list primitive.

func PrimMakeParameter

func PrimMakeParameter(ctx context.Context, mc *machine.MachineContext) error

PrimMakeParameter implements the (make-parameter) primitive. Creates a parameter object with an initial value and optional converter.

(make-parameter init) ; create with initial value (make-parameter init converter) ; create with converter procedure

If a converter is provided, it is applied to the initial value and to any value passed when setting the parameter.

func PrimMakeString

func PrimMakeString(_ context.Context, mc *machine.MachineContext) error

PrimMakeString implements the make-string primitive. (make-string k) creates a string of k unspecified characters. (make-string k char) creates a string of k copies of char.

func PrimMakeVector

func PrimMakeVector(_ context.Context, mc *machine.MachineContext) error

PrimMakeVector implements the (make-vector) primitive. Creates a vector of the given size, optionally filled with a specified value.

func PrimMax

func PrimMax(_ context.Context, mc *machine.MachineContext) error

PrimMax implements the max primitive.

func PrimMember

func PrimMember(_ context.Context, mc *machine.MachineContext) error

PrimMember implements the member primitive. R7RS §6.4: (member obj list [compare]) Finds an element in a list using equal? for comparison, or a custom compare procedure.

func PrimMemq

func PrimMemq(_ context.Context, mc *machine.MachineContext) error

PrimMemq implements the memq primitive. Finds an element in a list using eq? for comparison.

func PrimMemv

func PrimMemv(_ context.Context, mc *machine.MachineContext) error

PrimMemv implements the memv primitive. Finds an element in a list using eqv? for comparison.

func PrimMin

func PrimMin(_ context.Context, mc *machine.MachineContext) error

PrimMin implements the min primitive.

func PrimModulo

func PrimModulo(_ context.Context, mc *machine.MachineContext) error

PrimModulo implements the modulo primitive. Returns the modulo of two integers with the sign of the divisor. Accepts exact and inexact integers per R7RS.

func PrimMul

func PrimMul(_ context.Context, mc *machine.MachineContext) error

PrimMul implements the * primitive.

func PrimNegativeQ

func PrimNegativeQ(_ context.Context, mc *machine.MachineContext) error

PrimNegativeQ implements the negative? predicate.

R7RS §6.2.6: Returns #t if the real number is negative.

func PrimNot

func PrimNot(_ context.Context, mc *machine.MachineContext) error

PrimNot implements the not primitive. Returns #t if the argument is #f, #f otherwise.

func PrimNullQ

func PrimNullQ(_ context.Context, mc *machine.MachineContext) error

PrimNullQ implements the null? predicate. Returns #t if the argument is the empty list '().

func PrimNumEq

func PrimNumEq(_ context.Context, mc *machine.MachineContext) error

PrimNumEq implements the = primitive.

R7RS §6.2.6: Returns #t if its arguments are numerically equal.

func PrimNumGe

func PrimNumGe(_ context.Context, mc *machine.MachineContext) error

PrimNumGe implements the >= primitive.

R7RS §6.2.6: Returns #t if its arguments are monotonically nonincreasing. IEEE 754: Any comparison with NaN returns #f.

func PrimNumGt

func PrimNumGt(_ context.Context, mc *machine.MachineContext) error

PrimNumGt implements the > primitive.

R7RS §6.2.6: Ordering comparisons require real arguments.

func PrimNumLe

func PrimNumLe(_ context.Context, mc *machine.MachineContext) error

PrimNumLe implements the <= primitive.

R7RS §6.2.6: Returns #t if its arguments are monotonically nondecreasing. IEEE 754: Any comparison with NaN returns #f.

func PrimNumLt

func PrimNumLt(_ context.Context, mc *machine.MachineContext) error

PrimNumLt implements the < primitive.

R7RS §6.2.6: Ordering comparisons require real arguments.

func PrimOddQ

func PrimOddQ(_ context.Context, mc *machine.MachineContext) error

PrimOddQ implements the odd? predicate.

R7RS §6.2.6: Returns #t if the integer is odd, #f otherwise. Accepts any integer, including inexact integers (e.g., 3.0).

func PrimPairQ

func PrimPairQ(_ context.Context, mc *machine.MachineContext) error

PrimPairQ implements the pair? predicate. Returns #t if the argument is a pair (cons cell).

func PrimPositiveQ

func PrimPositiveQ(_ context.Context, mc *machine.MachineContext) error

PrimPositiveQ implements the positive? predicate.

R7RS §6.2.6: Returns #t if the real number is positive.

func PrimQuotient

func PrimQuotient(_ context.Context, mc *machine.MachineContext) error

PrimQuotient implements the (quotient) primitive. Returns truncated integer quotient. Accepts exact and inexact integers per R7RS.

func PrimRationalQ

func PrimRationalQ(_ context.Context, mc *machine.MachineContext) error

PrimRationalQ implements the rational? predicate.

R7RS §6.2.6: Returns #t if the argument is a rational number. Integers (including BigInteger) are a subset of rationals.

func PrimRealQ

func PrimRealQ(_ context.Context, mc *machine.MachineContext) error

PrimRealQ implements the real? predicate.

R7RS §6.2.6: Returns #t if the argument is a real number. Rationals (including integers and BigInteger) are a subset of reals.

func PrimRemainder

func PrimRemainder(_ context.Context, mc *machine.MachineContext) error

PrimRemainder implements the (remainder) primitive. Returns remainder with sign of dividend. Accepts exact and inexact integers per R7RS.

func PrimReverse

func PrimReverse(_ context.Context, mc *machine.MachineContext) error

PrimReverse implements the (reverse) primitive. Returns reversed copy of list.

func PrimSetBox

func PrimSetBox(_ context.Context, mc *machine.MachineContext) error

PrimSetBox implements the set-box! primitive. Sets the value contained in a box.

func PrimSetCar

func PrimSetCar(_ context.Context, mc *machine.MachineContext) error

PrimSetCar implements the set-car! primitive.

func PrimSetCdr

func PrimSetCdr(_ context.Context, mc *machine.MachineContext) error

PrimSetCdr implements the set-cdr! primitive.

func PrimString

func PrimString(_ context.Context, mc *machine.MachineContext) error

PrimString implements the string primitive. (string char ...) returns a newly allocated string composed of the given characters.

func PrimStringAppend

func PrimStringAppend(_ context.Context, mc *machine.MachineContext) error

PrimStringAppend implements the (string-append) primitive. Concatenates strings.

func PrimStringCopy

func PrimStringCopy(_ context.Context, mc *machine.MachineContext) error

PrimStringCopy implements the string-copy primitive. R7RS §6.7: (string-copy string [start [end]]) Returns a newly allocated copy of the given string (or substring). The returned string is mutable and distinct from the original.

func PrimStringEqVariadic

func PrimStringEqVariadic(_ context.Context, mc *machine.MachineContext) error

PrimStringEqVariadic implements the variadic string=? primitive.

func PrimStringGeVariadic

func PrimStringGeVariadic(_ context.Context, mc *machine.MachineContext) error

PrimStringGeVariadic implements the variadic string>=? primitive.

func PrimStringGtVariadic

func PrimStringGtVariadic(_ context.Context, mc *machine.MachineContext) error

PrimStringGtVariadic implements the variadic string>? primitive.

func PrimStringLeVariadic

func PrimStringLeVariadic(_ context.Context, mc *machine.MachineContext) error

PrimStringLeVariadic implements the variadic string<=? primitive.

func PrimStringLength

func PrimStringLength(_ context.Context, mc *machine.MachineContext) error

PrimStringLength implements string-length. Returns the number of characters (runes) in the string.

func PrimStringLtVariadic

func PrimStringLtVariadic(_ context.Context, mc *machine.MachineContext) error

PrimStringLtVariadic implements the variadic string<? primitive.

func PrimStringRef

func PrimStringRef(_ context.Context, mc *machine.MachineContext) error

PrimStringRef implements the string-ref primitive. Returns the character at the given index in the string.

func PrimStringSet

func PrimStringSet(_ context.Context, mc *machine.MachineContext) error

PrimStringSet implements the string-set! primitive. Stores char in element k of string. R7RS §6.7: (string-set! string k char)

func PrimStringToList

func PrimStringToList(_ context.Context, mc *machine.MachineContext) error

PrimStringToList implements the string->list primitive. R7RS §6.7: (string->list string [start [end]]) Converts a string (or substring) to a list of characters.

func PrimStringToSymbol

func PrimStringToSymbol(_ context.Context, mc *machine.MachineContext) error

PrimStringToSymbol implements the string->symbol primitive. Converts a string to an interned symbol.

func PrimStringToUtf8

func PrimStringToUtf8(_ context.Context, mc *machine.MachineContext) error

PrimStringToUtf8 implements the string->utf8 primitive. Converts a string to a UTF-8 encoded bytevector with optional start and end indices.

func PrimStringToVector

func PrimStringToVector(_ context.Context, mc *machine.MachineContext) error

PrimStringToVector implements the string->vector primitive. R7RS §6.8: (string->vector string [start [end]]) Returns a vector containing the characters of string between start and end.

func PrimSub

func PrimSub(_ context.Context, mc *machine.MachineContext) error

PrimSub implements the - primitive.

func PrimSubstring

func PrimSubstring(_ context.Context, mc *machine.MachineContext) error

PrimSubstring implements the substring primitive. Returns a substring between the given start and end indices.

func PrimSymbolEq

func PrimSymbolEq(_ context.Context, mc *machine.MachineContext) error

PrimSymbolEq implements the symbol=? primitive. R7RS §6.5: (symbol=? symbol1 symbol2 symbol3 ...) Returns #t if all arguments are symbols and all are the same symbol.

func PrimSymbolToString

func PrimSymbolToString(_ context.Context, mc *machine.MachineContext) error

PrimSymbolToString implements the symbol->string primitive. Converts a symbol to a string.

func PrimSyntaxToDatum

func PrimSyntaxToDatum(_ context.Context, mc *machine.MachineContext) error

PrimSyntaxToDatum implements the syntax->datum procedure (R6RS). Recursively unwraps a syntax object to its underlying datum, stripping all lexical context information.

func PrimUnbox

func PrimUnbox(_ context.Context, mc *machine.MachineContext) error

PrimUnbox implements the unbox primitive. Returns the value contained in a box.

func PrimUtf8ToString

func PrimUtf8ToString(_ context.Context, mc *machine.MachineContext) error

PrimUtf8ToString implements the utf8->string primitive. Converts a UTF-8 encoded bytevector to a string with optional start and end indices.

func PrimValues

func PrimValues(_ context.Context, mc *machine.MachineContext) error

PrimValues implements the values primitive. Returns multiple values as specified by R7RS. With no arguments returns no values. With one or more arguments, returns all arguments as multiple values.

func PrimVector

func PrimVector(_ context.Context, mc *machine.MachineContext) error

PrimVector implements the vector primitive.

func PrimVectorAppend

func PrimVectorAppend(_ context.Context, mc *machine.MachineContext) error

PrimVectorAppend implements the vector-append primitive. R7RS §6.8: (vector-append vector ...) Returns a newly allocated vector whose elements are the concatenation of the elements of the given vectors.

func PrimVectorCopy

func PrimVectorCopy(_ context.Context, mc *machine.MachineContext) error

PrimVectorCopy implements the vector-copy primitive. R7RS §6.8: (vector-copy vector [start [end]]) Returns a newly allocated copy of the elements of vector between start and end.

func PrimVectorCopyTo

func PrimVectorCopyTo(_ context.Context, mc *machine.MachineContext) error

PrimVectorCopyTo implements the vector-copy! primitive. R7RS §6.8: (vector-copy! to at from [start [end]]) Copies elements from vector from to vector to, starting at index at in to.

func PrimVectorFill

func PrimVectorFill(_ context.Context, mc *machine.MachineContext) error

PrimVectorFill implements the vector-fill! primitive. R7RS §6.8: (vector-fill! vector fill [start [end]]) Sets the elements of vector between start and end to fill.

func PrimVectorForEach

func PrimVectorForEach(_ context.Context, mc *machine.MachineContext) error

PrimVectorForEach implements the vector-for-each primitive. R7RS §6.8: (vector-for-each proc vector1 vector2 ...) Applies proc element-wise to the vectors for side effects.

func PrimVectorLength

func PrimVectorLength(_ context.Context, mc *machine.MachineContext) error

PrimVectorLength implements the vector-length primitive. Returns the number of elements in a vector as an integer.

func PrimVectorMap

func PrimVectorMap(_ context.Context, mc *machine.MachineContext) error

PrimVectorMap implements the vector-map primitive. R7RS §6.8: (vector-map proc vector1 vector2 ...) Returns a new vector containing the results of applying proc element-wise to the vectors.

func PrimVectorRef

func PrimVectorRef(_ context.Context, mc *machine.MachineContext) error

PrimVectorRef implements the vector-ref primitive. Returns the element of a vector at the given index. R7RS §6.8: The index must be an exact non-negative integer.

func PrimVectorSet

func PrimVectorSet(_ context.Context, mc *machine.MachineContext) error

PrimVectorSet implements the vector-set! primitive. Sets the element of a vector at the given index to a new value. R7RS §6.8: The index must be an exact non-negative integer.

func PrimVectorToList

func PrimVectorToList(_ context.Context, mc *machine.MachineContext) error

PrimVectorToList implements the vector->list primitive. R7RS §6.8: (vector->list vector [start [end]]) Converts a vector (or subvector) to a list with the same elements in the same order.

func PrimVectorToString

func PrimVectorToString(_ context.Context, mc *machine.MachineContext) error

PrimVectorToString implements the vector->string primitive. R7RS §6.8: (vector->string vector [start [end]]) Returns a string constructed from the characters in vector between start and end.

func PrimVoidQ

func PrimVoidQ(_ context.Context, mc *machine.MachineContext) error

PrimVoidQ implements the void? predicate. Returns #t if the argument is the void value.

func PrimZeroQ

func PrimZeroQ(_ context.Context, mc *machine.MachineContext) error

PrimZeroQ implements the zero? predicate. Returns #t if the number is zero, #f otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL