Living Code: docstrings, introspection, self-modification, evolve#30
Draft
HelgeSverre wants to merge 7 commits into
Draft
Living Code: docstrings, introspection, self-modification, evolve#30HelgeSverre wants to merge 7 commits into
HelgeSverre wants to merge 7 commits into
Conversation
…elf-modification Phase 1 (Layer 0+1): Docstrings & Doctests - Docstring support in defn/define/defmacro (optional string before params) - (meta sym) returns map with :name/:doc/:type/:arity/:params/:variadic?/:source/:file - (doc sym) pretty-prints documentation to stderr - (doc/search query) searches names and docstrings - (doctest sym) runs >>> examples from docstrings - Doctest parser/runner in crates/sema-eval/src/doctest.rs - sema test CLI command Phase 2 (Layer 2): Self-Reading - (source-of sym) returns source text of definitions - ;;@key value directive comment parser in sema-reader - (read-source path) parses .sema files into structured definition maps - Glob support for read-source Phase 3 (Layer 3+4): LLM-Powered Introspection - (ask target question) LLM-powered code analysis - (ask/code target instruction) returns parsed Sema code from LLM - (heal! sym) auto-repair loop using doctests as spec - sema test --heal CLI flag Phase 4 (Layer 6): Runtime Self-Modification - (observe! sym n callback) wraps function with call logger - (become! sym new-def) replaces definition with doctest validation - (history sym) returns version history list - (rollback! sym version) restores previous version - (freeze! sym) permanently prevents mutation - (bench thunk n) structured benchmarking with timing stats Architecture: metadata stored on Env via parallel SpurMap alongside bindings. Introspection forms are special forms (need calling Env). LLM calls use call_llm_complete() helper via env binding lookup. Amp-Thread-ID: https://ampcode.com/threads/T-019c9195-39f2-76a9-9f61-e37b65785c4f Co-authored-by: Amp <[email protected]>
…ta sync - become!: temporarily install candidate in env during doctest validation so recursive calls resolve to the new definition, not the old one. Restores old definition if doctests fail. - become!: update :source metadata after successful replacement. - rollback!: save current :source to history entry before restoring. - rollback!: restore :source metadata from the history entry. Amp-Thread-ID: https://ampcode.com/threads/T-019c9195-39f2-76a9-9f61-e37b65785c4f Co-authored-by: Amp <[email protected]>
Phase 5 of Living Code: (evolve :name ... :spec ... :fitness fn :seed-prompt ...) generates candidate function implementations via LLM, evaluates them against a spec (inline or doctest-based), computes fitness via user callback, and iteratively breeds/mutates the best candidates using crossover and mutation. Components: - evolve.rs: config parsing, spec runner, fitness computation, types - special_forms.rs: eval_evolve (evolution loop), generate_candidate, log_generation - 9 integration tests covering all config validation error paths Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-019c91b8-b2f4-70d3-ac9c-f7b1c3e12dd6
…ation, evolve Comprehensive documentation page covering all 5 phases of Living Code: - Docstrings & Doctests (defn, doc, doc/search, doctest, meta, CLI) - Source Introspection (source-of, reader directives, read-source) - Conversational Introspection (ask, ask/code, heal!) - Runtime Self-Modification (observe!, become!, history, rollback!, freeze!) - Genetic Programming (evolve with spec modes, fitness functions) Includes 3 end-to-end scenarios (self-healing parser, adaptive memoization, evolving for performance) and best practices. Added to sidebar and LLM index. Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-019c91b8-b2f4-70d3-ac9c-f7b1c3e12dd6
Update all documentation to prefer (defn name (params) body) over (define (name params) body) for function definitions. define remains the canonical form for value bindings (define x 42). - special-forms.md: defn is now the primary heading, define section notes function shorthand is legacy, added preferred-style tip - All code examples across 18 doc files updated - defun references changed to defn (packages.md) - Prose references to define-as-function kept where explaining compatibility Amp-Thread-ID: https://ampcode.com/threads/T-019c91b8-b2f4-70d3-ac9c-f7b1c3e12dd6 Co-authored-by: Amp <[email protected]>
Metaprogramming (language/metaprogramming.md) covers introspection and runtime modification features that work without an LLM: - Docstrings, doctests, doc, doc/search, meta - source-of, reader directives, read-source - observe!, become!, history, rollback!, freeze! - bench - Scenarios: hot-swapping, profiling, doc generation Living Code (llm/living-code.md) now focuses on LLM-powered features: - ask, ask/code, heal!, evolve - References metaprogramming page for prerequisites Added Metaprogramming to Language Reference sidebar section. Amp-Thread-ID: https://ampcode.com/threads/T-019c91b8-b2f4-70d3-ac9c-f7b1c3e12dd6 Co-authored-by: Amp <[email protected]>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
become!/rollback!), and self-modificationevolvespecial form for LLM-driven genetic programmingdefnthe canonical function definition formTest plan
become!/rollback!recursive doctest validation and source metadata syncevolvewith an LLM provider configured