Iteration Using DOLIST

The control constructs provided by Common Lisp often allow shorter and more understandable code than use of PROG and GO, as illustrated by the following version of LENGTH:


(DEFUN LENGTH (L)

  (LET ((COUNT 0))

    (DOLIST (ITEM L) (INCF COUNT))

    COUNT ))

INCF is a macro that increments a value. (INCF COUNT) expands into
(SETQ COUNT (1+ COUNT)).

Contents    Page-10    Prev    Next    Page+10    Index