ちっぽけな名前空間を作るマクロを作成

elisp名前空間を作る機能がないので、毎回同じような関数を違うprefixで定義しなければならなくてすごく面倒。
というか、関数の名前が長くなりがち。面倒。
なのでwith-prefixというマクロを作った。

すごく、強引だけどdefmacro!が認められるのだとしたらあって良い気がする。
とりあえず、個人的に利用するつもり。

使い方

(with-prefix 
    ((@ with-prefix:)
     (util. with-prefix-util:))
  
  (defun @odd? (x) 
    "check a received argument is odd number or not"
    (if (<= x 0) nil (@even? (- x 1))))
  
  (defun @even? (x)
    (if (<= x 0) t (@odd? (- x 1))))

  (defun util.out (&rest args) 
    (message (prin1-to-string args)))

  (util.out (@odd? 9) 
        (@even? 9) 
        (funcall '@odd? 10)
        (apply '@even? '(10))))

定義されたシンボルの対応関係

だいたいこんな感じの対応。

ファイルの中 実際に定義される名前
@odd? with-prefix:odd?
@even? with-prefix:even?
util.out with-prefix-util:out

もちろん、funcall,applyからも使えます。

あと、

もちろん、M-x find-function with-prefix:odd?で@odd?の定義位置に飛べますよ。
(describe-functionの*Help*に表示される。ファイルパスから定義位置に飛べる)

コードはgist
いんすとーるは

git clone git://gist.github.com/923807.git gist-923807
cp gist-923887/with-prefix.el <path> # pathはemacsのload-pathのどれか。