Skip to content
karimamerPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto-Fix System for Racket & Scheme AKA lazarus

This serves as an experimental project and provides an opportunity to revisit Scheme and Racket.

v2: #lang lazarus (Racket)

A self-healing Racket language. Write a program in #lang lazarus; if a form fails, lazarus repairs it — first with learned strategies, then via the Claude API — verifies the whole program against its checks, rewrites the source, and commits the heal to git.

#lang lazarus
(define total 10)
(displayln (+ totl 5))          ; typo — will be healed to (+ total 5)
(check-equal? (+ total 5) 15)   ; the bar a heal must pass
raco pkg install --link --auto ./lazarus   # once
racket broken.rkt                          # heals, verifies, rewrites, commits
racket broken.rkt                          # now runs clean

Rules of the game:

  • A fix only persists when the file's checks pass (yours, or generated ones written to <file>.checks.rkt for review). Failed verification leaves the file byte-identical.
  • Persistence requires a clean git state for the file; every heal is one auditable commit (git revert to undo).
  • Verified LLM fixes are generalized into strategy modules under strategies/, validated, and reused on future runs — the system extends its own code, and git log strategies/ is the record of it learning.
  • No ANTHROPIC_API_KEY? Built-in and learned strategies still heal; learning and check generation are disabled.

Design: docs/superpowers/specs/2026-09-03-lazarus-lang-design.md. The v1 expression-level system remains under src/ (Racket and Chez Scheme).

Prerequisites

For Racket

  • Racket 8.0+ installed
  • Required packages: net/http-client, json, racket/system

For Scheme

  • Chez Scheme 9.5+ (recommended) or compatible Scheme implementation
  • Basic R6RS/R7RS support

API Access (Optional but Recommended)

  • Anthropic API key for Claude models (primary)
  • OpenAI API key for GPT models (fallback)

Setup

  1. Configure API Keys (for LLM integration):

    export ANTHROPIC_API_KEY=your-anthropic-api-key-here
    # Optional fallback:
    export OPENAI_API_KEY=your-openai-api-key-here
  2. Clone and Navigate:

    git clone <repository-url>
    cd experiment

Usage

Basic Auto-Fix System

Racket

#lang racket
(require "src/racket/auto-fix.rkt")

;; Evaluate with automatic error fixing
(safe-eval-with-fix '(+ 1 2 3))        ; Works normally: 6

;; Handle undefined variables
(safe-eval-with-fix '(+ undefined-var 5))  ; Attempts to fix

;; Fix type errors
(safe-eval-with-fix '(+ "hello" 5))     ; Suggests type conversion

;; Run example demonstrations
(example-usage)

Scheme

(load "src/scheme/auto-fix.scm")

;; Same syntax as Racket
(safe-eval-with-fix '(+ 1 2 3))
(safe-eval-with-fix '(+ undefined-var 5))
(example-usage)

Metaprogramming System

Racket

#lang racket
(require "src/racket/meta-auto-fix.rkt")

;; Use the with-auto-fix macro for expressions
(with-auto-fix (/ 10 0))               ; Handles division by zero

;; Define functions with built-in error handling
(auto-fix-function safe-divide (x y)
  (/ x y))

(safe-divide 10 0)                     ; Automatically handles errors

;; Create custom error handlers
(define-auto-fix-handler my-handler syntax-error
  (lambda (condition code)
    (displayln "Custom syntax fix applied")))

Scheme

(load "src/scheme/meta-auto-fix.scm")

;; Same macro syntax
(with-auto-fix (/ 10 0))

;; Define auto-fixing functions
(auto-fix-function safe-divide (x y)
  (/ x y))

;; Create custom fix modules
(define-auto-fix-module my-system
  (safe-divide safe-multiply))

Testing

Run the comprehensive test suite:

Racket Tests

# From project root directory:
racket tests/racket/test-auto-fix.rkt    # Basic functionality
racket tests/racket/meta-test.rkt        # Metaprogramming features

Scheme Tests

# From project root directory (Chez Scheme):
scheme --script tests/scheme/test-auto-fix.scm              # Basic functionality
scheme --script tests/scheme/meta-test.scm                  # Metaprogramming features
scheme --script tests/scheme/test-metaprog-comprehensive.scm

API Configuration

Anthropic Claude (Primary)

export ANTHROPIC_API_KEY=your-key
# Uses: claude-sonnet-4-6 model
# Endpoint: https://api.anthropic.com/v1/messages

OpenAI GPT (Fallback)

export OPENAI_API_KEY=your-key
# Uses: gpt-3.5-turbo model
# Endpoint: https://api.openai.com/v1/chat/completions

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages