forked from alex-eg/sex
modularize sex
Also rename macros to sex-macros, module-system to sex-modules for clarity, uniformity, and to avoid name clashes with Chicken's units/modules named "macros" and "modules"
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
(declare (unit sex-macros))
|
||||
|
||||
(import
|
||||
scheme
|
||||
(only fmt fmt)
|
||||
(chicken base)
|
||||
(chicken plist)
|
||||
(chicken string))
|
||||
|
||||
(define (cat-syms s-1 s-2)
|
||||
(import fmt)
|
||||
(fmt #f s-1 s-2))
|
||||
|
||||
(define (cat sym-1 sym-2)
|
||||
@@ -14,18 +14,20 @@
|
||||
(define (register-macro name arglist body)
|
||||
(put! name 'sex-macro
|
||||
`(lambda ,arglist
|
||||
(import scheme
|
||||
(only sex-macros cat))
|
||||
,@body)))
|
||||
|
||||
(define (get-macro name)
|
||||
(eval (get name 'sex-macro)))
|
||||
|
||||
(define (sex-macro? form)
|
||||
(define (macro? form)
|
||||
(and (list? form)
|
||||
(symbol? (car form))
|
||||
(get (car form) 'sex-macro)))
|
||||
|
||||
(define (apply-macro form)
|
||||
(assert (sex-macro? form)
|
||||
(assert (macro? form)
|
||||
(fmt #f (car form) " is not a macro"))
|
||||
(apply (get-macro (car form))
|
||||
(cdr form)))
|
||||
|
||||
Reference in New Issue
Block a user