どのような種類の引数も受け入れることができる関数を記述し、引数の名前と値を出力できるようにしました。この関数は期待どおりに機能します。しかし、私は関数呼び出しがこのような値の引用符を渡す必要が好きではない(my-message 'emacs-version 'emacs-copyright)
。 (my-message emacs-version emacs-copyright)
に簡略化したいと思います。したがって、マクロを使用して関数を書き換えます。メッセージが2回印刷されました
(defmacro my-message (&rest args)
(if args
(progn
(message "This is the start of debug message.\n")
(dolist (arg args)
(cond
((stringp arg)
(message arg))
((numberp arg)
(message (number-to-string arg)))
((boundp arg)
(pp arg)
(message "")
(pp (symbol-value arg)))
((not (boundp arg))
(pp arg)
(message "Undefined")))
(message "\n"))
(message "This is the end of debug message."))
(message "This is a debug message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")))
ただし、一部のメッセージは2回印刷されます。
(my-message emacs-version emacs-copyright 12345 "HelloWorld" foobar)
This is the start of debug message.
emacs-version
"24.5.1"
[2 times]
emacs-copyright
"Copyright (C) 2015 Free Software Foundation, Inc."
[2 times]
12345
[2 times]
HelloWorld
[2 times]
foobar
Undefined
[2 times]
This is the end of debug message.
何が問題ですか?
これがなぜ[2倍]が作られたのかの本当の理由です。 – tom