Skip to content

Add extensible environment system#180

Open
vydd wants to merge 3 commits intomasterfrom
extensible-environment
Open

Add extensible environment system#180
vydd wants to merge 3 commits intomasterfrom
extensible-environment

Conversation

@vydd
Copy link
Owner

@vydd vydd commented Jan 18, 2026

Summary

  • Add infrastructure for defining environment properties outside environment.lisp
  • Includes workaround for noisy library export issue (first commit)

Changes

Extensible Environment

  • env struct gains extensions hash-table for dynamic properties
  • define-environment-property macro generates accessors/setters automatically
  • Properties initialized via initialize-environment-extensions during env setup
  • New exports: define-environment-property, *env*

Example Usage

(define-environment-property :my-cache
  (make-hash-table))

;; Then use:
(env-my-cache *env*)
(setf (env-my-cache *env*) new-value)

Why

This enables future refactoring where properties like :pen, :font can be moved to their respective files while maintaining backward compatibility. It's the first step toward a cleaner backend separation (see PR #162).

Test plan

  • Sketch loads successfully
  • New properties can be defined and accessed
  • Existing functionality unaffected

🤖 Generated with Claude Code

Add infrastructure for defining environment properties outside of
environment.lisp, near the code that uses them.

New features:
- env struct has 'extensions' hash-table for dynamic properties
- define-environment-property macro generates accessors and setters
- initialize-environment-extensions called during env setup
- Exports: define-environment-property, *env*

Example usage:
  (define-environment-property :my-cache
    (make-hash-table))
  ;; Then use (env-my-cache *env*) and (setf (env-my-cache *env*) val)

This enables future refactoring where properties like :pen, :font can
be moved to their respective files while maintaining backward compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vydd vydd force-pushed the extensible-environment branch from 57e3731 to a58a5ba Compare January 18, 2026 18:10
vydd and others added 2 commits January 18, 2026 19:20
Move pen property from fixed env struct slot to use the new
define-environment-property macro. This demonstrates the migration
pattern for other properties.

Changes:
- Add define-environment-property :pen in pen.lisp
- Remove (pen nil) slot from env struct
- Remove pen initialization from initialize-environment
- Simplify make-default-pen (no longer needs memoization)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace auto-generated make-env with custom version that:
  - Initializes extension properties automatically
  - Accepts extension keywords: (make-env :pen my-pen)
  - Validates keywords against registered initializers (catches typos)

- Add copy-env that properly copies extension properties
  (auto-generated copier only shallow-copies the extensions hash table)

- Remove initialize-environment-extensions call from initialize-environment
  since make-env now handles it

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant