Last active
March 7, 2024 11:05
-
-
Save yuhr/bba4de4b34db940dcfba2b756f6cbc32 to your computer and use it in GitHub Desktop.
macro.ss: Defining macros simply on chez scheme.
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
#| | |
macro.ss | |
Defining macros simply on chez scheme. This code is in the public domain. | |
|# | |
(import (scheme)) | |
(define-syntax macro | |
(syntax-rules () | |
((k (name . args) body ...) | |
(macro name (lambda args body ...))) | |
((k name transformer) | |
(define-syntax name | |
(lambda (stx) | |
(syntax-case stx () | |
((l . sv) | |
(let* ((v (syntax->datum (syntax sv))) | |
(e (apply transformer v))) | |
(if (eq? (void) e) | |
(syntax (void)) | |
(datum->syntax (syntax l) e)))))))))) | |
; (macro (m1 x) `(display ,x)) | |
; (macro (m2 x) (display x) (display #\a)) | |
; (macro (m3 x) (let ((y (+ x 3))) | |
; (display y) | |
; `(display ,x))) | |
; (begin | |
; (m1 1) | |
; (m2 2) | |
; (m3 3)) ; => 2a613 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment