importしたライブラリでコードを変形するマクロ

追記 :
http://www.het.brown.edu/people/andre/macros/

   * Wrapped = Unwrapped (r6rs optional):
   
       A wrapped syntax object is the same as an unwrapped syntax 
       object, and can be directly manipulated using car, cdr, ... 
       without syntax-case deconstruction.  
       This should make porting of legacy low-level macros,
       e.g., explicit renaming or define-macro, easier.
       Macros depending on this feature wil not be 
       portable to all r6rs implementations.  

これと、次のPhase semanticsあたりが問題のようだ。

以前の内容

結局、

(import (for (skymosh-utils utils) expand)
        (rnrs))

(define-syntax defseq
  (lambda (x)
    (define (createslot i spec)
      (list 'define spec i))
    (syntax-case x ()
      ((p spec)
       (with-syntax ((lst (datum->syntax (syntax p)
                            (cons 'begin
                                  (map-with-index
                                     createslot
                                     (syntax->datum (syntax spec)))))))
         (syntax lst))))))

(defseq (a b c d))

(display c)(newline)

のようになった。defseqは書かれた順番に(define a 0)(define b 1)...のように展開される。
ikarus,PLT,mosh,ypsilonの全部で期待通りに動く。map-with-indexは(skymosh-utils utils)に入っている。
もっと良い手法があるはずだけど。。

  • 地味に"インタプリタR6RSモードで起動する"方法が分からなくて不便だった。
    • この中ではPLTが一番ライブラリに関して厳しい。ファイル先頭に#!r6rsを入れ、拡張子をssかslsにする。
  • Ypsilonで動くけど他で動かないというケース(変換子からsyntax以外を出力しても動くケースが有る?)に何度か遭遇した。
  • datum->syntaxに(syntax _)を渡すと期待通りに動かない。
  • やっぱりR6RSのマクロで存在しない識別子を生成するのは良くない。

人に聞かないとわからないレベル。