This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problems with macro-defining macros


Following Kjetil and Per's discussion, I tried the experiment below, but I can't get it to work (I've tried it only in the REPL). I did manage to get a trivially modified version of it to work in PLT Scheme 360 (changes in comments).


(define (alter-syntax-datum proc stx) ;; must use define-syntax-datum in PLT (datum->syntax-object stx (proc (syntax-object->datum stx))))

(define-syntax define-symbol-altering-macro
(syntax-rules ()
((_ (macro-name arg) expr . exprs)
(define-symbol-altering-macro macro-name (lambda (arg) expr . exprs)))
((_ macro-name proc)
(define-syntax macro-name
(lambda (stx)
(syntax-case stx ()
((_ sym . args)
(let ((new-sym (alter-syntax-datum proc (syntax sym))))
;; must use #, in PLT
#`(,new-sym . args)))))))))


(define-symbol-altering-macro (call-reversename sym)
  (string->symbol
   (list->string
    (reverse
     (string->list
      (symbol->string sym))))))

(call-reversename yalpsid 50)
=> <stdin>:40:1: circular list is not allowed after #<syntax mys in #171>



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]