### Run example with interactive REPL Source: https://github.com/aalpar/wile/blob/master/examples/README.md Loads the state-machine example and starts an interactive REPL after loading. ```bash ./dist/wile --file examples/macros/state-machine.scm --interactive ``` -------------------------------- ### Run a single example Source: https://github.com/aalpar/wile/blob/master/examples/README.md Runs the example file examples/basics/hello.scm with the Wile interpreter. ```bash ./dist/wile --file examples/basics/hello.scm ``` -------------------------------- ### Development setup commands for Wile Source: https://github.com/aalpar/wile/blob/master/CONTRIBUTING.md Sets up the development environment: clone the repository, build the interpreter with `make build`, run tests with `make test`, and start the REPL using the platform-specific binary paths for macOS ARM64 and Linux x86-64. ```bash # Clone the repository git clone https://github.com/aalpar/wile.git cd wile # Build the interpreter make build # Run tests make test # Run the REPL ./dist/darwin/arm64/wile # macOS ARM64 ./dist/linux/amd64/wile # Linux x86-64 ``` -------------------------------- ### Run Schelog example files Source: https://github.com/aalpar/wile/blob/master/examples/logic/schelog/README.md Commands to run each example file. Load schelog.scm first, then the example file. All complete in seconds. ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm -f examples/logic/schelog/toys.scm ``` ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm -f examples/logic/schelog/mapcol.scm ``` ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm \ -f examples/logic/schelog/puzzle.scm \ -f examples/logic/schelog/games.scm ``` ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm -f examples/logic/schelog/england.scm ``` ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm -f examples/logic/schelog/bible.scm ``` ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm -f examples/logic/schelog/holland.scm ``` -------------------------------- ### Initial Setup: Create Plan-based Issues Source: https://github.com/aalpar/wile/blob/master/scripts/README.md Step 2 of initial setup: preview plan-based issues with --dry-run, then create them. ```bash ./scripts/create-plan-issues.sh --dry-run # Preview ``` ```bash ./scripts/create-plan-issues.sh # Create ``` -------------------------------- ### Run all examples in a category Source: https://github.com/aalpar/wile/blob/master/examples/README.md Loops over all .scm files in examples/basics and runs each with Wile, printing the filename before each run. ```bash for f in examples/basics/*.scm; do echo "=== $f ===" ./dist/wile --file "$f" echo done ``` -------------------------------- ### Wile REPL session with meta commands Source: https://github.com/aalpar/wile/blob/master/README.md Example REPL session showing a recursive Fibonacci definition, evaluation, and meta commands. Meta commands start with `,`; use `,help` for the full list. The REPL supports readline-style editing, multi-line expressions, and a built-in debugger. ```scheme > (define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2))))) > (fib 10) 55 > ,doc map > ,break program.scm:42 > ,continue ``` -------------------------------- ### Run any example and build the interpreter Source: https://github.com/aalpar/wile/blob/master/examples/README.md Command-line instructions to run a Wile Scheme example using the built interpreter and to compile the interpreter from source with make. Requires the project to be built first. ```shell ./dist/wile --file examples/basics/hello.scm ``` ```shell make build ``` -------------------------------- ### Example file structure template Source: https://github.com/aalpar/wile/blob/master/examples/README.md Shows the consistent format used by each example file, including header comments, explanatory comments, and demonstration output. ```scheme ;;; filename.scm - Brief description ;;; ;;; Demonstrates: feature1, feature2, feature3 ;;; Wile-specific: non-standard extensions used (if any) ;;; ;;; Usage: ./dist/wile --file examples/category/filename.scm ;; Explanatory comments (define (example-function args) ;; Implementation ...) ;; Demonstration output (display "Expected: ...") (display (example-function test-input)) ``` -------------------------------- ### Install Scheme implementations for comparison Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README-USAGE.md Install other Scheme implementations for comparison. The commands cover macOS, Ubuntu/Debian, and Fedora/RHEL package managers. ```bash # macOS brew install chezscheme # Ubuntu/Debian sudo apt install chezscheme racket chibi-scheme # Fedora/RHEL sudo dnf install chezscheme racket chibi-scheme ``` -------------------------------- ### syntax-rules — my-let Example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example macro definition using syntax-rules to implement my-let. ```scheme (define-syntax my-let (syntax-rules () ((my-let ((var val) ...) body ...) ((lambda (var ...) body ...) val ...)))) ``` -------------------------------- ### Start Wile REPL with Schelog Source: https://github.com/aalpar/wile/blob/master/examples/logic/schelog/README.md Starts a Wile REPL with the Schelog library loaded. Use this to try Schelog queries interactively. ```bash ./dist/wile -i -f examples/logic/schelog/schelog.scm ``` -------------------------------- ### Creating a namespace and engine with options Source: https://github.com/aalpar/wile/blob/master/docs/embedding/api-design.md Example of building a namespace with profile and sandbox, then creating an engine with that namespace and library paths. The namespace options (WithProfile, WithSandbox) are passed to NewNamespace, while engine options (WithLibraryPaths) go to NewEngineWithNamespace. ```go ns, _ := wile.NewNamespace(ctx, wile.WithProfile(wile.Small), wile.WithSandbox()) eng, _ := wile.NewEngineWithNamespace(ctx, ns, wile.WithLibraryPaths(".")) ``` -------------------------------- ### do example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example of do loop summing numbers 0 to 9, returning 45. ```scheme (do ((i 0 (+ i 1)) (sum 0 (+ sum i))) ((= i 10) sum)) ; → 45 ``` -------------------------------- ### stream-ref example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example of a stream-ref procedure using delay-force for proper tail recursion. ```scheme (define (stream-ref s n) (if (= n 0) (force (car s)) (stream-ref (force (cdr s)) (- n 1)))) ``` -------------------------------- ### Complete example: create engine with extensions and evaluate Scheme imports Source: https://github.com/aalpar/wile/blob/master/docs/extensions/libraries.md Shows a complete Go program that creates a wile engine with math, process, and system extensions, enables library paths, and evaluates a Scheme snippet that selectively imports bindings. The Scheme code imports only sqrt and floor from the math library and prefixes the system library, then computes the floor of the square root of 200, printing "14.0". Requires WithLibraryPaths() to enable the import system; otherwise imports fail with "no library registry configured". ```go package main import ( "context" "fmt" "github.com/aalpar/wile/pkg/wile" "github.com/aalpar/wile/extensions/math" "github.com/aalpar/wile/extensions/process" "github.com/aalpar/wile/extensions/system" ) func main() { ctx := context.Background() engine, err := wile.NewEngine(ctx, wile.WithExtensions( math.Extension, process.Extension, system.Extension, ), wile.WithLibraryPaths(), ) if err != nil { panic(err) } result, err := engine.EvalMultiple(ctx, ` ;; Selectively import only what we need (import (only (wile math) sqrt floor)) (import (prefix (wile system) sys:)) ;; Use imported bindings (let ((x (sqrt 200))) (floor x)) `) if err != nil { panic(err) } fmt.Println(result.SchemeString()) // "14.0" } ``` -------------------------------- ### Quicktest Assertion Examples Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Shows common assertions using the quicktest (qt) framework. Use qt.Equals for basic equality, valuestest.SchemeEquals for Value comparison, qt.IsNil for nil errors, and qt.IsNotNil for non-nil results. ```go qt.Assert(t, actual, qt.Equals, expected) qt.Assert(t, actual, valuestest.SchemeEquals, expected) // For Value comparison qt.Assert(t, err, qt.IsNil) qt.Assert(t, result, qt.IsNotNil) ``` -------------------------------- ### parameterize example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example of parameterize with a custom parameter, showing the value inside and outside the dynamic extent. ```scheme (define current-precision (make-parameter 10)) (parameterize ((current-precision 20)) (current-precision)) ; → 20 ; outside: (current-precision) → 10 ``` -------------------------------- ### syntax-case — my-or Example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example procedural macro using syntax-case to implement my-or. ```scheme (define-syntax my-or (lambda (stx) (syntax-case stx () ((_ a b) #'(let ((t a)) (if t t b)))))) ``` -------------------------------- ### let-values example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Binds multiple return values from floor/ and returns a list of them. ```scheme (let-values (((q r) (floor/ 17 5))) (list q r)) ; → (3 2) ``` -------------------------------- ### Install other Scheme implementations Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/BENCHMARKING.md Installs Chez Scheme, Racket, Chibi Scheme, and Guile on macOS, Ubuntu/Debian, or Fedora/RHEL. Required for manual comparison benchmarks. ```bash # macOS brew install chezscheme racket chibi-scheme guile # Ubuntu/Debian apt install chezscheme racket chibi-scheme guile-3.0 # Fedora/RHEL dnf install chezscheme racket chibi-scheme guile ``` -------------------------------- ### Setting up a complete runtime with bootstrap.NewNamespaceFrame Source: https://github.com/aalpar/wile/blob/master/docs/environment/system.md Builds a complete runtime environment with primitives and macros using bootstrap.NewNamespaceFrame, sets a library registry, and configures the library environment factory. Note that pkg/internal/bootstrap is importable only inside the module and installs no initial-import bulk rows, so the frame lacks the macro-vocabulary row at phases ≥ 1 that wile.NewEngine declares. ```go import ( "context" "github.com/aalpar/wile/pkg/environment" "github.com/aalpar/wile/pkg/internal/bootstrap" "github.com/aalpar/wile/pkg/machine/compilation" ) func setupRuntime(ctx context.Context) (*environment.EnvironmentFrame, error) { // Create complete environment with primitives and macros env, err := bootstrap.NewNamespaceFrame(ctx) if err != nil { return nil, err } // Set up library loading registry := compilation.NewLibraryRegistry() env.SetLibraryRegistry(registry) // Configure library environment factory (shares Namespace) env.Namespace().SetLibraryEnvFactory(bootstrap.NewLibraryEnvironmentFrame) return env, nil } ``` -------------------------------- ### Workaround: use list or vector-copy to get mutable non-literal data Source: https://github.com/aalpar/wile/blob/master/docs/reference/r7rs-differences.md Workaround for programs that must mutate: construct with list, cons, make-vector, or vector-copy to obtain an allocation not shared with any literal. The wrong example mutates a pair literal, which is not detected and can affect structure-shared quotations; the right examples use list and vector-copy to guarantee mutable, non-aliased data. ```scheme ;; Wrong: mutates a pair literal; not detected, and visible through any ;; structure-shared quotation of the same shape: (let ((xs '(1 2 3))) (set-car! xs 99) xs) ;; Right — guaranteed mutable, no aliasing with literals: (let ((xs (list 1 2 3))) (set-car! xs 99) xs) (let ((v (vector-copy '#(1 2 3)))) (vector-set! v 0 99) v) ``` -------------------------------- ### Create a Namespace and get its runtime environment Source: https://github.com/aalpar/wile/blob/master/docs/environment/system.md Creates a new Namespace and obtains its runtime environment. The first form is the basic creation path; the second is a deprecated convenience wrapper that delegates to NewNamespace().Runtime(). ```go ns := environment.NewNamespace() env := ns.Runtime() // Get the runtime (phase 0) environment ``` ```go env := environment.NewNamespaceFrame() ``` -------------------------------- ### guard example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example of guard catching an error and returning a message string. ```scheme (guard (exn ((error-object? exn) (string-append "caught: " (error-object-message exn))) (else "unknown error")) (error "something went wrong")) ; → "caught: something went wrong" ``` -------------------------------- ### Start the MCP server with `wile --mcp` Source: https://github.com/aalpar/wile/blob/master/docs/embedding/mcp.md Command to start Wile as an MCP server on stdio. Mutually exclusive with `-e`, `-f`, `-i`, and `--check`. Communicates via JSON-RPC over stdin/stdout. ```bash wile --mcp ``` -------------------------------- ### Optimize symbol lookup with benchmark-driven development Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/BENCHMARKING.md Use this workflow to identify a slow benchmark, apply an optimization, rebuild, and verify improvement. The example shows a 0.8s to 0.6s reduction (25% improvement) and ends with running the full suite to check for regressions. ```bash # 1. Identify slow benchmark ./dist/wile --file examples/benchmarks/deriv.scm # "Total time: 0.8s" - this does a lot of symbol lookups # 2. Make optimization to environment/binding.go # 3. Rebuild and re-run make build ./dist/wile --file examples/benchmarks/deriv.scm # "Total time: 0.6s" - 25% improvement! # 4. Run full suite to check for regressions cd examples/benchmarks && ./run-all.sh ``` -------------------------------- ### NewLibraryEnvironmentFrame factory and installation Source: https://github.com/aalpar/wile/blob/master/docs/environment/system.md Defines the library environment factory used by the Namespace to create R7RS library environments. It shares the caller's Namespace via NewChildRuntime and is installed with SetLibraryEnvFactory. Note that wile.NewEngine installs its own factory closure instead. ```go // In pkg/internal/bootstrap/bootstrap.go — NewLibraryEnvironmentFrame func NewLibraryEnvironmentFrame(ctx context.Context, callerEnv *environment.EnvironmentFrame, _ []string) (*environment.EnvironmentFrame, error) { // Create a new environment that shares the caller's Namespace libEnv := callerEnv.Namespace().NewChildRuntime() // Initialize with shared sequence (primitives, macros, etc.) // ... return libEnv, nil } // Internal setup (e.g. pkg/registry/testhelpers) env.Namespace().SetLibraryEnvFactory(bootstrap.NewLibraryEnvironmentFrame) ``` -------------------------------- ### define — Example Definitions Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Examples of define: a variable, a function, and a function with a rest parameter. ```scheme (define x 42) (define (square n) (* n n)) (define (f x . rest) (cons x rest)) ``` -------------------------------- ### Composable continuation with prompt tag Source: https://github.com/aalpar/wile/blob/master/docs/continuations/racket-primitives.md Shows how to install a continuation prompt and capture a composable continuation up to that prompt. The captured continuation k is invoked twice, demonstrating that composable continuations extend rather than replace the current continuation. Note that Wile requires all three arguments to call-with-continuation-prompt, while Racket makes the last two optional. ```scheme (define tag (make-continuation-prompt-tag)) (call-with-continuation-prompt (lambda () (+ 1 (call-with-composable-continuation (lambda (k) ;; k captures (+ 1 [hole]) — just this one frame (k (k 10))) ; (k 10)->11, (k 11)->12; proc's 12 then flows IN ; PLACE into the live (+ 1 _) => 13 (compose, not remove) tag))) tag #f) ; no handler; Wile requires all three arguments, Racket makes the last two optional ``` -------------------------------- ### quote — Example Data Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Examples of quoted data: a list, a symbol, and a vector. ```scheme '(1 2 3) ; list 'hello ; symbol '#(1 2) ; vector ``` -------------------------------- ### Import extension primitives with R7RS (import ...) modifiers Source: https://github.com/aalpar/wile/blob/master/docs/extensions/libraries.md Demonstrates importing extension primitives with R7RS (import ...) syntax. Shows only, except, prefix, rename, and combined modifiers, with example calls and expected results. ```scheme ;; Import all primitives from the math extension (import (wile math)) (sqrt 16) ; → 4 ;; Import only specific bindings (import (only (wile math) sqrt sin cos)) ;; Exclude specific bindings (import (except (wile math) expt rationalize)) ;; Prefix all imported bindings (import (prefix (wile math) m:)) (m:sqrt 9) ; → 3 ;; Rename specific bindings (import (rename (wile math) (sqrt square-root))) (square-root 25) ; → 5 ;; Combine modifiers (import (prefix (only (wile math) sqrt sin cos) math:)) (math:sqrt 4) ; → 2 ``` -------------------------------- ### Compare against other schemes Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README-USAGE.md Run a few quick benchmarks (tak, fib, deriv, peval) on all installed Schemes. Chez and Racket load a prelude defining current-jiffy and jiffies-per-second; benchmarks that import libraries or include Wile sources report FAILED outside Wile. ```bash cd examples/benchmarks ./compare-schemes.sh ``` -------------------------------- ### Import Scheme and wile libraries with (import ...) Source: https://github.com/aalpar/wile/blob/master/cmd/wile/prompts/wile-scheme.md Loads libraries on demand with (import ...). The session starts with the full primitive set already bound, so define, display, and arithmetic work before any import. Use libraries to see which are already loaded, and doc with a library name (e.g. (wile files)) to see what it exports. ```scheme (import (scheme base)) ; core: define, if, let, lambda, lists, arithmetic (import (scheme write)) ; display, write, newline, write-char (import (scheme file)) ; open-input-file, open-output-file, etc. (import (scheme process-context)); command-line, exit, get-environment-variable (import (scheme time)) ; current-second, current-jiffy (import (scheme eval)) ; eval, environment, interaction-environment (import (scheme lazy)) ; delay, force, make-promise (import (scheme char)) ; char-alphabetic?, char-upcase, etc. (import (scheme inexact)) ; finite?, nan?, sqrt, exp, log, sin, ... (import (scheme cxr)) ; caddr, cdddr, ... (import (scheme r5rs)) ; R5RS compatibility (import (srfi 1)) ; list library: iota, fold, filter, append-map, ... (import (chibi test)) ; test framework: test, test-group, test-end (import (wile files)) ; filesystem: directory-files, create-directory, current-directory, ... (import (wile math)) ; extended math: exact-integer-sqrt, inexact-accuracy, trig, logarithms (import (wile system)) ; command-line, exit, current-second, current-jiffy (import (wile process)) ; system, process-spawn, process-wait, process-kill (import (wile threads)) ; SRFI-18: make-thread, thread-start!, mutex-lock!, ... (import (wile gointerop)) ; Go FFI: opaque values, type tags (import (wile introspection)) ; disassemble, environment-bound-names, available-libraries, ... (import (wile algebra)) ; lattices, semirings, monoids, groups, fields ``` -------------------------------- ### Benchmark output format Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README-USAGE.md Example output format of a benchmark. The Total time is what matters for comparison. ```text === Benchmark Name === Benchmark: description Iterations: 10 Total time: 1.234s Per iteration: 0.1234s ``` -------------------------------- ### Named let loop example Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Example of named let as a looping construct. Accumulates numbers 0 to 4 and returns the reversed list. ```scheme (let loop ((i 0) (acc '())) (if (= i 5) (reverse acc) (loop (+ i 1) (cons i acc)))) ; → (0 1 2 3 4) ``` -------------------------------- ### lambda — Example Forms Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Examples of lambda forms: fixed arity, one required plus rest, and all arguments as a list. ```scheme (lambda (x y) (+ x y)) ; fixed arity (lambda (x . rest) rest) ; one required + rest (lambda args (length args)) ; all args as list ``` -------------------------------- ### wile://libraries resource response Source: https://github.com/aalpar/wile/blob/master/docs/embedding/mcp.md Example response from the wile://libraries resource. Returns a JSON array of loaded libraries, omitting discoverable-but-not-imported ones. ```json [ {"name": "(scheme base)", "description": "R7RS base library"}, {"name": "(wile algebra)", "description": "Algebraic structures"} ] ``` -------------------------------- ### Run all tests via shell script Source: https://github.com/aalpar/wile/blob/master/examples/logic/schelog/README.md Runs the validation suite covering all fast examples (toys, holland, england, bible, mapcol, games). Completes in seconds. ```bash ./examples/logic/schelog/run-all-tests.sh ``` -------------------------------- ### Install Wile as a Go library Source: https://github.com/aalpar/wile/blob/master/README.md Adds the Wile library to a Go project. Requires Go 1.24 or later; for a build free of known stdlib vulnerabilities, use Go 1.26.4 or later. ```bash go get github.com/aalpar/wile@latest ``` -------------------------------- ### Run Scheme tests with alternative implementations Source: https://github.com/aalpar/wile/blob/master/test/COMPATIBILITY.md Runs the test suite with alternative Scheme implementations by setting the SCHEME variable. Chez Scheme may require manual installation of chibi-test, and Gauche may also need manual setup. ```bash make test-scheme SCHEME=chez-scheme ``` ```bash make test-scheme SCHEME=chibi-scheme ``` ```bash make test-scheme SCHEME=gauche ``` -------------------------------- ### wile://primitives resource response Source: https://github.com/aalpar/wile/blob/master/docs/embedding/mcp.md Example response from the wile://primitives resource. Returns a JSON array of registered primitives with signatures and documentation; fields category, variadic, and doc are omitted when empty or false. ```json [ {"name": "car", "category": "pairs", "paramCount": 1, "doc": "..."}, {"name": "+", "category": "arithmetic", "paramCount": 1, "variadic": true, "doc": "..."} ] ``` -------------------------------- ### Quasiquotation examples Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Quasiquote with unquote and unquote-splicing, including vector quasiquote. ```scheme `(a ,(+ 1 2) b) ; → (a 3 b) `(a ,@(list 1 2) b) ; → (a 1 2 b) `#(a ,(+ 1 2)) ; → #(a 3) (vector quasiquote) ``` -------------------------------- ### Scheme docstring with full metadata sections for map Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Example docstring with all metadata sections: Parameters, Returns, Category, and See also. Metadata sections appear after the prose description and before Examples/See also. Type names must match the ValueType.String() vocabulary; unknown names degrade to any. ```scheme (define (map f lst) "Apply F to each element of LST, returning a list of results.\n\nParameters:\n f : procedure\n lst : list\nReturns: list\nCategory: lists\n\nSee also: `for-each', `vector-map'." ...) ``` -------------------------------- ### Per-line coverage summary output Source: https://github.com/aalpar/wile/blob/master/docs/coverage/scheme-coverage.md Example output of wile --cover-summary. N/M shows distinct sub-expressions covered vs. total on the line; max_col_reached is the rightmost start column of any covered sub-expression. Under branches, a high max_col_reached with low N/M indicates a skipped middle sub-expression, typically a dead branch. ```text myapp.scm:12 3/5 covered max_col_reached=27 myapp.scm:15 0/2 covered max_col_reached=0 TOTAL 3/7 sexprs covered ``` -------------------------------- ### Import grouping with standard, internal, and third-party packages Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Shows the required import grouping order: standard library first, then internal packages, then third-party. The example uses the wile project's internal packages and the go-flags third-party package. ```go import ( "context" "fmt" "io" "strings" "github.com/aalpar/wile/pkg/environment" "github.com/aalpar/wile/pkg/syntax" "github.com/aalpar/wile/pkg/values" "github.com/jessevdk/go-flags" ) ``` -------------------------------- ### R7RS environment snapshot example Source: https://github.com/aalpar/wile/blob/master/docs/environment/racket-namespaces.md Attempts to evaluate an expression in a frozen R7RS environment. As specified by R7RS, the environment is a snapshot, so definitions do not persist across evaluations, making it unsuitable for building a REPL. ```scheme (eval '(+ 1 2) (environment '(scheme base))) ``` -------------------------------- ### wile CLI usage examples Source: https://github.com/aalpar/wile/blob/master/docs/reference/cli-and-repl.md Command-line invocations of the wile interpreter. Use these to start a REPL, run a file, evaluate expressions, add library search paths, or combine flags. The -f flag runs a file without skipping the shebang line, and -i enters the REPL after running the file. Multiple -e expressions are evaluated in order. ```bash wile # Start REPL ``` ```bash wile program.scm # Run file and exit ``` ```bash wile -f program.scm # Same, via flag (no #! skip) ``` ```bash wile -f program.scm -i # Run file, then enter REPL ``` ```bash wile -e '(+ 1 2)' # Evaluate expression and print result ``` ```bash wile -L /path/to/libs program.scm # Add library search path ``` ```bash wile -e '(define x 10)' -e '(* x x)' # Multiple expressions, in order ``` -------------------------------- ### Create comparison script compare-benchmarks.sh Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/BENCHMARKING.md A bash script that runs the same benchmark (tak.scm) on Wile, Chez, Racket, Chibi, and Guile, timing each and grepping for "Total time" output. Requires the other Scheme implementations installed and the benchmark file present. ```bash #!/usr/bin/env bash # compare-benchmarks.sh BENCH="tak" echo "Benchmark: $BENCH" echo "========================" echo -n "Wile: " time ./dist/wile --file examples/benchmarks/${BENCH}.scm 2>&1 | grep "Total time" echo -n "Chez: " time scheme --script examples/benchmarks/${BENCH}.scm 2>&1 | grep "Total time" echo -n "Racket: " time racket examples/benchmarks/${BENCH}.scm 2>&1 | grep "Total time" echo -n "Chibi: " time chibi-scheme examples/benchmarks/${BENCH}.scm 2>&1 | grep "Total time" ``` -------------------------------- ### Symbol identifiers Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Identifiers follow R7RS rules; most characters allowed except whitespace and delimiters. Shows examples of valid symbols. ```scheme hello list->vector string=? set! + ... a34kTMNs ``` -------------------------------- ### Attenuate file-write capability with a closure in Scheme Source: https://github.com/aalpar/wile/blob/master/docs/security/sandboxing.md Shows how to attenuate a file-writing capability in Scheme by wrapping it in a closure that checks the path prefix. The example contrasts full authority (write-file) with an attenuated version (safe-write-file) that rejects paths not starting with "/tmp/". Note that a lexical prefix test is not a containment check; use Wile's security.containedInRoot for canonicalized containment. ```scheme ;; Full authority: can write anywhere (define write-file open-output-file) ;; Attenuated: only accepts paths spelled under /tmp (define (safe-write-file path) (if (string-prefix? "/tmp/" path) (open-output-file path) (error "access denied" path))) ``` -------------------------------- ### Run all tutorial chapters with make tutorial-test Source: https://github.com/aalpar/wile/blob/master/docs/algebra/tutorial.md Run all tutorial chapters as part of the CI-enforced test suite. Any mismatch in expected output fails the build. ```shell make tutorial-test ``` -------------------------------- ### Enable R7RS library system with wile.WithLibraryPaths Source: https://github.com/aalpar/wile/blob/master/docs/extensions/libraries.md Shows how to enable the R7RS library system. Without WithLibraryPaths, (import ...) raises a configuration error. The default search path is ".", and custom paths are passed as arguments. ```go // Library system disabled (default) engine, _ := wile.NewEngine(ctx) // (import ...) → error: "no library registry configured" // Library system enabled with the default search path (".") engine, _ := wile.NewEngine(ctx, wile.WithLibraryPaths(), ) // Library system enabled with custom search paths engine, _ := wile.NewEngine(ctx, wile.WithLibraryPaths("/app/libs", "./vendor"), ) // Search order: /app/libs, ./vendor, . ``` -------------------------------- ### Table-Driven Test Example Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Uses a table-driven test structure with a slice of anonymous structs for test cases. Each case provides inputs and expected output, and the test iterates over them, calling the method and asserting with qt.Assert using valuestest.SchemeEquals. ```go func TestInteger_Add(t *testing.T) { tcs := []struct { in0 *Integer in1 Number out Number }{ {in0: NewInteger(1), in1: NewInteger(2), out: NewInteger(3)}, {in0: NewInteger(-1), in1: NewInteger(1), out: NewInteger(0)}, } for _, tc := range tcs { result := tc.in0.Add(tc.in1) qt.Assert(t, result, valuestest.SchemeEquals, tc.out) } } ``` -------------------------------- ### Run a single chapter with wile --file Source: https://github.com/aalpar/wile/blob/master/docs/algebra/tutorial.md Run a single tutorial chapter. Replace the path with the chapter file you want to execute. ```shell wile --file examples/algebra/tutorial/chapters/01-getting-started.scm ``` -------------------------------- ### Automatic library registration and extension primitives vs. library imports Source: https://github.com/aalpar/wile/blob/master/docs/extensions/libraries.md Two ASCII diagrams illustrate the automatic library registration flow during NewEngine and the relationship between extension primitives and library imports. The first shows how core, math, and system extensions contribute primitives and how snapshots record index ranges for library creation. The second contrasts direct top-level access (always available) with import access via a library (only with WithLibraryPaths). ```text NewEngine initialization: registration index ┌─ core.AddToRegistry(reg) 0 → C │ ├─ math.AddToRegistry(reg) C → M ├─ record snapshot: "math" = [C, M) │ ├─ system.AddToRegistry(reg) M → S ├─ record snapshot: "system" = [M, S) │ └─ ... (library system setup) ├─ Create LibraryRegistry ├─ For "math": create library (wile math) exporting prims[C:M] └─ For "system": create library (wile system) exporting prims[M:S] ``` ```text ┌──────────────────────────┐ │ Top-level environment │ │ │ Direct access: │ sqrt → ForeignClosure │ ← always available │ sin → ForeignClosure │ │ cos → ForeignClosure │ │ ... │ └──────────────────────────┘ ▲ │ (same closures) │ ┌──────────┴───────────────┐ Import access: │ Library (wile math) │ ← only with WithLibraryPaths │ exports: sqrt, sin, cos │ └──────────────────────────┘ ``` -------------------------------- ### Define reset and shift macros over Wile primitives Source: https://github.com/aalpar/wile/blob/master/docs/continuations/racket-primitives.md These two Scheme macros define the core delimited continuation operators `reset` and `shift` in terms of Wile's existing primitives. `reset` installs a prompt with the default tag; `shift` captures up to that prompt and aborts with a handler. The shipped definitions in `pkg/stdlib/lib/wile/control.scm` are more elaborate, using a `%prompt-reinstall` helper and wrapping `k` to re-delimit its result. ```scheme ;; reset installs a prompt with the default tag (define-syntax reset (syntax-rules () [(_ body ...) (call-with-continuation-prompt (lambda () body ...) (default-continuation-prompt-tag))])) ``` ```scheme ;; shift captures up to the prompt, then aborts with a handler (define-syntax shift (syntax-rules () [(_ k body ...) (call-with-composable-continuation (lambda (k) (abort-current-continuation (default-continuation-prompt-tag) (lambda () body ...))) (default-continuation-prompt-tag))])) ``` -------------------------------- ### Loss-signal suffix examples (WithAccuracy, Truncated, Lossy, Lossless) Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Illustrates the four loss-signal suffixes: *WithAccuracy returns the accuracy signal, *Truncated drops it by name, *Lossy acknowledges precision loss, and *Lossless refuses to drop information. The *Truncated form must always have a *WithAccuracy companion; *Lossless functions return an error when rounding would occur. ```go // *WithAccuracy — bridges Go big.Accuracy to the caller func (p *BigFloat) Float64WithAccuracy() (float64, big.Accuracy) func ToFloat64WithAccuracy(n Number) (float64, big.Accuracy, bool, error) func ToComplex128WithAccuracy(n Number) (Complex128Result, error) // *Truncated — name warns the reader at every call site func (p *BigFloat) Float64Truncated() float64 func (p *Rational) Float64Truncated() float64 // *Lossy — hot-path lossy reduction, contract documented at the function func NumberToComplex128Lossy(n Number) complex128 // *Lossless — refuses the lossy path func ToFloat64Lossless(n Number) (float64, error) func ToComplex128Lossless(n Number) (complex128, error) ``` -------------------------------- ### Creating test environments with NewNamespaceFrame and bootstrap Source: https://github.com/aalpar/wile/blob/master/docs/environment/system.md Shows how to create test environments: a simple namespace frame, a full frame with primitives via bootstrap.NewNamespaceFrame, and configuring the library environment factory for library tests. ```go func TestSomething(t *testing.T) { // Simple environment for unit tests env := environment.NewNamespaceFrame() // Or with full primitives env, err := bootstrap.NewNamespaceFrame(context.TODO()) if err != nil { t.Fatal(err) } // For tests involving libraries env.Namespace().SetLibraryEnvFactory(bootstrap.NewLibraryEnvironmentFrame) } ``` -------------------------------- ### Create Project Board via CLI Source: https://github.com/aalpar/wile/blob/master/scripts/README.md Creates a GitHub Project board via CLI. Prints manual steps for web UI configuration. The web UI is recommended instead; follow docs/dev/project-board-setup.md for detailed instructions (updated for 2026 GitHub Projects v2 UI). ```bash ./scripts/create-project-board.sh ``` -------------------------------- ### Create baseline Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README-USAGE.md Create a baseline by running the canonical benchmarks and copying the results to baseline.csv. ```bash cd examples/benchmarks ./run-canonical.sh cp canonical-results-*.csv baseline.csv ``` -------------------------------- ### Run individual benchmark from examples/benchmarks Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README-USAGE.md Run an individual benchmark from the examples/benchmarks directory using the Wile interpreter. ```bash cd examples/benchmarks ../../dist/wile --file tak.scm ``` -------------------------------- ### Simple extension with NewDescribedExtension Source: https://github.com/aalpar/wile/blob/master/docs/extensions/architecture.md Creates a simple extension using the NewDescribedExtension adapter, which takes a name, a description, and a function that registers primitives. The function adds a primitive with the PhaseSetRuntime phase and returns nil on success. ```go var Extension = registry.NewDescribedExtension("myext", "Brief description of this extension.", func(r *registry.PrimitiveRegistry) error { r.AddPrimitive(spec, registry.PhaseSetRuntime) return nil }) ``` -------------------------------- ### Build and run Wile from command line Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Build Wile and run it from the command line. Use `--file` to execute a script, `--interactive` to enter the REPL after running a file, and `-e` to evaluate an expression directly. ```bash make build # Build to ./dist///wile ./dist///wile # Start REPL ./dist///wile --file program.scm # Run file ./dist///wile --file program.scm --interactive # Run file then REPL ./dist///wile -e '(+ 1 2)' # Evaluate expression ``` -------------------------------- ### Example Problem Statement Source: https://github.com/aalpar/wile/blob/master/docs/dev/debug-methodology.md Example of a problem statement for a specific bug where `(let ((x 8)) (or #f (or #f x)))` returns `#f` instead of `8`. ```markdown ## Problem Statement **Symptom**: `(let ((x 8)) (or #f (or #f x)))` returns `#f` **Expected**: Should return `8` (user's `x` value) **Minimal reproduction**: The expression above in the REPL ``` -------------------------------- ### Run all Wile Scheme benchmarks Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README.md Shell script loop to run every benchmark file in the examples/benchmarks directory. It skips the README.md file and prints the benchmark name before executing it. ```bash for bench in examples/benchmarks/*.scm; do [ "$bench" = "examples/benchmarks/README.md" ] && continue echo "Running $(basename $bench)..." ./dist/wile --file "$bench" echo "" done ``` -------------------------------- ### Creating Library Environments with NewChildRuntime Source: https://github.com/aalpar/wile/blob/master/docs/environment/system.md Shows the correct way to create an environment for libraries: share the caller's Namespace via NewChildRuntime, not NewNamespaceFrame. The wrong approach breaks syntax identity; the correct one isolates bindings and phase hierarchy while sharing the Namespace. ```go // WRONG: Creates new Namespace, breaks syntax identity // libEnv := environment.NewNamespaceFrame() // CORRECT: Share Namespace with caller callerTopLevel := callerEnv.Namespace() libEnv := callerTopLevel.NewChildRuntime() ``` -------------------------------- ### Phase-shifting import modifiers: for-syntax, for-template, for-meta Source: https://github.com/aalpar/wile/blob/master/docs/reference/scheme.md Phase-shifting import modifiers place library bindings at a phase other than 0. `for-syntax` makes bindings visible to macro transformers (phase 1), `for-template` places them at phase -1, and `for-meta 2` makes them visible to a nested `begin-for-syntax`. Shifts compose additively; a shift outside the `int8` phase range ([-128, 127]) is an error, e.g., `for-meta: phase 200 out of range [-128, 127]`. Nothing in Wile evaluates at phase -1, so `for-template` bindings are installed but never consulted. ```scheme (import (for-syntax (scheme base))) ; phase 1: visible to macro transformers (import (for-template (scheme base))) ; phase -1 (import (for-meta 2 (scheme base))) ; phase 2: visible to a nested begin-for-syntax ``` -------------------------------- ### If Statement Assignments: Separate Assignment from Comparison Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Never combine assignment and comparison in a single if statement. Separate assignments onto their own lines, as shown in the correct examples; the avoid examples show the prohibited combined forms. This keeps operations atomic, aids debugging with breakpoints, and makes variables available in the outer scope. ```go // Correct - assignment on separate line err := doSomething() if err != nil { return err } // Correct - multiple assignments separated result, err := process(input) if err != nil { return nil, err } // Avoid - combined assignment and comparison if err := doSomething(); err != nil { // DON'T return err } // Avoid - combined with type assertion if v, ok := x.(SomeType); ok { // DON'T // ... } ``` -------------------------------- ### Tiny CLOS class and generic function example Source: https://github.com/aalpar/wile/blob/master/docs/types/scheme-types-records-mop.md Shows Tiny CLOS's non-standard Scheme API for defining classes, creating generic functions, and adding methods with multiple dispatch. Uses make-class, make-generic, make-method, add-method, and slot-ref. The example defines and classes and a distance generic with methods for each. ```scheme ;; Tiny CLOS style (not standard Scheme) (define (make-class (list ) (list (list 'x) (list 'y)))) (define (make-class (list ) (list (list 'z)))) ;; Generic function with methods (define distance (make-generic)) (add-method distance (make-method (list ) (lambda (call-next-method p) (sqrt (+ (sqr (slot-ref p 'x)) (sqr (slot-ref p 'y))))))) (add-method distance (make-method (list ) (lambda (call-next-method p) (sqrt (+ (sqr (slot-ref p 'x)) (sqr (slot-ref p 'y)) (sqr (slot-ref p 'z))))))) ``` -------------------------------- ### Run all canonical benchmarks Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/README-USAGE.md Run all 16 canonical Gabriel benchmarks from the examples/benchmarks directory. Results are saved to a timestamped CSV file. ```bash cd examples/benchmarks ./run-canonical.sh ``` -------------------------------- ### Zero-configuration engine with embedded libraries Source: https://github.com/aalpar/wile/blob/master/docs/embedding/source-loading.md Configures an engine with embedded libraries (stdlib.FS), OS filesystem access, and library paths. WithLibraryPaths() is required for (import ...) to work. When both embedded and OS libraries exist, the embedded FS wins because it is added first. ```go eng, err := wile.NewEngine(ctx, wile.WithProfile(wile.KitchenSink), wile.WithSourceFS(stdlib.FS), // embedded libs wile.WithSourceOS(), // user files on disk wile.WithLibraryPaths(), // enables (import ...); required ) ``` -------------------------------- ### Create engine with WithSourceFS and WithSourceOS Source: https://github.com/aalpar/wile/blob/master/docs/embedding/source-loading.md Constructs an engine with a virtual FS resolver searched first and an OS resolver searched second. Once any resolver option is specified, the implicit OS default is suppressed, so OS access must be explicitly added with WithSourceOS(). ```go eng, err := wile.NewEngine(ctx, wile.WithSourceFS(stdlib.FS), // FSFileResolver — searched first wile.WithSourceOS(), // OSFileResolver — searched second ) ``` -------------------------------- ### Create engine with ConsoleWithLoad profile and library path Source: https://github.com/aalpar/wile/blob/master/docs/security/sandboxing.md Creates an engine with the ConsoleWithLoad profile and a library path. Libraries loaded from /tmp/stagedlib inherit the profile's restrictions transitively; calls outside /tmp are denied at runtime, and primitives absent from the profile fail at compile time. Under the plain Console profile, file-backed import/include is refused before the file is opened, so pair WithLibraryPaths with ConsoleWithLoad or a custom authorizer that admits the library root. ```go engine, err := wile.NewEngine(ctx, wile.WithProfile(wile.ConsoleWithLoad), wile.WithLibraryPaths("/tmp/stagedlib"), ) ``` -------------------------------- ### Context parameter placement in Go Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md When a context is needed, it is always the first parameter after the receiver. This example shows parseImportSet with ctx as the first parameter. ```go func parseImportSet(ctx context.Context, expr syntax.SyntaxValue) (*ImportSet, error) { ... } ``` -------------------------------- ### wile://session resource response Source: https://github.com/aalpar/wile/blob/master/docs/embedding/mcp.md Example response from the wile://session resource. Shows the JSON shape returned when the engine is initialized, including the timeoutSeconds field. ```json { "initialized": true, "libraryCount": 42, "primitiveCount": 180, "timeoutSeconds": 30 } ``` -------------------------------- ### Create and make executable bench-wile wrapper Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/BENCHMARKING.md Creates a wrapper script bench-wile that runs Wile with the given benchmark file, then makes it executable. The script is required by the r7rs-benchmarks suite, which expects a bench- executable. ```bash #!/usr/bin/env bash # bench-wile - Wrapper for Wile Scheme in r7rs-benchmarks WILE="/path/to/wile/dist/wile" # The benchmark suite expects: bench- # It provides input via stdin and measures wall-clock time exec "$WILE" --file "$1" ``` ```bash chmod +x bench-wile ``` -------------------------------- ### Warmup run before actual benchmark runs Source: https://github.com/aalpar/wile/blob/master/examples/benchmarks/BENCHMARKING.md Perform a warmup run to populate disk cache and then run the benchmark three times for accurate results. The warmup output is discarded, and the actual runs are not redirected. ```bash # Warmup run (discard results) ./dist/wile --file examples/benchmarks/tak.scm > /dev/null 2>&1 # Actual benchmark runs for i in {1..3}; do ./dist/wile --file examples/benchmarks/tak.scm done ``` -------------------------------- ### Create Plan Issues from plans/ Directory Source: https://github.com/aalpar/wile/blob/master/scripts/README.md Preview what would be created with --dry-run (recommended first), then run without it to create the issues. Reads all .md files in plans/, extracts title, status, and phases, assigns labels based on filename/content, creates a GitHub issue with a link back to the plan document, and skips files marked as 'Complete'. ```bash ./scripts/create-plan-issues.sh --dry-run ``` ```bash ./scripts/create-plan-issues.sh ``` -------------------------------- ### Private helper naming in Go Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Use descriptive lowercase names for file-private helper functions. The example shows three signatures from prim_xxx.go: extractInteger, toBigFloat, and maybeSimplify. ```go // In prim_xxx.go func extractInteger(v values.Value, name string) (int64, *big.Int, bool, error) func toBigFloat(n Number) *BigFloat func maybeSimplify(real, imag Number) Number ``` -------------------------------- ### If Statement Exception: Short-Circuit Boolean Expression Source: https://github.com/aalpar/wile/blob/master/CODING_STYLE.md Exception to the if-assignment rule: short-circuit boolean expressions without assignment are acceptable. This example shows a combined condition that does not assign a variable. ```go if x != nil && x.IsValid() { // OK - no assignment // ... } ``` -------------------------------- ### Run hygiene demo with Wile Source: https://github.com/aalpar/wile/blob/master/docs/learn/macro-system.md Runs the hygiene-demo.scm program with the Wile interpreter. The path uses Go environment variables to locate the built binary. ```bash ./dist/$(go env GOOS)/$(go env GOARCH)/wile hygiene-demo.scm ```