;;;; Copyright 2002, Jonathan Bachrach.  See file TERMS.

(use goo/boot)
(use goo/fun)
(use goo/class)
(use goo/macros)
(use goo/types)
(use goo/math)
(use goo/cols/col)

(pub dg elt-setter (v|<any> x|<col!> (k <any>)))
(pub dg into (x|<col!> y|<col> => <col>)) 
(pub dg add! (c|<col!> x => <col!>))
(pub dg elt! (c|<col!> k f|<fun>))
(pub dg del! (c|<col!> x => <col!>))
(pub dg zap! (c|<col!> => <col!>))
(pub dg len-setter (new-len|<int> c|<col!>))
(pub dg len/fill-setter (new-len|<int> c|<col!> default))
(pub dg fill! (c|<col!> x => <col!>))
(pub dg low-elt-setter (v|<any> x|<col> k|<any>))

;; NEEDED FOR FAB-INTO
(dm (fab-elt-setter inline) (value c|<col!> key => <any>)
  (set (elt c key) value))

(dm (low-elt-setter inline) (value c|<col!> key => <any>)
  (set (elt c key) value))

;; TODO: REMOVE PERHAPS?
(dm add! (c|<col!> x => <col!>) (add c x))

(dv $not-found '("not found"))

(dm elt! (c|<col!> k f|<fun>) 
  (def x (elt-or c k $not-found)) 
  (if (== x $not-found) (set (elt c k) (f)) x))

(dm del! (c|<col!> x => <col!>) (del c x))

(dm zap! (c|<col!> => <col!>) (zap c))

(dm fill! (dst|<col!> val => <col!>)
  (rep in ((ds (enum dst)))
    (if (fin? ds)
        dst
        (seq (set (now ds) val)
             (in (nxt ds))))))

(dm into (dst|<col!> src|<col> => <col!>)
  (rep in ((ss (enum src)))
    (if (fin? ss)
        dst
        (seq (set (elt dst (now-key ss)) (now ss))
             (in (nxt ss))))))
