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

(use goo/boot)
(use goo/fun)
(use goo/class)
(use goo/macros)
(use goo/types)
(use goo/any)
(use goo/log)
(use goo/chr)
(use goo/mag)
(use goo/math)
(use goo/cols/col)
(use goo/cols/seq)
(use goo/cols/flat)

;; 3.7.6.1 REPEATED'S

;;;;!! Interface
(exported
 ;; Defined in boot
 <rep>
 rep-len
 rep-fab
 rep-fill!
 (dg rep-into! (d|<rep> s => <rep>))
 rep-nul
 rep-elt
 rep-elt-setter
)

(df (rep-nul inline) () %rnul)

(df (rep-len inline) (x|<rep> => <int>)
  (%ib (%rlen x)))

(df rep-fill! (x|<rep> val => <rep>)
  (def s (rep-len x))
  (rep fill ((i 0))
    (when (< i s)
      (set (rep-elt x i) val)
      (fill (+ i 1))))
  x)

(dm rep-into! (d|<rep> s|<rep> => <rep>)
  (def l (min (rep-len d) (rep-len s)))
  (rep into ((i 0))
    (when (< i l)
      (set (rep-elt d i) (rep-elt s i))
      (into (+ i 1))))
  d)

(dm rep-into! (d|<rep> s|<col> => <rep>)
  (def l (min (rep-len d) (len s)))
  (rep into ((i 0) (e (enum s)))
    (when (< i l)
      (set (rep-elt d i) (now e))
      (into (+ i 1) (nxt e))))
  d)

(df (rep-fab inline) (s|<int> fill => <rep>)
  (%rep (%iu s) fill))

(df (rep-elt inline) (x|<rep> i|<int> => <any>)
  (%relt x (%iu i)))
  
(df (rep-elt-setter inline) (z x|<rep> i|<int>)
  (set (%relt x (%iu i)) z))
  


