 (defn- fmt-ksh [m]
   (fmt-sh m #(str "\"$(echo $" % " | tr [:upper:] [:lower:])\"")))
 
-;;(defn- fmt-namelist [m]
-;; (let [f0 (fn [[dataref values]] (str "  " dataref "=" values "\n"))
-;;       f1 (fn [[name nvseq]] (str "&" name "\n" (strmap f0 (sort nvseq)) "/\n"))]
-;;   (strmap f1 (sort m))))
-
-(defn f0 [x]
-  (println (str "#PM# 1 " x))
-  (let [[dataref values] x]
-    (println (str "#PM# 2 " dataref))
-    (println (str "#PM# 3 " values))
-    (str "  " dataref "=" values "\n")))
-(defn f1 [[name nvseq]] (str "&" name "\n" (strmap f0 (sort nvseq)) "/\n"))
 (defn- fmt-namelist [m]
-  (println (str "#PM# 0 " m))
-  (strmap f1 (sort m)))
+  (let [f0 (fn [[dataref values]] (str "  " dataref "=" values "\n"))
+        f1 (fn [[name nv_sequence]] (str "&" name "\n" (strmap f0 (sort nv_sequence)) "/\n"))]
+    (strmap f1 (sort m))))
 
 ;; defs
 

        f0  (fn [[dataref values]]
              (let [v (eq values)]
                (str "'" dataref "') echo \"" v "\";;")))
        f1  (fn [[name nvseq]]
              (let [x (strmap f0 nvseq)]
                (str "'" name "') case " k " in " x "*) echo '';;esac;;" )))]
    (str "nmlquery(){ case " n " in " (strmap f1 ms) "*) echo '';;esac; }\n")))


  (get (get m (string/lower-case nml) {}) (string/lower-case key) ""))

(defn nml-map [s src]
  (let [tree (nml-parse s :s src)
        transformers
        {
         :c identity
         :dataref #(apply string/lower-case %)
         :name #(apply string/lower-case %)
         :nv_sequence (fn [& nv_subsequences] (into {} nv_subsequences))
         :nv_subsequence (fn [name values] {name values})
         :nv_subsequence_begin #(apply string/lower-case %)
         :partref #(apply string/lower-case %)
         :s (fn [& nv_sequences] (into {} nv_sequences))
         :stmt (fn [name nv_sequence _] (into {} {name nv_sequence}))
         :string (fn [& letters] (apply str letters))
         :value identity
         :values (fn [& values] (into [] values))
         }]
    (println (str "#PM# 0 " tree))
    (let [newtree (insta/transform transformers tree)]
      (println (str "#PM# 1 " newtree))
      newtree)))

(defn nml-set [m nml key val]
  (let [src (str "user-supplied value")
