 
 (defn j [v] (string/join " " (flatten v)))
 
-(defn c2g-sym [sym]
+(defn cvt-sym [sym]
   (-> (str sym)
       (string/replace "." "_")
       (string/replace "-" "_")
       (string/replace "?" "p")))
 
-(defn c2g-type [sym]
+(defn cvt-type [sym]
   (let [parts (string/split (str sym) #"-")
         plast (last parts)
         [p0 & prest] parts]


(defn -main []
  (let [smodel (read-model-file "src/cbfg/fence.cljs")
        pmodel (process-top-level-forms smodel)]
    (emit (:lines smodel) pmodel)))


     (re-find #"\?$" plast) "bool" ; When ends with '?'.
     :default (string/capitalize plast))))

(defn cvt-fn-params [params]
  ["(" (interpose "," (map (fn [sym] [(cvt-sym sym) (cvt-type sym)])
                           params))
   ")"])

(defn cvt-fn-body [params forms]
  (map-indexed (fn [idx form]
                 [(when (= idx (dec (count forms))) "return")
                  form ";"])
               forms))

(defn cvt-fn [params body]
  ["func" (cvt-fn-params params) "{" (cvt-fn-body params body) "}"])

(defn cvt-defn [name params body]
  ["func" (cvt-sym name) (rest (cvt-fn params body))])

(defn cvt-top-level-form [smodel form]
  (let [[op name & more] form]
    [(case (str op)
      "ns" (j ["package" (cvt-sym name)])
      "defn" (j (cvt-defn name (first more) (rest more)))
      "UNKNOWN-TOP-LEVEL-FORM")
     (line-range form)]))

(defn cvt-top-level-forms [smodel]
  (map #(cvt-top-level-form smodel %)
       (:forms smodel)))

(defn numbered-lines [lines beg end] ; beg and end are 1-based.
