原帖由 xdshting 于 2009-3-9 00:50 发表
谢谢,现在明白一些了
看到您用
(funcall '+ 3 4)
我用
(funcall #'+ 3 4)
可以得到相同的结果,我觉得你用的形式不对阿,为什么能执行?
Syntax:
funcall function &rest args => result*
......
funcall applies function to args. If function is a symbol, it is coerced to a function as if by finding its functional value in the global environment.
1+ is a built-in function in `C source code'.
(1+ NUMBER)
Return NUMBER plus one. NUMBER may be a number or a marker.
Markers are converted to integers.
原帖由 xdshting 于 2009-3-9 09:22 发表
谢谢了
再看ansi common lisp关于closure的介绍,又有一点不明白的地方
书上的例子
( let ((counter 0))
(defun reset ()
(setf counter 0))
(defun stamp ()
(setf counter (+ c ...
In Common Lisp, the defun construct always creates a top-level definition, e.g.
原帖由 xdshting 于 2009-3-9 11:05 发表
>>1,看了一些对closure的介绍
有一个感觉,有点像java里的封装吗,把free variable看作私有变量,只有通过对外接口去访问他
这样理解对不对?
2,另外,还是有点不明白,什么时候变量可以递增,什么时候 ...
(defparameter *fn* (let ((count 0)) #'(lambda () (setf count (1+ count)))))
原帖由 win_hate 于 2009-3-9 11:12 发表
我查了一个:
http://community.schemewiki.org/?scheme-faq-language
scheme 的 faq,在里面的 Is there a way to define top-level closures? 一节说到:
所以你能在 let 外访问 let 中定义的函 ...
原帖由 xdshting 于 2009-3-8 23:39 发表
书上的例子是
(let ((count 0)) #'(lambda () (setf count (1+ count))))
the reference to count inside the LAMBDA form should be legal according to the rules of lexical scoping. Yet the anonymou ...
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |