17.05.2015 Views

zl:1 - FTP

zl:1 - FTP

zl:1 - FTP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

121 count-if<br />

(count 'a '(a a b b a a) :start 1 :end 6) => 3<br />

(count 'a #(a b b b a) ) => 2<br />

For a table of related items: See the section "Searching for Sequence<br />

I terns" in Symbolics Common Lisp: Language Concepts.<br />

count Keyword For loop<br />

count expr {into uar} {data-type}<br />

If expr evaluates non-nil, a counter is incremented. The data-type defaults to<br />

fixnum. When the epilogue of the loop is reached, uar has been set to the<br />

accumulated result and can be used by the epilogue code.<br />

I t is safe to reference the values in uar during the loop, but they should not be<br />

modified until the epilogue code for the loop is reached.<br />

The forms count and counting are synonymous.<br />

Examples:<br />

(defun num-entry (small-list)<br />

(loop for x in small-list<br />

count t into num<br />

finally (return num») => NUN-ENTRY<br />

(num-entry '(a b cd» => 4<br />

I<br />

Is equivalent to<br />

(de fun num-entry (small-list)<br />

(loop for x in small-list<br />

counting t into num<br />

finally (return num») => NUN-ENTRY<br />

(num-entry '(a b cd» => 4<br />

Not only can there be multiple accumulations in a loop, but a single accumulation<br />

can come from multiple places within the same loop form, if the types of the<br />

collections are compatible. count and sum are compatible.<br />

See the section "loop Clauses", page 310.<br />

count-if predicate sequence &key key from-end (start 0) end<br />

Function<br />

count-if returns a non-negative integer, which represents the number of<br />

elements in the specified subsequence of sequence satisfying the predicate.<br />

predicate is the test to be performed on each element.

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

Saved successfully!

Ooh no, something went wrong!