[Mew-dist 15496] Re: 弱気

Shun-ichi GOTO gotoh at example.com
2000年 12月 14日 (木) 21:30:11 JST


## うーん...

>>>>> at Thu, 14 Dec 2000 20:34:13 +0900
>>>>> kazu == Kazu Yamamoto (山本和彦) <kazu at example.com> said,

kazu> a.el に
kazu> 	defsubst foo
kazu> 	defmacro bar
kazu> が定義してあったとします。これを a.elc にコンパイルします。

kazu> b.elc で、foo、bar を参照していたとします。

kazu> a.el の foo、bar の定義が変った場合、何がおきますか?

定義が変わった、というのは defsubst/defmacro の記述内容が変わり
それを評価したあとの事をいってるのかと思いますが、
『何が起きるか?』 というのは、元の a.elc と b.elc がロードされている
emacs 上で foo と bar の再定義 and 再評価 をした場合に b.elc で定義され
ている(foo,bar を参照している)関数にどんな変化があるか? 
あるいは a.el をコンパイルし、b.el をコンパイルし、a.el を修正し
a.el をコンパイルした後に b.el をロードすると、b.el での定義内容は
a.el の修正を反映しているか?
という事ですかね。

... であれば変化はないでしょう。foo の更新も bar の更新も 影響を
受けません。b.el のコンパイル時点で(両者は inline 展開されるので)
全ては確定し、外部関連が無くなります。


kazu> foo の定義は古いままだと思うのですが、bar って動的に新しいものにその場
kazu> で展開されませんでしたっけ?

その場ってどの場かなぁ... 
b.elc のコンパイル済みの関数定義の中のことをいってるのかなぁ。

以下のようなテストでは疑問は解消しませんか?



(defsubst foo (s) (concat s "-foo"))
(defmacro bar (s) `(concat ,s "-bar"))
(defun baz (a)
  (cons (foo a) (bar a)))

上記をeval-region した後では
(symbol-function 'baz)
=> (lambda (a) (cons (foo a) (bar a)))

baz を呼び出してみると
(baz "take#0")
=> ("take#0-foo" . "take#0-bar")

で baz をbyte-compile してから呼び出してみる
(byte-compile 'baz)
(baz "take#1")
=> ("take#1-foo" . "take#1-bar")

一緒ですね。その後

(defsubst foo (s) (concat s "-FOO"))
(defmacro bar (s) `(concat ,s "-BAR"))

を評価(再定義)した後では
(baz "take#2")
=> ("take#2-foo" . "take#2-bar")

変化無いですね。
で、再度 baz のdefun を評価してから実行してみると
(baz "take#3")
=> ("take#3-FOO" . "take#3-BAR")

baz を再コンパイルしても同様
(byte-compile 'baz)
(baz "take#4")
=> ("take#4-FOO" . "take#4-BAR")

ですね。

あるいは

a.el:
(defsubst foo (s) (concat s "-foo"))
(defmacro bar (s) `(concat ,s "-bar"))
(provide 'a)

b.el:
(require 'a)
(defun baz (a)
  (insert (foo a) "\n")
  (insert (bar a) "\n"))
(provide 'b)

を用意して、それぞれあらかじめ byte compile しておき、
Emacs 上にて初めて (require 'b) した後の (baz "A") の結果は

(baz "A")
=> ("A-foo" . "A-bar")

そして a.el を以下のように編集してa.el だけ再度byte-compile-file 
しておきます。

a.el:
(defsubst foo (s) (concat s "-FOO"))
(defmacro bar (s) `(concat ,s "-BAR"))
(provide 'a)

b.el , b.elc は 元のまま。
再度 Emacs をを立ち上げて (require 'b) して (baz "A") の結果は

(baz "A")
=> ("A-foo" . "A-bar")

ですね。

## 全て実際にやってみた結果です。

--- Regards,
 Shun-ichi Goto  <gotoh at example.com>
   R&D Group, TAIYO Corp., Tokyo, JAPAN




Mew-dist メーリングリストの案内