             [luaclj.library :refer :all]
             [com.rpl.specter :refer [select 
                                      ALL
+                                     LAST
+                                     STAY
                                      select-first
                                      pred
+                                     if-path
+                                     cond-path
                                      subselect 
                                      transform 
                                      walker]]

        "return"
        [:explist [:exp [:prefixexp [:var [:Name "e"]]]]]]]
      "end"]]]]
(pprint (lua-parser (slurp "resources/test/function.lua")))
(pprint (lua-parser (slurp "resources/test/for.lua")))
(eval (insta/transform transform-map (lua-parser (slurp "resources/test/function.lua"))))
  (try (pprint (insta/transform transform-map (lua-parser (slurp "resources/test/function.lua"))))
       (catch Exception ex (clojure.stacktrace/print-stack-trace ex)))

                                    global-var-init-statements)) 
        let-statements (into init-statements let-statements)
        expr `(let-mutable ~let-statements ~return-value)]
    (println "post-process-blocks out:" let-statements)
    ;(println "chunk-fn3:" global-var-init-statements)
    expr
    ))

(comment

  (select
    [ALL
     (if-path (pred #(= (safe-some-> %1 first) 'clojure.core/fn))
             LAST
             STAY)]
              
    `((clojure.core/fn :a :b)
      (let-mutable [:a :b])))
  )
(defn chunk-fn [& args]
  (println "chunk-fn:" args)
  (let [r (transform [ALL 
                (if-path (pred #(= (safe-some-> %1 first) 'clojure.core/fn))
                         LAST
                         STAY) ]
               #(post-process-blocks %1)
               args)]
    (println "chunk-fn result:" r)
    (first (transform [ALL] #(apply list %1) r))))

(defn block-fn [& args]
  (println "block-fn args:" args)
