Contents    Page-10    Prev    Next    Page+10    Index   

Multi-Level Patterns


(redefpatterns 'loop
     ((average ?set)
       (make-loop ?set ?item (?total ?n)
        (progn (setq ?total 0)
               (setq ?n 0))
        (progn (incf ?total ?item)
               (incf ?n))
               (/ ?total ?n) )
        t ((?item (gentemp "ITEM"))
           (?total (gentemp "TOTAL"))
           (?n (gentemp "N"))) ) ) )

(redefpatterns 'list
  '( ((make-loop ?lst ?item ?vars ?init ?action ?result)
        (let (?ptr ?item . ?vars)
          ?init
          (setq ?ptr ?lst)
          (while ?ptr
            (setq ?item (first ?ptr))
            (setq ?ptr (rest ?ptr))
            ?action)
          ?result)
        t ((?ptr (gentemp "PTR"))) ) ) )