(define impc:ti:register-new-generictype
(let ((cnt 0))
(lambda (name type)
(set! cnt 0)
(set! *impc:ti:generic-count* (+ *impc:ti:generic-count* 1))
;; (println 'add-gpolytype: name 'at: *impc:ti:generic-count*)
(if (symbol? type) (set! type (symbol->string type)))
(let* ((syms (cl:remove-duplicates (regex:match-all type "![a-zA-Z0-9_]*")))
(newsyms (map (lambda (s)
(if (regex:match? s "^!g")
(let ((r (regex:split s "_")))
(set! cnt (+ cnt 1))
(string-append (car r) "x" (number->string cnt) "_" (number->string *impc:ti:generic-count*)))
(let ((r (string-append "!g"
(substring s 1 (string-length s))
"_"
(number->string *impc:ti:generic-count*))))
r)))
syms))
(newtype (string->symbol (regex:replace-everything type syms newsyms)))
(v (assoc-strcmp name *impc:ti:generictype-cache*)))
;; (println 'gtype-name: name 'type: type 'newtype: newtype 'v: v)
(if v
(set-cdr! v newtype)
(set! *impc:ti:generictype-cache* (cons (cons name newtype) *impc:ti:generictype-cache*)))
#t))))