Alright, thanks Gary and Marko, I really appreciate the advice! On Sunday, March 10, 2013 8:26:47 AM UTC-5, Marko Topolnik wrote: > > Several comments: > > 1. camelCase is not idiomatic for Clojure. Prefer lowercase-dashed-style. > > 2. use :keywords for map keys and, more generally, for any > enumeration-type values (coming from a closed set of options). If you want > JSON output, transform these into camelCased strings only at the "checkout > desk". >
Ugh, I *do* actually know better than that, thanks for pointing it out! > > 3. make-student-factory is what you'd call a *curried* function. You'd > have an easier time with it if you declared it as a regular two-argument > function and then used either clojure.core/partial or a literal > #(make-student > teacher-name %). That would allow you to use the function either directly > as a student factory, or as a factory of student factories. Note that > your approach to use a closure *is *idiomatic, I'm just advising a more > idiomatic way to get it. > > Ok, I *think* I understand what you're saying. I did try an anonymous function at one point, but gave it up, I don't know why I did because it ended up working pretty well after reading your advice. How's this then? (ns teachers.core (:require [clj-json.core :as json])) (defn- gen-items-json [students] (json/generate-string {:timestamp 5000 :items students :identifier "id" :label "id" :rc 200 :msg "Data retrieved successfully."})) (defn- make-student [teacher-name student-name age] {:id (str teacher-name "!" student-name) :TeacherName teacher-name :StudentName student-name :age age}) (defn- make-name [prefix n] (str prefix n)) (defn- make-teacher-name [n] (make-name "TEACHER" n)) (defn- make-student-name [n] (make-name "STUDENT" n)) (defn- make-students [teacher-name n] (map #(make-student teacher-name (make-student-name %) 0) (range n))) (defn- spit-json [teacher-name n] (println "Creating " n " students for teacher: " teacher-name) (spit (str teacher-name ".json") (gen-items-json (make-students teacher-name n)))) (defn gen [num-teachers num-students] (doseq [teacher-name (map make-teacher-name (range num-teachers))] (spit-json teacher-name num-students))) Thanks a ton for your time, this list is really a great place and I appreciate being able to come here with questions! Cheers, Craig -- -- 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/groups/opt_out.