   (if msg (println (apply str msg)))
   (System/exit 1))
 
-(defn nmlget [tree nml key]
-  (let [stmt     (last (filter #(= (nmlname %) nml) (rest tree)))
-        nvsubseq (last (filter #(= (nmlname %) key) (rest (last stmt))))
+(defn nml-get [tree nml key]
+  (let [stmt     (last (filter #(= (nml-name %) nml) (rest tree)))
+        nvsubseq (last (filter #(= (nml-name %) key) (rest (last stmt))))
         values   (last nvsubseq)
-        value    (if (nil? values) "" (nmlstr values))]
+        value    (if (nil? values) "" (nml-str values))]
     (println (str nml ":" key "=" value))
     tree))
 
-(defn nmlname [x]
-  (nmlstr (second x)))
+(defn nml-name [x]
+  (nml-str (second x)))
 
-(defn nmlset [tree nml key val & sub]
+(defn nml-set [tree nml key val & sub]
   (let [child (if sub :nvsubseq :stmt)
         match (if sub key nml)
-        vnew  (if sub (fn [tree] (parse val :start :values)) #(nmlset % nml key val true))
-        f     (fn [k v] [child k (if (= (nmlstr k) match) (vnew v) v)])]
+        vnew  (if sub (fn [tree] (parse val :start :values)) #(nml-set % nml key val true))
+        f     (fn [k v] [child k (if (= (nml-str k) match) (vnew v) v)])]
     (insta/transform {child f} tree)))
 
-(defn nmlstr [x]
+(defn nml-str [x]
   (let [k (first x)
         v (rest  x)
         cjoin    #(string/join "," %)
-        delegate #(map nmlstr %)
-        ds       (fn [v] (delegate (sort-by #(nmlname %) v)))
-        list2str #(apply str (map nmlstr %))
-        sf       #(nmlstr (first %))
-        sl       #(nmlstr (last %))]
+        delegate #(map nml-str %)
+        ds       (fn [v] (delegate (sort-by #(nml-name %) v)))
+        list2str #(apply str (map nml-str %))
+        sf       #(nml-str (first %))
+        sl       #(nml-str (last %))]
     (if debug (println (str "k=" k " v=" v)))
     (apply str (case k
                  :s        (ds v)

  (let [{:keys [options arguments summary]} (cli/parse-opts args cliopts)
        gets (:get options)
        sets (:set options)
        tree (nmltree (first arguments))]
    (if (and gets sets) (fail "Do not mix get and set operations."))
    (cond gets (doseq [[nml key] gets] (nmlget tree nml key))
          sets (println (nmlstr (nmlxform tree sets)))
          :else (println (nmlstr tree)))))

                 :ws       ""
                 :wsopt    ""))))

(defn nml-tree [fname]
  (try (parse (slurp fname))
       (catch Exception e (fail "Could not open namelist file '" fname "'."))))

(defn nml-xform [tree sets]
  (loop [t tree s sets]
    (if (empty? s)
      t
      (let [[nml key val] (first s)]
        (recur (nml-set t nml key val) (rest s))))))

;; cli

