ここでは、関数の動作がその変数の名前に依存することを示す短いelispコードを示します。これはバグですか?関数の動作は変数の名前に依存する必要がありますか?
関数は変数xを使用して宣言されています。その関数がx以外の名前の変数で呼び出されると、期待どおりに機能します。しかし、xという名前の変数で呼び出された場合、失敗します。
私のシステムは
g5.tokyo.stp.isas.jaxa.jpに2008-04-05のGNU Emacsの22.2.1(PowerPCの-リンゴdarwin8.11.0、カーボンバージョン1.6.0)であります
これをemacsバッファーに貼り付け、最後の括弧の後ろにカーソルを置き、\ Cx \ Ceを押して、2回目に呼び出されたときに関数make-zeroが正しく機能することを確認します。
(progn
(defun make-zero (x)
"Simple function to make a variable zero."
(set x 0))
(setq x 10)
(insert "\n Variable x is now equal to " (number-to-string x))
(setq y 20)
(insert "\n Variable y is now equal to " (number-to-string y))
(insert "\n\n Let us apply make-zero to y")
(make-zero 'y)
(insert "\n Variable y is now equal to " (number-to-string y))
(insert "\n\n Let us apply make-zero to x")
(make-zero 'x)
(insert "\n Variable x is now equal to " (number-to-string x))
(insert "\n\n Why make-zero had no effect on x? Is it because the name of the
variable in the definition of make-zero, namely 'x', is the same as the name of
the variable when make-zero was called? If you change the name of the variable
in the definition of make-zero from x to z, this strange behaviour will
disappear. This seems to be a bug in elisp."))
2番目の例ではcl.elは必要ありません。これがなければ、うまくいくはずです。 – Drew