首页 > 其他 > 详细

defadvice中的?argv是什么

时间:2016-07-10 18:21:16      阅读:190      评论:0      收藏:0      [点我收藏+]

      《Jess In Action》58页,这样说?argv:In the body of a defadvice call, the variable ?argv is special: It points to the actual function call being executed。

并给出例子如下:

 1 Jess> (bind ?grocery-list (create$ peas beans butter milk))
 2 (peas beans butter milk)
 3 Jess> (nth$ 1 ?grocery-list)
 4 peas
 5 Jess> (defadvice before nth$
 6 ;; Strip off the function name
 7 (bind ?tail (rest$ ?argv))
 8 ;; Convert zero-based to one-based index
 9 (bind ?index (+ 1 (nth$ 1 ?tail)))
10 ;; Put the argument list back together.
11 (bind ?argv (create$ nth$ ?index (rest$ ?tail))))
12 TRUE
13 Jess> (nth$ 1 ?grocery-list)
14 beans

 

      从11和13行可以看出,(rest$ ?tail)对应?grocery-list,故?tail对应(1 ?grocery-list),所以9行的(nth$ 1 ?tail)就是1,加1以后变成了2。从7行得知,?tail(rest$ ?argv)得来的,那么?argv就应该是(nth$ 1 grocery-list),这个是调用函数本身。

   所以得出结论,文首的话翻译后是:所谓的?argv,是指向实际正执行的函数本身,这个本身是指其表述本身,既不是其执行的结果,也不是其执行的参数,而是组成它的字符串。嗯,应该有个更好的表述,回头想起来了再来修改。

defadvice中的?argv是什么

原文:http://www.cnblogs.com/solarup/p/5658131.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!