M-OZ BLOG

Scheme-users.jpTwitter

# 2008/10/14(Tue) : 今日のマクロ
Gauche には regexp-replace-all という文字列置換の便利な手続きがあるが、
ネストするとかっこわるいので、

(regexp-replace-all #/[A-Z]/
 (regexp-replace-all #/[0-9]+/ "ABC1234GHI" "DEF")
  "abc")

まとめて書けるマクロを考えてみた。

(define-syntax $replace
 (syntax-rules ()
  ((_ str r s) (regexp-replace-all r str s))
  ((_ str r1 s1 r2 s2 ...)
   ($replace ($replace str r1 s1) r2 s2 ...))))

string-tr も組み合わせて、
文字列操作に特化したマクロを考えてみるのもいいかもしれない。

[TOP] [ALL]