Create a new identifier using macros

I need a macro that creates a new type identifier

(new-name first second) => first-second

which can be used to define new top-level bindings

(define-syntax define-generic 
  (syntax-rules ()
    ((define-generic (name a b ...))
     (begin
       (define (new-name name data) 15)      ; <= create a new binding
       (define name (lambda (a b ...)
         (add (new-name name-data) 7))))))   ; <= use new identifier

If I installed! the binding value is "new name", then this should affect the newly created procedure.

+3
source share
2 answers

You cannot do this in pure R5RS. Fortunately, most popular Scheme implementations provide the correct macro system, in addition to the limited hygiene material R5RS:

(define-macro (new-name a b) (string->symbol (string-append (symbol->string a) "-" (symbol->string b))))

-1
source

Source: https://habr.com/ru/post/1788474/


All Articles