17.05.2015 Views

zl:1 - FTP

zl:1 - FTP

zl:1 - FTP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

183 do<br />

Zetalisp note: Zetalisp supports another, "old-style" version of do. This<br />

form is incompatible with the language specification presented in Guy<br />

Steele's Common Lisp: the Language.<br />

The older do looks like this:<br />

(do var init repeat end-test body . .. )<br />

The first time through the loop var gets the value of the init form; the<br />

remaining times through the loop it gets the value of the repeat form,<br />

which is reevaluated each time. Note that the init form is evaluated before<br />

var is bound, that is, lexically outside of the do. Each time around the<br />

loop, after var is set, end-test is evaluated. If it is non-nil, the do finishes<br />

and returns nil. If the end-test evaluated to nil, the body of the loop is executed.<br />

If the second element of the form is nil, there is no end-test nor exit-forms,<br />

and the body of the do is executed only once. In this type of do it is an<br />

error to have repeats. This type of do is no more powerful than let; it is<br />

obsolete and provided only for Maclisp compatibility.<br />

return and go can be used in the body. It is possible for body to contain<br />

no forms at all.<br />

Examples:<br />

(do (i B (+ 1 i)) ; searches list for Dan.<br />

(names '(Adam Brain Carla Dan Eric Fred) (cdr names)))<br />

I<br />

((null names))<br />

(if (equal 'Dan (car names))<br />

(princ "Hey Danny Boooooy U))) => Hey Danny Boooooy NIL<br />

(do ((22 x (cdr 22)))<br />

((or (null 22)<br />

(2erop (f (car 22))))))<br />

;this applies f to each element of x<br />

;continuously until f returns 2ero.<br />

;Note that the do has no body.<br />

(defun list-splice (a b)<br />

(do ((x a (cdr x))<br />

(y b (cdr y))<br />

(xy 'C) (append xy (list (car x) (car y)))) )<br />

((endp x) (endp y) (append xy x y) ))) => LIST-SPLICE<br />

(list-splice '(1 2 3) '(a b c)) => (1 A 2 B 3 C)<br />

(list-splice '(1 2 3) '(a b c de)) => (1 A 2 B 3 C 0 E)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!