Skip to content

Implement define-macro special form#8

Merged
mark-friedman merged 5 commits intomainfrom
feature/define-macro-433352381041054241
Mar 20, 2026
Merged

Implement define-macro special form#8
mark-friedman merged 5 commits intomainfrom
feature/define-macro-433352381041054241

Conversation

@mark-friedman
Copy link
Copy Markdown
Owner

Implemented the define-macro special form, providing Common Lisp-style unhygienic macros.

Changes:

  1. Core Implementation:

    • Added analyzeDefineMacro to src/core/interpreter/analyzers/core_forms.js.
    • This function evaluates the transformer body in a fresh, isolated interpreter instance during analysis.
    • It registers a wrapper function in the macro registry that invokes the transformer closure with the macro arguments.
    • Added define-macro to SYNTAX_KEYWORDS and SPECIAL_FORMS in src/core/interpreter/library_registry.js.
  2. Library Support:

    • Created src/core/scheme/define-macro.sld, exporting define-macro.
    • Updated repl.js and web/main.js to automatically import (scheme define-macro) into the initial environment.
    • Updated tests/run_scheme_tests_lib.js to load and import (scheme define-macro) for test files.
  3. Testing:

    • Added tests/functional/test_defmacro.scm covering basic usage, return values, and explicit transformer syntax.
    • Added this test to tests/test_manifest.js.

Test Results:

  • Node.js Test Suite: 2021 passed, 0 failed, 7 skipped.
  • Verified manual REPL usage.

PR created automatically by Jules for task 433352381041054241 started by @mark-friedman

Implemented the `define-macro` special form, providing Common Lisp-style unhygienic macros.
- Added `analyzeDefineMacro` to `src/core/interpreter/analyzers/core_forms.js`.
- Created `src/core/scheme/define-macro.sld`.
- Updated `repl.js` and `web/main.js` to import `(scheme define-macro)` by default.
- Added support for both `(define-macro (name . args) body)` and `(define-macro name transformer)` syntax.
- Updated `CHANGES.md`.

Co-authored-by: mark-friedman <1743690+mark-friedman@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Removed extraneous explanations related to macro call processing.
Copy link
Copy Markdown
Owner Author

@mark-friedman mark-friedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;; This library exports the define-macro special form.
;; It is loaded by default in the REPL environment.

(define-library (scheme define-macro)
Copy link
Copy Markdown
Owner Author

@mark-friedman mark-friedman Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules
define-macro should be in the (scheme-js define-macro) library since it's not in standard Scheme.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've moved the library definition to the scheme-js namespace since it's an extension, and also moved the file to src/extras/scheme/define-macro.sld to match the project's organization for non-standard libraries.

google-labs-jules bot and others added 3 commits March 20, 2026 22:49
- Changed library name to `(scheme-js define-macro)`
- Moved file to `src/extras/scheme/define-macro.sld`
- Updated all imports in `repl.js`, `web/main.js`, and `tests/run_scheme_tests_lib.js`

Co-authored-by: mark-friedman <1743690+mark-friedman@users.noreply.github.com>
Restored the original `CHANGES.md` and appended the `define-macro` walkthrough to the end of the file instead of overwriting it.

Co-authored-by: mark-friedman <1743690+mark-friedman@users.noreply.github.com>
Added the date to the `define-macro` walkthrough heading in `CHANGES.md` to match the style of other entries.

Co-authored-by: mark-friedman <1743690+mark-friedman@users.noreply.github.com>
@mark-friedman mark-friedman merged commit fd08480 into main Mar 20, 2026
1 check passed
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