- 论坛徽章:
- 0
|
本帖最后由 xdshting 于 2010-07-23 10:05 编辑
这是cl-ftp里面的一段代码- (defmethod receive-response ((conn ftp-connection) &key (block nil))
- (with-ftp-connection-slots (conn)
- (when (and (not block) (not (data-ready-p conn)))
- (return-from receive-response nil))
- (loop :with initial-line = (read-line (socket-stream socket))
- :with ftp-code = (parse-integer initial-line :end 3)
- :for line = initial-line :then (read-line (socket-stream socket))
- :for line-code = ftp-code :then
- (when (> (length line) 3)
- (parse-integer line :end 3
- :junk-allowed t))
- :when (and code-cut-off-p (eql line-code ftp-code))
- :collect (subseq line 4) :into lines
- :else
- :collect line :into lines
- :end
- :until (and (eql line-code ftp-code)
- (char= (char line 3) #\Space))
- :finally (let ((data (clean-ftp-response lines)))
- (log-session conn data)
- (return (values (maybe-cut-off-code code-cut-off-p
- data
- ftp-code)
- ftp-code))))))
复制代码 有三个问题
1,这段代码里面的loop循环什么时候退出,我没有看到条件判断
2,在这里with,for前面都加了冒号,是什么原因
另外,我做了一个小测试
(loop :for cons on '(1 2 3 4 5 6) :do (format t "~a" (car cons)) :when (cdr cons) :do (format t ","))
在关键字for,do,when前面加了冒号,功能没有区别
这条语句中 在for,do,when前面都加了冒号,其功能与没有冒号一样,请问为什么?
3,在我的lisp里面,sbcl,clisp都试验过了,for x=1 then exp,这条语句不能执行,如下是在clisp中,在sbcl中提示then关键字无定义,不知道什么原因,
[2]> (loop for x from 1 to 5
for y=0 then z
sum 1 into z
finally (return (values y z)))
*** - LOOP: illegal syntax near THEN in
(LOOP FOR X FROM 1 TO 5 FOR Y=0 THEN Z SUM 1 INTO Z FINALLY
(RETURN (VALUES Y Z)))
The following restarts are available:
ABORT :R1 ABORT
Break 1 [3]>
这个例子是在ansi common lisp中超过来的 |
|