enable semen-walk-form to embed results (for macro processing)

This commit is contained in:
2025-10-26 11:39:00 +03:00
committed by Pavel Kulyov
parent b4145255bd
commit 0ad1d01fec

View File

@@ -96,22 +96,36 @@
form form
(lambda (subform env) (lambda (subform env)
(if (sex-macro? subform) (if (sex-macro? subform)
(apply-macro subform) (cons semen-walk-embed-result (semen-apply-macro subform (list)))
subform)) subform))
#f)) #f))
;;; TODO: for greater inspiration, see SBCL's walk.lisp and their ;;; semen-walk-form and friends: form walker with various abilities.
;;; template system. Maybe it is worth it to implement something ;;; By default, replaces walked form with walk-fn result But may
;;; similar here ;;; perform additional operations depending of what the walk function
;;; has requested.
;;; For inspiration, see SBCL's walk.lisp and their template
;;; system.
(define semen-walk-embed-result (gensym)
;; For cases when result is a list which must be embedded in the
;; form, e.g. when it returned from a macro
)
(define (semen-walk-form form walk-fn env) (define (semen-walk-form form walk-fn env)
(if (atom? form) form (if (atom? form) form
(let ((new-form (walk-fn form env))) (let ((new-form (walk-fn form env)))
(cond ((not (eq? form new-form)) (cond ((not (eq? form new-form))
(semen-walk-form new-form walk-fn env)) (semen-walk-form new-form walk-fn env))
(else (recons (else
new-form (let ((new-car (semen-walk-form (car new-form) walk-fn env))
(semen-walk-form (car new-form) walk-fn env) (new-cdr (semen-walk-form (cdr new-form) walk-fn env)))
(semen-walk-form (cdr new-form) walk-fn env))))))) (cond ((and (pair? new-car)
(eq? (car new-car) semen-walk-embed-result))
(append (cdr new-car) new-cdr))
(else
(recons new-form new-car new-cdr)))))))))
;;; Typdef ;;; Typdef