Contents    Page-10    Prev    Next    Page+10    Index   

Iterative List Design Pattern


public int fn (Cons lst) {
  initialize answer;
  for (Cons ptr = lst;
            ptr != null;
            ptr = rest(ptr) ) {
    answer = someCombinationOf(
               answer,
               somethingAbout( first(ptr) )); }
  return answer; }


(defun fn (lst)
  (let (answer)
    initialize answer
    (while (not (null lst))
      (setq answer
            (some-combination-of
              answer
              (something-about (first lst)) ) )
      (setq lst (rest lst)) )
    answer ))