#lang scheme/base

;; Misc forth syntax utilities.

(require
 "../tools.ss"
 "../scat.ss"
 (for-syntax
  "parser-tx.ss"
  scheme/base))

(provide
 (all-defined-out))




;; Analogous to the 'compositions' macro, this performs compile time
;; substitutions.

(define-sr (substitutions ns
             ((name pat ...) temp) ...)
  (begin
    (define-syntax-ns ns name
      (forth-rules () ((_ pat ...) temp))) ...))


;; Like 'substitutions', but translate code using a different
;; compiler and splice it in.

(define-syntax-rule (primitive-substitutions ns lang: (pat code) ...)
  (begin
    ;; Evaluation the pattern to check if the names are actually
    ;; defined, but that doesn't work because it includes pattern
    ;; names as well..
    ;; (begin (lang: . code) ...) ;; test-eval it
    (substitutions ns (pat (,(lang: . code))) ...)))

