On Aug 2, 2:12 am, Meikel Brandmeyer <m...@kotka.de> wrote: > > (defmacro with-chosen-file > "Opens a file chooser, binds the result the user chose to the given > variable name and executes the body. In front of the body there might > be two options given: > > :directory is the initial directory shown in the chooser > :label is the label shown on the Ok button of the dialog > > If no directory is given, the dialog will show the parent directory > of the last chosen file. If no label is given Choose will be used. > If given, directory must be specified first." > [file & body] > (let [directory (when (= (first body) :directory) > (second body)) > body (if directory > (nnext body) > body) > label (if (= (first body) :label) > (second body) > "Choose") > body (if (= (first body) :label) > (nnext body) > body)] > (if directory > `(with-chosen-file* (fn [~file] ~...@body) ~directory ~label) > `(with-chosen-file* (fn [~file] ~...@body) ~label)))) > > Any thoughts? I'm not totally happy with the current form, so > discussion appreciated.
Why not just use a map for the options? I think it's easier to understand and process within the macro. (defmacro with-chosen-file "docstring" {:arglists '([name option-map? & body])} [file & [opts & body :as all]] (let [have-opts (instance? clojure.lang.IPersistentMap opts) opts (merge {:label "Chooser" } (if have-opts opts {})) body (if have-opts body all) directory (opts :directory)] (if directory `(with-chosen-file* (fn [~file] ~...@body) ~directory ~(:label opts)) `(with-chosen-file* (fn [~file] ~...@body) ~(:label opts))))) then call as (with-chosen-file foo {:directory "somedir"} (dostuff foo)) The option map could even be passed to the driver function as is, eliminating the need for overloads. also, file-chooser-last-directory could be made local to the function by doing the 'defn inside a (let [last-dir (atom ...)] ...) -- Jarkko --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---