2015-02-28 16:43 GMT+01:00 Chris Freeman <cwfree...@gmail.com>: > You can pass your functions around directly; you don't need to wrap them > in #(). That will get rid of most of the rest of the duplication you've > got. >
That did not work in the beginning, but that probably had to do that I was first using a list instead of a vector. (I spend quite some time getting it to work. But I learned from it.) > Also, please consider doseq instead of dotimes. > > (doseq [[description function] search-fields] > (grid-bag-layout > search-panel > :fill GridBagConstraints/HORIZONTAL > :ipadx 8 ...)) > That does not work because I need the i. But with the comment from Marc I made the following. In a let I have (not in a def of-course): search-fields [ ["Search Quotes (Case Independent)" show-search-quotes] ["Search Quotes Not (Case Independent)" show-search-quotes-not] ["Search Quotes Word Bounderies" show-search-quotes-word-boundary] ["Search Quotes Begin (Case Independent)" show-search-quotes-begin] ["Search Quotes End (Case Independent)" show-search-quotes-end] ["Search Quotes Java Regular Expression" show-search-quotes-java-regex] ["Search Quotes Java Regular Expression Not" show-search-quotes-java-regex-not] [nil nil] ["Search Authors (Case Independent)" show-search-authors] ] The code (it is extended to have also an empty line): (doall (map-indexed (fn [i [description function]] (if (nil? description) (grid-bag-layout search-panel :fill GridBagConstraints/HORIZONTAL :ipadx 8 :ipady 4 :gridy i :gridx 0 ^JLabel (label " ")) (grid-bag-layout search-panel :fill GridBagConstraints/HORIZONTAL :ipadx 8 :ipady 4 :gridy i :gridx 0 ^JLabel (label description) :gridx 1 ^JTextField (text :columns 40 :listen [:action (fn [e] (let [ search-str (text e) ] (when (not (empty? search-str)) (function search-str)))) ])))) search-fields)) The only 'problem' is that there is a little duplication of code, but I can live with that I think. In the attachment is a screendump of the frame as it has become. You could extract the doseq into a var-args function, then call it with the > items like so: > > (def-grids > ["Search Quotes (Case Independent)" show-search-quotes] > ["Search Quotes Not (Case Independent)" > show-search-quotes-not] > ["Search Quotes Word Bounderies" > show-search-quotes-word-boundary] > ["Search Quotes Begin (Case Independent)" > show-search-quotes-begin] > ["Search Quotes End (Case Independent)" > show-search-quotes-end] > ["Search Quotes Java Regular Expression" > show-search-quotes-java-regex] > ["Search Quotes Java Regular Expression Not" > show-search-quotes-java-regex]) > I do not understand what you mean by this. > On Feb 28, 2015 4:50 AM, "Cecil Westerhof" <cldwester...@gmail.com> wrote: > >> I need some things that are almost the same. I solved that in this way: >> (def search-fields >> [ >> ["Search Quotes (Case Independent)" >> #(show-search-quotes %)] >> ["Search Quotes Not (Case Independent)" >> #(show-search-quotes-not %)] >> ["Search Quotes Word Bounderies" >> #(show-search-quotes-word-boundary %)] >> ["Search Quotes Begin (Case Independent)" >> #(show-search-quotes-begin %)] >> ["Search Quotes End (Case Independent)" >> #(show-search-quotes-end %)] >> ["Search Quotes Java Regular Expression" >> #(show-search-quotes-java-regex %)] >> ["Search Quotes Java Regular Expression Not" >> #(show-search-quotes-java-regex %)] >> ]) >> >> (dotimes >> [i (count search-fields)] >> (let [ >> description (nth (nth search-fields i) 0) >> function (nth (nth search-fields i) 1) >> ] >> (grid-bag-layout >> search-panel >> :fill GridBagConstraints/HORIZONTAL >> :ipadx 8 >> :ipady 4 >> :gridy i >> :gridx 0 ^JLabel (label description) >> :gridx 1 ^JTextField >> (text :columns 40 >> :listen >> [:action (fn [e] >> (let [ >> search-str (text e) >> ] >> (when (not (empty? search-str)) >> (function search-str)))) >> ])))) >> >> Is that the correct way, or can it be done better? >> > -- Cecil Westerhof -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.