我在init.el中有一个方便的定义来做一些日志记录
(defvar log4me::loglevel 5
"Global loglevel.")
(defun log4me (level logmsg)
"Log message."
(interactive)
(when (>= level log4elisp::loglevel)
(message logmsg))))
它有点工作但不知何故我常常做
(log4me somelevel (format "mymessage with %d" 1))
所以我发现了emacs lisp& rest参数,我认为我可能会这样使用:
(defun log4me (level logmsg &rest formatparams)
"Log message."
(interactive)
(when (<= level log4elisp::loglevel)
(message (format logmsg formatparams))))
(log4me 3 "Hello %ust!" 1)
重新转换为&#34;格式说明符不匹配参数类型&#34;因为formatparams实际上是(1)而不是1。
是否有一种很好的方法可以将格式参数包含到log4elisp defun中,并使它们以格式函数调用的形式到达&#34; normal&#34;参数(不是单个列表)?
答案 0 :(得分:6)
您需要的是apply
:
(defun log4me (level logmsg &rest formatparams)
"Log message."
(interactive)
(when (<= level log4elisp::loglevel)
(apply #'message logmsg formatparams)))
答案 1 :(得分:0)
public IActionResult Filter(string bGroup, string gender)
{
List<EmployeeViewModel> empList = new List<EmployeeViewModel>();
return RedirectToAction("Index",empList);
}
对于函数来说是完美的,但对于诸如宏之类的函数对象无效。以下解决方案适用于函数和宏。
apply