Specialization by Transformation

A generic operation can be specialized for a particular abstract data structure. Example: sum of a set.


(redefpatterns 'loop
  '( ((sum ?set)
      (make-loop ?set ?item (?total)
         (setq ?total 0)
         (incf ?total ?item) ?total)
      t
      ((?item (gentemp "ITEM"))
       (?total (gentemp "TOTAL"))) ) ) )

(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"))) ) ) )

Contents    Page-10    Prev    Next    Page+10    Index