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?, number?, string?, symbol?, etc.
- Equality: eq?, eqv?, equal?
- Pairs and lists: cons, car, cdr, list, append, reverse
- 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 ¶
- Variables
- func PrimAbortCurrentContinuation(mc machine.CallContext) error
- func PrimAbs(mc machine.CallContext) error
- func PrimAdd(mc machine.CallContext) error
- func PrimAppend(mc machine.CallContext) error
- func PrimApply(cc machine.CallContext) error
- func PrimApropos(mc machine.CallContext) error
- func PrimAssq(mc machine.CallContext) error
- func PrimAssv(mc machine.CallContext) error
- func PrimBoundIdentifierEqualQ(mc machine.CallContext) error
- func PrimBox(mc machine.CallContext) error
- func PrimBytevector(mc machine.CallContext) error
- func PrimBytevectorAppend(mc machine.CallContext) error
- func PrimBytevectorCopy(mc machine.CallContext) error
- func PrimBytevectorCopyBang(mc machine.CallContext) error
- func PrimBytevectorLength(mc machine.CallContext) error
- func PrimBytevectorU8Ref(mc machine.CallContext) error
- func PrimBytevectorU8Set(mc machine.CallContext) error
- func PrimCallCC(cc machine.CallContext) error
- func PrimCallWithComposableContinuation(cc machine.CallContext) error
- func PrimCallWithContinuationBarrier(cc machine.CallContext) error
- func PrimCallWithContinuationPrompt(cc machine.CallContext) error
- func PrimCallWithExit(cc machine.CallContext) error
- func PrimCallWithImmediateContMark(cc machine.CallContext) error
- func PrimCallWithValues(cc machine.CallContext) error
- func PrimCar(mc machine.CallContext) error
- func PrimCdr(mc machine.CallContext) error
- func PrimCharToInteger(mc machine.CallContext) error
- func PrimCons(mc machine.CallContext) error
- func PrimContinuationMarkSetFirst(mc machine.CallContext) error
- func PrimContinuationMarkSetToList(mc machine.CallContext) error
- func PrimContinuationMarkSetToListStar(mc machine.CallContext) error
- func PrimContinuationMarks(mc machine.CallContext) error
- func PrimContinuationPromptAvailableQ(cc machine.CallContext) error
- func PrimCurrentContinuationMarks(cc machine.CallContext) error
- func PrimCurrentErrorContext(cc machine.CallContext) error
- func PrimDatumToSyntax(mc machine.CallContext) error
- func PrimDefaultContinuationPromptTag(mc machine.CallContext) error
- func PrimDiv(mc machine.CallContext) error
- func PrimDocTopic(mc machine.CallContext) error
- func PrimDocTopics(mc machine.CallContext) error
- func PrimError(cc machine.CallContext) error
- func PrimErrorContextMarks(mc machine.CallContext) error
- func PrimErrorContextSource(mc machine.CallContext) error
- func PrimErrorContextStackTrace(mc machine.CallContext) error
- func PrimErrorObjectQ(mc machine.CallContext) error
- func PrimErrorObjectSource(mc machine.CallContext) error
- func PrimErrorObjectStackTrace(mc machine.CallContext) error
- func PrimEvenQ(mc machine.CallContext) error
- func PrimExact(mc machine.CallContext) error
- func PrimExceptionHandlerParameter(cc machine.CallContext) error
- func PrimFileErrorQ(mc machine.CallContext) error
- func PrimFreeIdentifierEqualQ(mc machine.CallContext) error
- func PrimGcd(mc machine.CallContext) error
- func PrimGenerateTemporaries(mc machine.CallContext) error
- func PrimHashtableDelete(mc machine.CallContext) error
- func PrimHashtableRef(mc machine.CallContext) error
- func PrimHashtableSet(mc machine.CallContext) error
- func PrimIdentifierQ(mc machine.CallContext) error
- func PrimInexact(mc machine.CallContext) error
- func PrimIntegerQ(mc machine.CallContext) error
- func PrimIntegerToChar(mc machine.CallContext) error
- func PrimLcm(mc machine.CallContext) error
- func PrimLength(mc machine.CallContext) error
- func PrimLibraryDescription(mc machine.CallContext) error
- func PrimList(mc machine.CallContext) error
- func PrimListCopy(mc machine.CallContext) error
- func PrimListRef(mc machine.CallContext) error
- func PrimListSet(mc machine.CallContext) error
- func PrimListTail(mc machine.CallContext) error
- func PrimListToString(mc machine.CallContext) error
- func PrimListToVector(mc machine.CallContext) error
- func PrimMakeBytevector(mc machine.CallContext) error
- func PrimMakeContinuationPromptTag(mc machine.CallContext) error
- func PrimMakeHashtable(mc machine.CallContext) error
- func PrimMakeList(mc machine.CallContext) error
- func PrimMakeParameter(cc machine.CallContext) error
- func PrimMakeString(mc machine.CallContext) error
- func PrimMakeVector(mc machine.CallContext) error
- func PrimMax(mc machine.CallContext) error
- func PrimMemq(mc machine.CallContext) error
- func PrimMemv(mc machine.CallContext) error
- func PrimMin(mc machine.CallContext) error
- func PrimModulo(mc machine.CallContext) error
- func PrimMul(mc machine.CallContext) error
- func PrimNullQ(mc machine.CallContext) error
- func PrimNumEq(mc machine.CallContext) error
- func PrimNumGe(mc machine.CallContext) error
- func PrimNumGt(mc machine.CallContext) error
- func PrimNumLe(mc machine.CallContext) error
- func PrimNumLt(mc machine.CallContext) error
- func PrimOddQ(mc machine.CallContext) error
- func PrimPairQ(mc machine.CallContext) error
- func PrimParameterConvert(cc machine.CallContext) error
- func PrimParameterRawSet(mc machine.CallContext) error
- func PrimPrimitiveSpecCategory(mc machine.CallContext) error
- func PrimPrimitiveSpecGoFunction(mc machine.CallContext) error
- func PrimPrimitiveSpecGoSource(mc machine.CallContext) error
- func PrimPrimitiveSpecName(mc machine.CallContext) error
- func PrimPrimitiveSpecParamCount(mc machine.CallContext) error
- func PrimPrimitiveSpecQ(mc machine.CallContext) error
- func PrimPrimitiveSpecReturnType(mc machine.CallContext) error
- func PrimPrimitiveSpecVariadicQ(mc machine.CallContext) error
- func PrimProcedureArity(mc machine.CallContext) error
- func PrimProcedureBoundSymbols(mc machine.CallContext) error
- func PrimProcedureDocumentation(mc machine.CallContext) error
- func PrimProcedureName(mc machine.CallContext) error
- func PrimProcedureSourceLocation(mc machine.CallContext) error
- func PrimProcedureType(mc machine.CallContext) error
- func PrimQuotient(mc machine.CallContext) error
- func PrimRaise(cc machine.CallContext) error
- func PrimRaiseContinuable(cc machine.CallContext) error
- func PrimRationalQ(mc machine.CallContext) error
- func PrimReadErrorQ(mc machine.CallContext) error
- func PrimRealQ(mc machine.CallContext) error
- func PrimRegisteredPrimitives(mc machine.CallContext) error
- func PrimRemainder(mc machine.CallContext) error
- func PrimReverse(mc machine.CallContext) error
- func PrimSetCar(mc machine.CallContext) error
- func PrimSetCdr(mc machine.CallContext) error
- func PrimString(mc machine.CallContext) error
- func PrimStringAppend(mc machine.CallContext) error
- func PrimStringCopy(mc machine.CallContext) error
- func PrimStringLength(mc machine.CallContext) error
- func PrimStringRef(mc machine.CallContext) error
- func PrimStringSet(mc machine.CallContext) error
- func PrimStringToList(mc machine.CallContext) error
- func PrimStringToSymbol(mc machine.CallContext) error
- func PrimStringToUtf8(mc machine.CallContext) error
- func PrimStringToVector(mc machine.CallContext) error
- func PrimSub(mc machine.CallContext) error
- func PrimSubstring(mc machine.CallContext) error
- func PrimSymbolToString(mc machine.CallContext) error
- func PrimSyntaxSource(mc machine.CallContext) error
- func PrimSyntaxSpan(mc machine.CallContext) error
- func PrimSyntaxToDatum(mc machine.CallContext) error
- func PrimSyntaxToList(mc machine.CallContext) error
- func PrimUtf8ToString(mc machine.CallContext) error
- func PrimValues(mc machine.CallContext) error
- func PrimVector(mc machine.CallContext) error
- func PrimVectorAppend(mc machine.CallContext) error
- func PrimVectorCopy(mc machine.CallContext) error
- func PrimVectorCopyTo(mc machine.CallContext) error
- func PrimVectorFill(mc machine.CallContext) error
- func PrimVectorLength(mc machine.CallContext) error
- func PrimVectorRef(mc machine.CallContext) error
- func PrimVectorSet(mc machine.CallContext) error
- func PrimVectorToList(mc machine.CallContext) error
- func PrimVectorToString(mc machine.CallContext) error
- func PrimVoidQ(mc machine.CallContext) error
- func PrimWithTimeout(cc machine.CallContext) error
Constants ¶
This section is empty.
Variables ¶
var AddToRegistry = Builder.AddToRegistry
AddToRegistry registers all core primitives.
var BootstrapFS embed.FS
BootstrapFS embeds the two bootstrap sources. bootstrap.scm is retained on disk as documentation of load order (it (include)s both files) but is no longer registered as a source — the two files are registered directly through separate channels so they target different frames. The embedded FS is still passed to an EmbedFileResolver so any (include ...) directives resolve.
var Builder = registry.NewRegistryBuilder(
addSpecialForms,
addPredicates,
addEquality,
addPairs,
addLists,
addArithmetic,
addControl,
addReflection,
addVectors,
addStrings,
addCharacters,
addBytevectors,
addSyntax,
addSyntaxLoc,
addParameters,
addPrompts,
addBoxes,
addOpaque,
addHashtables,
addExceptions,
addContMarks,
addTimer,
addBootstrapSources,
)
Builder aggregates all core registration functions.
ADDING A NEW CORE PRIMITIVE requires updates in these locations:
- registry/core/<category>.go — add PrimitiveSpec to the appropriate addXxx function
- registry/core/prim_<category>.go — implement the ForeignFunction
- registry/core/register.go — add addXxx to Builder (only if creating a new category)
- registry/core/prim_<category>_test.go — add table-driven tests
If the primitive invokes a Scheme procedure (its Impl reaches ApplyCallable or runs a sub-context), it MUST set InvokesProcedure:true on its PrimitiveSpec — see the field doc in registry/registry.go. TestInvokesProcedureStaticGuard (pkg/wile) fails CI if the annotation is missing.
var Extension = registry.NewExtension("core", AddToRegistry)
Extension is the core extension containing required primitives.
var ImmutableVectorStringMapSource string
var MutableVectorStringMapSource string
MutableVectorStringMapSource and ImmutableVectorStringMapSource are the two interchangeable bootstrap fragments defining vector-map and string-map — the one bootstrap procedure that depends on a mutation primitive. The default (Mutable) fills a fresh result in place with vector-set! / string-set! (fastest); the Immutable one builds it functionally (list->vector / list->string over map) and depends on no mutator. addBootstrapSources registers the Mutable one, so every engine is unchanged by default; a no-mutation dialect swaps it for the Immutable one (matching by value in the registry's procedure sources), which lets the mutation primitives be removed entirely. This is the sole seam where a dialect substitutes a mutation-dependent bootstrap procedure.
var PrimBooleanQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Boolean) return ok })
PrimBooleanQ implements the boolean? predicate.
var PrimBoxQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Box) return ok })
PrimBoxQ implements the box? predicate. Returns #t if the argument is a box, #f otherwise.
var PrimBytevectorQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.ByteVector) return ok })
PrimBytevectorQ implements the bytevector? predicate.
var PrimCharQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Character) return ok })
PrimCharQ implements the char? predicate.
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).
var PrimContinuationMarkSetQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*machine.ContinuationMarkSet) return ok })
PrimContinuationMarkSetQ implements (continuation-mark-set? obj).
var PrimContinuationPromptTagQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*machine.PromptTag) return ok })
PrimContinuationPromptTagQ tests whether a value is a continuation prompt tag.
var PrimContinuationQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*machine.CapturedContinuation) return ok })
PrimContinuationQ implements (continuation? obj).
var PrimEqQ = makeBinaryPredicate(helpers.EqIdentity)
PrimEqQ implements the eq? predicate (R7RS §6.1). Returns #t if both arguments are identical: pointer equality for most types, string key comparison for symbols (R7RS §6.5).
var PrimEqualQ = makeBinaryPredicate(values.EqualTo)
PrimEqualQ implements the equal? predicate for structural equality. Returns #t if both arguments have the same structure and values.
var PrimEqvQ = makeBinaryPredicate(helpers.Eqv)
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.
var PrimErrorContextQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*machine.ErrorContext) return ok })
PrimErrorContextQ implements (error-context? obj). Returns #t if obj is an ErrorContext value.
var PrimErrorObjectIrritants = helpers.MakeUnaryAccessor(werr.ErrNotANativeError, "error-object-irritants", func(errObj *values.NativeError) values.Value {
return errObj.Irritants()
})
PrimErrorObjectIrritants implements the error-object-irritants accessor. Returns the list of irritant objects from an error object.
var PrimErrorObjectMessage = helpers.MakeUnaryAccessor(werr.ErrNotANativeError, "error-object-message", func(errObj *values.NativeError) values.Value {
return errObj.Message()
})
PrimErrorObjectMessage implements the error-object-message accessor. Returns the message string from an error object.
var PrimExactQ = helpers.MakeNumericPredicate[values.Number]( "exact?", werr.ErrNotANumber, values.Number.IsExact, )
PrimExactQ implements the exact? predicate.
R7RS §6.2.6: Returns #t if the number is exact, #f otherwise.
var PrimHashtableClear = helpers.MakeUnarySideEffect(werr.ErrNotAHashtable, "hashtable-clear!", func(ht *values.Hashtable) {
ht.Clear()
})
PrimHashtableClear implements the hashtable-clear! primitive. Removes all entries from the hash table.
var PrimHashtableCopy = helpers.MakeUnaryAccessor(werr.ErrNotAHashtable, "hashtable-copy", func(ht *values.Hashtable) values.Value {
return ht.Copy()
})
PrimHashtableCopy implements the hashtable-copy primitive. Returns a shallow copy of the hash table.
var PrimHashtableKeys = helpers.MakeUnaryAccessor(werr.ErrNotAHashtable, "hashtable-keys", func(ht *values.Hashtable) values.Value {
return ht.Keys()
})
PrimHashtableKeys implements the hashtable-keys primitive. Returns a list of all keys in the hash table.
var PrimHashtableQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Hashtable) return ok })
PrimHashtableQ implements the hashtable? predicate. Returns #t if the argument is a hash table, #f otherwise.
var PrimHashtableSize = helpers.MakeUnaryAccessor(werr.ErrNotAHashtable, "hashtable-size", func(ht *values.Hashtable) values.Value { return values.NewInteger(int64(ht.Size())) })
PrimHashtableSize implements the hashtable-size primitive. Returns the number of entries in the hash table.
var PrimHashtableValues = helpers.MakeUnaryAccessor(werr.ErrNotAHashtable, "hashtable-values", func(ht *values.Hashtable) values.Value {
return ht.Values()
})
PrimHashtableValues implements the hashtable-values primitive. Returns a list of all values in the hash table.
var PrimInexactQ = helpers.MakeNumericPredicate[values.Number]( "inexact?", werr.ErrNotANumber, func(n values.Number) bool { return !n.IsExact() }, )
PrimInexactQ implements the inexact? predicate.
R7RS §6.2.6: Returns #t if the number is inexact, #f otherwise.
var PrimNumberQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(values.Number) return ok })
PrimNumberQ implements the number? predicate.
var PrimOpaqueQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.OpaqueValue) return ok })
PrimOpaqueQ implements the opaque? predicate. Returns #t if the argument is an OpaqueValue.
var PrimOpaqueTag = helpers.MakeUnaryAccessor(werr.ErrNotAnOpaqueValue, "opaque-tag", func(o *values.OpaqueValue) values.Value { return values.NewSymbol(o.OpaqueTag()) })
PrimOpaqueTag implements the opaque-tag primitive. Returns the tag of an opaque value as a symbol.
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.
var PrimProcedureQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(values.Callable) return ok })
PrimProcedureQ implements the procedure? predicate. R7RS §6.1: Returns #t for all callable types — lambdas, case-lambdas, parameter objects (R7RS §4.2.6), and composable continuations.
var PrimSetBox = helpers.MakeBinarySetter(werr.ErrNotABox, "set-box!", func(b *values.Box, val values.Value) {
b.Value = val
})
PrimSetBox implements the set-box! primitive. Sets the value contained in a box.
var PrimStringQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.String) return ok })
PrimStringQ implements the string? predicate.
var PrimSymbolQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Symbol) return ok })
PrimSymbolQ implements the symbol? predicate.
var PrimSyntaxColumn = makeSyntaxLocAccessor("syntax-column", func(start syntax.SourceIndexes) int {
return start.Column()
})
PrimSyntaxColumn returns the 0-based column of a syntax object, or #f.
Racket §12.2: syntax-column
var PrimSyntaxLine = makeSyntaxLocAccessor("syntax-line", func(start syntax.SourceIndexes) int {
return start.Line()
})
PrimSyntaxLine returns the 1-based line number of a syntax object, or #f.
Racket §12.2: syntax-line
var PrimSyntaxPosition = makeSyntaxLocAccessor("syntax-position", func(start syntax.SourceIndexes) int {
return start.Index()
})
PrimSyntaxPosition returns the 0-based byte position of a syntax object, or #f.
Racket §12.2: syntax-position
var PrimUnbox = helpers.MakeUnaryAccessor(werr.ErrNotABox, "unbox", func(b *values.Box) values.Value {
return b.Unbox()
})
PrimUnbox implements the unbox primitive. Returns the value contained in a box.
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(mc machine.CallContext) 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(mc machine.CallContext) error
PrimAbs implements the abs primitive. R7RS §6.2.6: abs is only defined for real numbers.
func PrimAppend ¶
func PrimAppend(mc machine.CallContext) error
PrimAppend implements (append list ...) per R7RS §6.4. 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 and is shared (not copied) — the result shares structure only with it. Benchmarked: kept in Go — Scheme impl is 4-9x slower on short lists (benchmark gate: 20% threshold; actual regression was ~363% for Append).
func PrimApply ¶
func PrimApply(cc machine.CallContext) error
PrimApply implements the apply primitive. Applies a procedure to a list of arguments.
func PrimApropos ¶
func PrimApropos(mc machine.CallContext) error
PrimApropos implements (apropos pattern). Returns a sorted list of symbols whose name, doc, or category contains the pattern as a case-insensitive substring. Searches all documentation sources: primitives, binding specs, doc entries, environment bindings, loaded libraries, and unloaded library exports.
func PrimBoundIdentifierEqualQ ¶
func PrimBoundIdentifierEqualQ(mc machine.CallContext) 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(mc machine.CallContext) error
PrimBox implements the box primitive. Creates a new box containing the given value.
func PrimBytevector ¶
func PrimBytevector(mc machine.CallContext) error
PrimBytevector implements the bytevector primitive. Creates bytevector from byte arguments.
func PrimBytevectorAppend ¶
func PrimBytevectorAppend(mc machine.CallContext) error
PrimBytevectorAppend implements the bytevector-append primitive. Concatenates bytevectors.
func PrimBytevectorCopy ¶
func PrimBytevectorCopy(mc machine.CallContext) error
PrimBytevectorCopy implements the bytevector-copy primitive. Returns a copy of a bytevector.
func PrimBytevectorCopyBang ¶
func PrimBytevectorCopyBang(mc machine.CallContext) error
PrimBytevectorCopyBang implements the bytevector-copy! primitive. Copies bytes between bytevectors.
func PrimBytevectorLength ¶
func PrimBytevectorLength(mc machine.CallContext) error
PrimBytevectorLength implements the bytevector-length primitive. Returns length of bytevector.
func PrimBytevectorU8Ref ¶
func PrimBytevectorU8Ref(mc machine.CallContext) error
PrimBytevectorU8Ref implements the bytevector-u8-ref primitive. Returns byte at index as an exact integer (R7RS §6.9).
func PrimBytevectorU8Set ¶
func PrimBytevectorU8Set(mc machine.CallContext) error
PrimBytevectorU8Set implements the bytevector-u8-set! primitive. Sets byte at index.
func PrimCallCC ¶
func PrimCallCC(cc machine.CallContext) 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.
Curry-Howard: call/cc as Peirce's law (Griffin 1990).
call/cc : ((A → B) → A) → A where f : (A → B) → A is the user callback, and the escape continuation k : A → B has return type B (invoking k never returns to f — it reinstalls the captured continuation at the prompt). Adding call/cc to a language = adding the law of excluded middle. This means certain program transformations (e.g., CPS conversion optimizations that assume intuitionistic control flow) are unsound in the presence of call/cc. Invariant: invoking k must NOT return to f. The CapturedContinuation returns an ErrResumeContinuation carrying the captured segment unrun; the nearest DefaultPromptTag driver reinstalls it onto the live chain (boundary == nil: replace the whole chain). Resuming the captured continuation instead of returning to f is what gives k the B return type. Constrains: ErrResumeContinuation handling (must propagate through foreign calls), RunResumable (the top-level resume/abort driver). Constrained by: CESK model (K must be capturable data, not Go stack), WindingStack (captured by value for dynamic-wind thunks), threadID (cross-thread invocation rejected).
See BIBLIOGRAPHY.md "call/cc as Peirce's Law".
Implementation follows the Racket model: capture a composable continuation (via SliceContinuationAt) and return it as a CapturedContinuation value. Invoking that value does not run the segment — it returns an ErrResumeContinuation that the driver reinstalls onto the live chain (the resume trampoline; see docs/continuations/resume-trampoline.md). The equivalence below is the semantic model, not the literal runtime path:
(call/cc f) ≡
(call-with-composable-continuation
(lambda (k)
(f (lambda (v) (abort-current-continuation default-prompt-tag (k v)))))
default-prompt-tag)
One capture, one apply seam, two driver modes. The continuation is captured once (shared by both modes); the lambda is then applied once in a selected target context. The only per-mode difference is driver provenance:
- Inline (mc.Parent() != nil): apply in the current VM context. Preserves the full continuation chain, so continuations captured inside the lambda include the complete call stack back to top level — critical for cooperative coroutines and other multi-continuation patterns. Resume is resolved by the ambient DefaultPromptTag driver already running above this frame.
- Sub-context (mc.Parent() == nil): call/cc is rootless (invoked inside another foreign function's sub-context — e.g. apply or dynamic-wind — or a thread root), so there is no ambient driver. Apply in a fresh sub-context that installs its own DefaultPromptTag driver to resolve this call/cc's resume.
func PrimCallWithComposableContinuation ¶
func PrimCallWithComposableContinuation(cc machine.CallContext) 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)
Follows Racket's call-with-composable-continuation: like call/cc but (a) proc runs IN PLACE — the current continuation is NOT removed, so proc's result flows through the live delimited frames — and (b) the captured ComposableContinuation is non-abortive: applying it COMPOSES (extends) the current continuation rather than replacing it, so the captured frames may run more than once. This is the raw composable capture; shift/control add their own abort on top (wile/control.scm).
func PrimCallWithContinuationBarrier ¶
func PrimCallWithContinuationBarrier(cc machine.CallContext) error
PrimCallWithContinuationBarrier implements (call-with-continuation-barrier thunk).
Calls thunk with no arguments and returns its result. Establishes a continuation barrier: any attempt to invoke a continuation that would cross the barrier boundary signals an error. Barriers cannot be re-entered — they return exactly once.
Specifically, any call/cc captured continuation or composable continuation captured inside the barrier will fail with a barrier violation if invoked from outside the barrier (after the barrier has returned), or from a different barrier context. Similarly, continuations captured outside the barrier cannot be invoked from inside it to jump out.
Exceptions, prompt aborts, and call-with-exit escapes propagate normally through the barrier, since they are upward-only unwinds that do not cross boundaries.
See plans/CALL_WITH_EXIT_AND_WITH_BAFFLE.md for full semantics and test cases.
func PrimCallWithContinuationPrompt ¶
func PrimCallWithContinuationPrompt(cc machine.CallContext) 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 PrimCallWithExit ¶
func PrimCallWithExit(cc machine.CallContext) error
PrimCallWithExit implements (call-with-exit proc).
Calls proc with a single-use escape procedure. If the escape procedure is called with a value during proc's dynamic extent, call-with-exit immediately returns that value (after running any dynamic-wind after thunks). If proc returns normally, call-with-exit returns that value and the escape procedure is invalidated.
Unlike call/cc, call-with-exit does NOT capture a reified continuation — the escape procedure is a lightweight one-shot upward escape. Calling the escape after call-with-exit has returned signals an error.
Inspired by S7 Scheme's call-with-exit and Guile's call-with-escape-continuation.
func PrimCallWithImmediateContMark ¶
func PrimCallWithImmediateContMark(cc machine.CallContext) error
PrimCallWithImmediateContMark implements (call-with-immediate-continuation-mark key proc [default]).
Gets the nearest mark for key in the current continuation, then calls proc with that value. If no mark is set, calls proc with default (#f if omitted).
Uses GetImmediateMark, which checks the live frame first, then the saved continuation frame — covering both tail and non-tail compilation contexts. In tail position, with-continuation-mark writes to mc.marks. In non-tail position, SaveContinuation moves mc.marks to mc.cont before the call.
func PrimCallWithValues ¶
func PrimCallWithValues(cc machine.CallContext) error
PrimCallWithValues implements the call-with-values primitive. Calls producer, passes results to consumer.
func PrimCar ¶
func PrimCar(mc machine.CallContext) 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 PrimCdr ¶
func PrimCdr(mc machine.CallContext) 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 PrimCharToInteger ¶
func PrimCharToInteger(mc machine.CallContext) error
PrimCharToInteger implements the (char->integer) primitive. Returns the Unicode code point of the character as an integer.
func PrimCons ¶
func PrimCons(mc machine.CallContext) error
PrimCons implements the cons primitive. Creates a new pair from the car and cdr arguments.
func PrimContinuationMarkSetFirst ¶
func PrimContinuationMarkSetFirst(mc machine.CallContext) error
PrimContinuationMarkSetFirst implements (continuation-mark-set-first mark-set key [default]). Returns the value for key from the nearest frame, or default (#f if omitted).
func PrimContinuationMarkSetToList ¶
func PrimContinuationMarkSetToList(mc machine.CallContext) error
PrimContinuationMarkSetToList implements (continuation-mark-set->list mark-set key). Extracts a list of values for key across all frames in the mark set.
func PrimContinuationMarkSetToListStar ¶
func PrimContinuationMarkSetToListStar(mc machine.CallContext) error
PrimContinuationMarkSetToListStar implements (continuation-mark-set->list* mark-set key-list [none-v]). Returns a list of vectors, one per frame that has at least one of the keys. Each vector position corresponds to a key in key-list. Missing keys use none-v (default #f).
Racket §10.5: continuation-mark-set->list*
func PrimContinuationMarks ¶
func PrimContinuationMarks(mc machine.CallContext) error
PrimContinuationMarks implements (continuation-marks cont [prompt-tag]). Extracts a ContinuationMarkSet from a captured continuation (the result of call/cc), optionally stopping at prompt-tag.
func PrimContinuationPromptAvailableQ ¶
func PrimContinuationPromptAvailableQ(cc machine.CallContext) error
PrimContinuationPromptAvailableQ tests whether a prompt with the given tag is on the current continuation chain.
(continuation-prompt-available? tag) -> boolean
Walks the continuation chain using FindPrompt, which checks both continuation frames and the context-level prompt.
Racket §10.4: continuation-prompt-available?
func PrimCurrentContinuationMarks ¶
func PrimCurrentContinuationMarks(cc machine.CallContext) error
PrimCurrentContinuationMarks implements (current-continuation-marks [prompt-tag]). Walks the continuation chain and returns a ContinuationMarkSet snapshot.
func PrimCurrentErrorContext ¶
func PrimCurrentErrorContext(cc machine.CallContext) error
PrimCurrentErrorContext implements (current-error-context). Returns the ErrorContext from the nearest continuation mark, or #f if not currently inside an exception handler dispatch.
func PrimDatumToSyntax ¶
func PrimDatumToSyntax(mc machine.CallContext) 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(mc machine.CallContext) error
PrimDefaultContinuationPromptTag returns the default continuation prompt tag.
func PrimDocTopic ¶
func PrimDocTopic(mc machine.CallContext) error
PrimDocTopic implements (doc-topic category). Returns a sorted list of symbols in the named category.
func PrimDocTopics ¶
func PrimDocTopics(mc machine.CallContext) error
PrimDocTopics implements (doc-topics). Returns a sorted list of category name strings.
func PrimError ¶
func PrimError(cc machine.CallContext) error
PrimError implements (error message irritant ...): builds an error object from MESSAGE and irritants, then raises it as a non-continuable exception.
func PrimErrorContextMarks ¶
func PrimErrorContextMarks(mc machine.CallContext) error
PrimErrorContextMarks implements (error-context-marks ctx). Returns the continuation mark set snapshot from the raise site, or #f if marks were not captured.
func PrimErrorContextSource ¶
func PrimErrorContextSource(mc machine.CallContext) error
PrimErrorContextSource implements (error-context-source ctx). Returns the source location string from the error context, or #f if no source location was captured.
func PrimErrorContextStackTrace ¶
func PrimErrorContextStackTrace(mc machine.CallContext) error
PrimErrorContextStackTrace implements (error-context-stack-trace ctx). Returns the stack trace as a list of alists, where each alist has keys name, file, line, and column. Returns the empty list if no stack trace was captured.
func PrimErrorObjectQ ¶
func PrimErrorObjectQ(mc machine.CallContext) error
PrimErrorObjectQ implements the error-object? predicate. Returns #t if the argument is an error object created by (error ...), #f otherwise.
func PrimErrorObjectSource ¶
func PrimErrorObjectSource(mc machine.CallContext) error
PrimErrorObjectSource implements (error-object-source err). Returns the source location string from a NativeError, or #f if empty.
func PrimErrorObjectStackTrace ¶
func PrimErrorObjectStackTrace(mc machine.CallContext) error
PrimErrorObjectStackTrace implements (error-object-stack-trace err). Returns the stack trace from a NativeError as a list of alists, or () if no stack trace has been captured.
func PrimEvenQ ¶
func PrimEvenQ(mc machine.CallContext) 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(mc machine.CallContext) 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 PrimExceptionHandlerParameter ¶
func PrimExceptionHandlerParameter(cc machine.CallContext) error
PrimExceptionHandlerParameter returns the canonical exception-handler parameter (machine.ExceptionHandlerParam). Bootstrap binds its result to the global %exception-handlers, which the Scheme with-exception-handler parameterizes.
func PrimFileErrorQ ¶
func PrimFileErrorQ(mc machine.CallContext) error
PrimFileErrorQ implements the file-error? predicate. R7RS §6.11: Returns #t if obj is an error object raised during file operations.
func PrimFreeIdentifierEqualQ ¶
func PrimFreeIdentifierEqualQ(mc machine.CallContext) 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 PrimGenerateTemporaries ¶
func PrimGenerateTemporaries(mc machine.CallContext) 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 PrimHashtableDelete ¶
func PrimHashtableDelete(mc machine.CallContext) error
PrimHashtableDelete implements the hashtable-delete! primitive. (hashtable-delete! ht key)
func PrimHashtableRef ¶
func PrimHashtableRef(mc machine.CallContext) 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(mc machine.CallContext) error
PrimHashtableSet implements the hashtable-set! primitive. (hashtable-set! ht key value)
func PrimIdentifierQ ¶
func PrimIdentifierQ(mc machine.CallContext) error
PrimIdentifierQ implements the identifier? predicate (R6RS). Returns #t if the argument is a syntax object representing an identifier.
func PrimInexact ¶
func PrimInexact(mc machine.CallContext) 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 PrimIntegerQ ¶
func PrimIntegerQ(mc machine.CallContext) 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(mc machine.CallContext) 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 PrimLength ¶
func PrimLength(mc machine.CallContext) error
PrimLength implements the (length) primitive. Benchmarked: kept in Go — Scheme impl is 9x slower on short lists.
func PrimLibraryDescription ¶
func PrimLibraryDescription(mc machine.CallContext) error
PrimLibraryDescription implements (library-description library-name). Returns the description string of a loaded library, or #f if none or not loaded.
func PrimList ¶
func PrimList(mc machine.CallContext) error
PrimList implements the (list) primitive. Creates a list from the given arguments.
The rest-arg list may be backed by a reusable buffer (restArgBuf), so we must copy the spine to produce a persistent list.
func PrimListCopy ¶
func PrimListCopy(mc machine.CallContext) error
PrimListCopy implements the list-copy primitive. Benchmarked: kept in Go — Scheme impl is 7x slower on short lists.
Two-pass block construction (mirrors PrimReverse/PrimList): pass 1 counts the pairs and captures the terminating cdr, pass 2 block-allocates the whole spine as one PairBlock and fills the cars front-to-front. This amortizes N cons allocations to a single block. Unlike a proper-list copy, list-copy preserves an improper tail: ForEach visits each car and returns the final cdr (EmptyList for a proper list, the shared atom otherwise), which we re-point the last cell at so the copy shares structure with it (R7RS §6.4).
func PrimListRef ¶
func PrimListRef(mc machine.CallContext) 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(mc machine.CallContext) error
PrimListSet implements the Scheme list-set! primitive. R7RS §6.4: The index must be an exact non-negative integer.
func PrimListTail ¶
func PrimListTail(mc machine.CallContext) error
PrimListTail implements the (list-tail) primitive. Benchmarked: kept in Go — Scheme impl is 6x slower on short lists.
func PrimListToString ¶
func PrimListToString(mc machine.CallContext) error
PrimListToString implements the (list->string) primitive. Converts a list of characters to a string.
func PrimListToVector ¶
func PrimListToVector(mc machine.CallContext) error
PrimListToVector implements the list->vector primitive.
func PrimMakeBytevector ¶
func PrimMakeBytevector(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) error
PrimMakeHashtable implements the make-hashtable primitive. Creates a new empty hash table.
func PrimMakeList ¶
func PrimMakeList(mc machine.CallContext) error
PrimMakeList implements the Scheme make-list primitive.
func PrimMakeParameter ¶
func PrimMakeParameter(cc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) error
PrimMakeVector implements the (make-vector) primitive. Creates a vector of the given size, optionally filled with a specified value.
func PrimMemq ¶
func PrimMemq(mc machine.CallContext) error
PrimMemq implements the memq primitive. Finds an element in a list using eq? for comparison.
func PrimMemv ¶
func PrimMemv(mc machine.CallContext) error
PrimMemv implements the memv primitive. Finds an element in a list using eqv? for comparison.
func PrimModulo ¶
func PrimModulo(mc machine.CallContext) 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 PrimNullQ ¶
func PrimNullQ(mc machine.CallContext) error
PrimNullQ implements the null? predicate. Returns #t if the argument is the empty list '().
func PrimNumEq ¶
func PrimNumEq(mc machine.CallContext) error
PrimNumEq implements the = primitive.
R7RS §6.2.6: Returns #t if its arguments are numerically equal.
func PrimNumGe ¶
func PrimNumGe(mc machine.CallContext) 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(mc machine.CallContext) error
PrimNumGt implements the > primitive.
R7RS §6.2.6: Ordering comparisons require real arguments.
func PrimNumLe ¶
func PrimNumLe(mc machine.CallContext) 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(mc machine.CallContext) error
PrimNumLt implements the < primitive.
R7RS §6.2.6: Ordering comparisons require real arguments.
func PrimOddQ ¶
func PrimOddQ(mc machine.CallContext) 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(mc machine.CallContext) error
PrimPairQ implements the pair? predicate. Returns #t if the argument is a pair (cons cell). EmptyList is not a *Pair (it's a separate type), so the type assertion handles (pair? '()) -> #f at the type level per R7RS §6.4.
func PrimParameterConvert ¶
func PrimParameterConvert(cc machine.CallContext) error
PrimParameterConvert implements (%parameter-convert param val). Applies the parameter's converter to val and returns the result. If the parameter has no converter, returns val unchanged.
Used by the parameterize macro to pre-convert the value before storing it as a continuation mark. This is an internal primitive.
func PrimParameterRawSet ¶
func PrimParameterRawSet(mc machine.CallContext) error
PrimParameterRawSet implements the (%parameter-raw-set! param val) primitive. Sets a parameter's internal value directly, bypassing the converter.
This is an internal primitive — not part of the public API.
func PrimPrimitiveSpecCategory ¶
func PrimPrimitiveSpecCategory(mc machine.CallContext) error
PrimPrimitiveSpecCategory implements (primitive-spec-category spec).
func PrimPrimitiveSpecGoFunction ¶
func PrimPrimitiveSpecGoFunction(mc machine.CallContext) error
PrimPrimitiveSpecGoFunction implements (primitive-spec-go-function spec). Returns the fully-qualified Go function name, or the empty string for binding-only primitives (nil Impl).
func PrimPrimitiveSpecGoSource ¶
func PrimPrimitiveSpecGoSource(mc machine.CallContext) error
PrimPrimitiveSpecGoSource implements (primitive-spec-go-source spec). Returns "file:line" (absolute path), or the empty string for binding-only primitives. Callers wanting a repo-relative path should strip the known workspace prefix themselves.
func PrimPrimitiveSpecName ¶
func PrimPrimitiveSpecName(mc machine.CallContext) error
PrimPrimitiveSpecName implements (primitive-spec-name spec).
func PrimPrimitiveSpecParamCount ¶
func PrimPrimitiveSpecParamCount(mc machine.CallContext) error
PrimPrimitiveSpecParamCount implements (primitive-spec-param-count spec).
func PrimPrimitiveSpecQ ¶
func PrimPrimitiveSpecQ(mc machine.CallContext) error
PrimPrimitiveSpecQ implements (primitive-spec? v).
func PrimPrimitiveSpecReturnType ¶
func PrimPrimitiveSpecReturnType(mc machine.CallContext) error
PrimPrimitiveSpecReturnType implements (primitive-spec-return-type spec). Returns the declared ReturnType name, or the empty string if unset.
func PrimPrimitiveSpecVariadicQ ¶
func PrimPrimitiveSpecVariadicQ(mc machine.CallContext) error
PrimPrimitiveSpecVariadicQ implements (primitive-spec-variadic? spec).
func PrimProcedureArity ¶
func PrimProcedureArity(mc machine.CallContext) error
PrimProcedureArity implements (procedure-arity proc).
func PrimProcedureBoundSymbols ¶
func PrimProcedureBoundSymbols(mc machine.CallContext) error
PrimProcedureBoundSymbols implements (procedure-bound-symbols proc).
func PrimProcedureDocumentation ¶
func PrimProcedureDocumentation(mc machine.CallContext) error
PrimProcedureDocumentation implements (procedure-documentation proc). Returns the docstring attached to a procedure, or #f if none. For Scheme closures, the docstring is extracted from the body (Guile convention). For foreign closures, the docstring comes from PrimitiveSpec.Doc.
func PrimProcedureName ¶
func PrimProcedureName(mc machine.CallContext) error
PrimProcedureName implements (procedure-name proc).
func PrimProcedureSourceLocation ¶
func PrimProcedureSourceLocation(mc machine.CallContext) error
PrimProcedureSourceLocation implements (procedure-source-location proc).
func PrimProcedureType ¶
func PrimProcedureType(mc machine.CallContext) error
PrimProcedureType implements (procedure-type proc).
func PrimQuotient ¶
func PrimQuotient(mc machine.CallContext) error
PrimQuotient implements the (quotient) primitive. Returns truncated integer quotient. Accepts exact and inexact integers per R7RS.
func PrimRaise ¶
func PrimRaise(cc machine.CallContext) error
PrimRaise implements (raise obj): invokes the current exception handler on obj as a non-continuable exception.
func PrimRaiseContinuable ¶
func PrimRaiseContinuable(cc machine.CallContext) error
PrimRaiseContinuable implements (raise-continuable obj): invokes the current handler; if the handler returns, its value becomes the value of the raise-continuable expression and execution resumes at the call site (R7RS §6.11).
func PrimRationalQ ¶
func PrimRationalQ(mc machine.CallContext) 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 PrimReadErrorQ ¶
func PrimReadErrorQ(mc machine.CallContext) error
PrimReadErrorQ implements the read-error? predicate. R7RS §6.11: Returns #t if obj is an error object raised during reading.
func PrimRealQ ¶
func PrimRealQ(mc machine.CallContext) 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 PrimRegisteredPrimitives ¶
func PrimRegisteredPrimitives(mc machine.CallContext) error
PrimRegisteredPrimitives implements (registered-primitives). Returns a list of opaque primitive-spec values wrapping the current namespace's registry entries. Each value can be queried via the primitive-spec-* accessors below.
func PrimRemainder ¶
func PrimRemainder(mc machine.CallContext) error
PrimRemainder implements the (remainder) primitive. Returns remainder with sign of dividend. Accepts exact and inexact integers per R7RS.
func PrimReverse ¶
func PrimReverse(mc machine.CallContext) error
PrimReverse implements the (reverse) primitive. Benchmarked: kept in Go — Scheme impl is 7x slower on short lists.
Two-pass block construction: pass 1 validates the proper list and counts its length; pass 2 block-allocates all cells at once (PairBlock), links the spine via LinkSpine, then fills the cars back-to-front so the result emerges reversed. This amortizes N cons allocations to a single block allocation. The extra spine traversal is allocation-free pointer-chasing.
func PrimSetCar ¶
func PrimSetCar(mc machine.CallContext) error
PrimSetCar implements the set-car! primitive. PrimSetCar is NOT converted to helpers.MakeBinarySetter: set-car!/set-cdr! are core list mutation reachable from tight loops (Larceny destruc/maze), and the factory's extra indirect call measured ~2% slower on a set-car!-dominated microbenchmark. Kept as an explicit func per the FACTORY-AUDIT hot-path exclusion. See ArgShape unification notes.
func PrimSetCdr ¶
func PrimSetCdr(mc machine.CallContext) error
PrimSetCdr implements the set-cdr! primitive. PrimSetCdr is kept as an explicit func for the same hot-path reason as PrimSetCar above (set-cdr! measured ~2% slower through the factory closure).
func PrimString ¶
func PrimString(mc machine.CallContext) error
PrimString implements the string primitive. (string char ...) returns a newly allocated string composed of the given characters.
func PrimStringAppend ¶
func PrimStringAppend(mc machine.CallContext) error
PrimStringAppend implements the (string-append) primitive. Concatenates strings.
func PrimStringCopy ¶
func PrimStringCopy(mc machine.CallContext) 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 PrimStringLength ¶
func PrimStringLength(mc machine.CallContext) error
PrimStringLength implements string-length. Returns the number of characters (runes) in the string.
func PrimStringRef ¶
func PrimStringRef(mc machine.CallContext) error
PrimStringRef implements the string-ref primitive. Returns the character at the given index in the string.
func PrimStringSet ¶
func PrimStringSet(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) error
PrimStringToSymbol implements the string->symbol primitive. Converts a string to a symbol.
func PrimStringToUtf8 ¶
func PrimStringToUtf8(mc machine.CallContext) error
PrimStringToUtf8 implements the string->utf8 primitive. Converts a string to a UTF-8 encoded bytevector with optional start and end indices.
R7RS §6.9: (string->utf8 string [start [end]]) Returns a newly allocated bytevector containing the UTF-8 encoding of the characters in string between start and end (character positions, not byte positions).
func PrimStringToVector ¶
func PrimStringToVector(mc machine.CallContext) 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 PrimSubstring ¶
func PrimSubstring(mc machine.CallContext) error
PrimSubstring implements the substring primitive. Returns a substring between the given start and end indices.
func PrimSymbolToString ¶
func PrimSymbolToString(mc machine.CallContext) error
PrimSymbolToString implements the symbol->string primitive. Converts a symbol to an immutable string. R7RS §6.5: The string returned by symbol->string is immutable.
func PrimSyntaxSource ¶
func PrimSyntaxSource(mc machine.CallContext) error
PrimSyntaxSource returns the source file path of a syntax object, or #f if the syntax object has no source location.
Racket §12.2: syntax-source
func PrimSyntaxSpan ¶
func PrimSyntaxSpan(mc machine.CallContext) error
PrimSyntaxSpan returns the byte span (end - start) of a syntax object, or #f.
Racket §12.2: syntax-span
func PrimSyntaxToDatum ¶
func PrimSyntaxToDatum(mc machine.CallContext) error
PrimSyntaxToDatum implements the syntax->datum procedure (R6RS). Recursively unwraps a syntax object to its underlying datum, stripping all lexical context information.
func PrimSyntaxToList ¶
func PrimSyntaxToList(mc machine.CallContext) error
PrimSyntaxToList converts a syntax pair chain to a list of syntax objects. Returns #f if the argument is a syntax object but not a proper syntax list. Raises an error if the argument is not a syntax object at all.
Racket §12.2: syntax->list
func PrimUtf8ToString ¶
func PrimUtf8ToString(mc machine.CallContext) error
PrimUtf8ToString implements the utf8->string primitive. Converts a UTF-8 encoded bytevector to a string with optional start and end indices.
R7RS §6.9: (utf8->string bytevector [start [end]]) Decodes the bytes of a bytevector between start and end (byte positions) and returns the corresponding string.
func PrimValues ¶
func PrimValues(mc machine.CallContext) 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(mc machine.CallContext) error
PrimVector implements the vector primitive.
func PrimVectorAppend ¶
func PrimVectorAppend(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) 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 PrimVectorLength ¶
func PrimVectorLength(mc machine.CallContext) error
PrimVectorLength implements the vector-length primitive. Returns the number of elements in a vector as an integer.
func PrimVectorRef ¶
func PrimVectorRef(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) 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(mc machine.CallContext) error
PrimVoidQ implements the void? predicate. Returns #t if the argument is the void value.
func PrimWithTimeout ¶
func PrimWithTimeout(cc machine.CallContext) error
PrimWithTimeout implements (with-timeout ms handler thunk).
Runs thunk with a wall-clock timeout of ms milliseconds. If the thunk completes normally, returns its result. If the timer fires before the thunk finishes, the thunk is suspended and handler is called with a composable continuation that can resume the computation.
The sub-context pattern follows call-with-continuation-barrier (prim_barrier.go): a fresh sub-context isolates the thunk's execution while inheriting the parent's environment and winding stack.
Types ¶
This section is empty.
Source Files
¶
- arithmetic.go
- bootstrap.go
- boxes.go
- byte_vectors.go
- characters.go
- cont_marks.go
- control.go
- doc.go
- equality.go
- exceptions.go
- hashtables.go
- lists.go
- opaque.go
- pairs.go
- parameters.go
- predicates.go
- prim_arithmetic.go
- prim_barrier.go
- prim_boxes.go
- prim_byte_vectors.go
- prim_characters.go
- prim_cont_marks.go
- prim_control.go
- prim_equality.go
- prim_error_context.go
- prim_exceptions.go
- prim_exit.go
- prim_hashtables.go
- prim_lists.go
- prim_opaque.go
- prim_pairs.go
- prim_parameters.go
- prim_predicates.go
- prim_prompt.go
- prim_reflection.go
- prim_strings.go
- prim_syntax.go
- prim_syntax_loc.go
- prim_timer.go
- prim_vectors.go
- prompts.go
- reflection.go
- register.go
- specialforms.go
- strings.go
- syntax.go
- syntax_loc.go
- timer.go
- vectors.go