For Loop

The Glisp compiler can compile loops over sets of data, including lists, trees, and any type for which iterator macros are defined.

A for loop can include when predicate and verbs do, collect, sum, average, stats.


(gldefun t11 ((grades (listof integer)))
  (for x in grades average x))

> (glcp 't11)

result type: INTEGER
(LAMBDA (GRADES)
  (LET (SUM VAL (N 0))
    (DOLIST (X GRADES)
      (SETQ VAL X)
      (IF (ZEROP N) (SETQ SUM VAL) (INCF SUM VAL))
      (INCF N))
    (IF (PLUSP N) (/ SUM N) 0)))

> (t11 '(90 95 87 100))

93

Contents    Page-10    Prev    Next    Page+10    Index