Re: Sorting a collection on multiple fields
The thing is that I need to provide some kind of sorting specification in my Pedestal app, and I thought the MongoDB way of using an object with { field: 1/-1 } was a nice spec. That's why I went all the way up to a function that takes such a spec. Obviously, I can't use the (. f (compare x y)) trick in ClojureScript, so I went with the regular compare there. On Thursday, 12 September 2013 02:33:19 UTC+2, Jay Fields wrote: No - I honestly missed that version of yours the first time. I like that solution, and prefer it to the sort-by-map final solution. Probably just a style pref though. On Wed, Sep 11, 2013 at 6:07 PM, ulsa ulrik.s...@gmail.com javascript: wrote: Interesting. You used recursion, where I tried to see it as a sequence. Any other differences? My solution was: (defn compare-many [comps] (fn [xs ys] (if-let [result (first (drop-while zero? (map (fn [f x y] (. f (compare x y))) comps xs ys)))] result 0))) (- [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}] (sort-by (juxt :name :age) (compare-many [compare ]))) On Saturday, 31 August 2013 17:28:45 UTC+2, Jay Fields wrote: I would solve it like this- (defn multi-compare [[c cs] [x xs] [y ys]] (if (= x y) (multi-compare cs xs ys) (c x y))) (defn multi-comparator [comparators] (fn [xs ys] (if (= (count xs) (count ys) (count comparators)) (multi-compare comparators xs ys) (throw (RuntimeException. count not equal) (- [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}] (sort-by (juxt :name :age) (multi-comparator [compare ])) ) On Sat, Aug 31, 2013 at 9:04 AM, Leonardo Borges leonardo...@gmail.com wrote: Would this help? (sort-by (juxt :key1 :key2) your-list-of-maps) On 31/08/2013 7:57 PM, ulsa ulrik.s...@gmail.com wrote: I wanted to sort a sequence of maps using a spec consisting of an ordered map of key and order, like this: (array-map :name 1 :age -1) I couldn't find a ready-made solution, so I rolled my own. I ended up with three functions with a total of 10 lines of code. Two of them are generic, and one is specific to my problem. First a comparator-generator, that is fed a collection of comparators: (defn compare-many [comps] (fn [xs ys] (if-let [result (first (drop-while zero? (map (fn [f x y] (. f (compare x y))) comps xs ys)))] result 0))) It uses the same trick as sort-by does, namely the fact that all functions implement Comparator. This means that I can pass in a predicate instead of a comparator, if it makes sense: user= ((compare-many [ compare]) [4 beta] [4 alpha]) 1 user= ((compare-many [ compare]) [4 beta] [3 gamma]) -1 Next, a convenience function that takes a collection of keyfns, a collection of comparators (or predicates), and a collection to sort, passing it to sort-by: (defn sort-by-many [keyfns comps coll] (sort-by (apply juxt keyfns) (compare-many comps) coll)) It's called like this: user= (sort-by-many [:a :b] [ compare] [{:a 4 :b beta} {:a 4 :b alpha} {:a 3 :b gamma} {:a 5 :b delta}]) ({:a 5, :b delta} {:a 4, :b alpha} {:a 4, :b beta} {:a 3, :b gamma}) And finally a function specific to my problem domain. It takes a sort order map and the collection to sort (note that I use (comp - compare) to get the inverse sort order): (defn sort-by-map [m coll] (sort-by-many (keys m) (map #(case % 1 compare -1 (comp - compare) (throw (Exception. 1 or -1))) (vals m)) coll)) It's called like this: user= (sort-by-map (array-map :name 1 :age -1) [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}]) ({:age 19, :name amanda} {:age 25, :name zack} {:age 21, :name zack} {:age 20, :name zack}) The collection doesn't have to contain maps: user= (sort-by-map (array-map first 1 second -1) [[zack 25] [amanda 19] [zack 20] [zack 21]]) ([amanda 19] [zack 25] [zack 21] [zack 20]) Is there anything that I've missed? Improvements? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Sorting a collection on multiple fields
No. I think you missed the part that I want to be able to sort either ascending or descending on each key: (array-map :name 1 :age -1) On Saturday, 31 August 2013 15:04:44 UTC+2, Leonardo Borges wrote: Would this help? (sort-by (juxt :key1 :key2) your-list-of-maps) On 31/08/2013 7:57 PM, ulsa ulrik.s...@gmail.com javascript: wrote: I wanted to sort a sequence of maps using a spec consisting of an ordered map of key and order, like this: (array-map :name 1 :age -1) I couldn't find a ready-made solution, so I rolled my own. I ended up with three functions with a total of 10 lines of code. Two of them are generic, and one is specific to my problem. First a comparator-generator, that is fed a collection of comparators: (defn compare-many [comps] (fn [xs ys] (if-let [result (first (drop-while zero? (map (fn [f x y] (. f (compare x y))) comps xs ys)))] result 0))) It uses the same trick as sort-by does, namely the fact that all functions implement Comparator. This means that I can pass in a predicate instead of a comparator, if it makes sense: user= ((compare-many [ compare]) [4 beta] [4 alpha]) 1 user= ((compare-many [ compare]) [4 beta] [3 gamma]) -1 Next, a convenience function that takes a collection of keyfns, a collection of comparators (or predicates), and a collection to sort, passing it to sort-by: (defn sort-by-many [keyfns comps coll] (sort-by (apply juxt keyfns) (compare-many comps) coll)) It's called like this: user= (sort-by-many [:a :b] [ compare] [{:a 4 :b beta} {:a 4 :b alpha} {:a 3 :b gamma} {:a 5 :b delta}]) ({:a 5, :b delta} {:a 4, :b alpha} {:a 4, :b beta} {:a 3, :b gamma}) And finally a function specific to my problem domain. It takes a sort order map and the collection to sort (note that I use (comp - compare) to get the inverse sort order): (defn sort-by-map [m coll] (sort-by-many (keys m) (map #(case % 1 compare -1 (comp - compare) (throw (Exception. 1 or -1))) (vals m)) coll)) It's called like this: user= (sort-by-map (array-map :name 1 :age -1) [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}]) ({:age 19, :name amanda} {:age 25, :name zack} {:age 21, :name zack} {:age 20, :name zack}) The collection doesn't have to contain maps: user= (sort-by-map (array-map first 1 second -1) [[zack 25] [amanda 19] [zack 20] [zack 21]]) ([amanda 19] [zack 25] [zack 21] [zack 20]) Is there anything that I've missed? Improvements? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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.
Re: Sorting a collection on multiple fields
Interesting. You used recursion, where I tried to see it as a sequence. Any other differences? My solution was: (defn compare-many [comps] (fn [xs ys] (if-let [result (first (drop-while zero? (map (fn [f x y] (. f (compare x y))) comps xs ys)))] result 0))) (- [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}] (sort-by (juxt :name :age) (compare-many [compare ]))) On Saturday, 31 August 2013 17:28:45 UTC+2, Jay Fields wrote: I would solve it like this- (defn multi-compare [[c cs] [x xs] [y ys]] (if (= x y) (multi-compare cs xs ys) (c x y))) (defn multi-comparator [comparators] (fn [xs ys] (if (= (count xs) (count ys) (count comparators)) (multi-compare comparators xs ys) (throw (RuntimeException. count not equal) (- [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}] (sort-by (juxt :name :age) (multi-comparator [compare ])) ) On Sat, Aug 31, 2013 at 9:04 AM, Leonardo Borges leonardo...@gmail.com javascript: wrote: Would this help? (sort-by (juxt :key1 :key2) your-list-of-maps) On 31/08/2013 7:57 PM, ulsa ulrik.s...@gmail.com javascript: wrote: I wanted to sort a sequence of maps using a spec consisting of an ordered map of key and order, like this: (array-map :name 1 :age -1) I couldn't find a ready-made solution, so I rolled my own. I ended up with three functions with a total of 10 lines of code. Two of them are generic, and one is specific to my problem. First a comparator-generator, that is fed a collection of comparators: (defn compare-many [comps] (fn [xs ys] (if-let [result (first (drop-while zero? (map (fn [f x y] (. f (compare x y))) comps xs ys)))] result 0))) It uses the same trick as sort-by does, namely the fact that all functions implement Comparator. This means that I can pass in a predicate instead of a comparator, if it makes sense: user= ((compare-many [ compare]) [4 beta] [4 alpha]) 1 user= ((compare-many [ compare]) [4 beta] [3 gamma]) -1 Next, a convenience function that takes a collection of keyfns, a collection of comparators (or predicates), and a collection to sort, passing it to sort-by: (defn sort-by-many [keyfns comps coll] (sort-by (apply juxt keyfns) (compare-many comps) coll)) It's called like this: user= (sort-by-many [:a :b] [ compare] [{:a 4 :b beta} {:a 4 :b alpha} {:a 3 :b gamma} {:a 5 :b delta}]) ({:a 5, :b delta} {:a 4, :b alpha} {:a 4, :b beta} {:a 3, :b gamma}) And finally a function specific to my problem domain. It takes a sort order map and the collection to sort (note that I use (comp - compare) to get the inverse sort order): (defn sort-by-map [m coll] (sort-by-many (keys m) (map #(case % 1 compare -1 (comp - compare) (throw (Exception. 1 or -1))) (vals m)) coll)) It's called like this: user= (sort-by-map (array-map :name 1 :age -1) [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}]) ({:age 19, :name amanda} {:age 25, :name zack} {:age 21, :name zack} {:age 20, :name zack}) The collection doesn't have to contain maps: user= (sort-by-map (array-map first 1 second -1) [[zack 25] [amanda 19] [zack 20] [zack 21]]) ([amanda 19] [zack 25] [zack 21] [zack 20]) Is there anything that I've missed? Improvements? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed
Sorting a collection on multiple fields
I wanted to sort a sequence of maps using a spec consisting of an ordered map of key and order, like this: (array-map :name 1 :age -1) I couldn't find a ready-made solution, so I rolled my own. I ended up with three functions with a total of 10 lines of code. Two of them are generic, and one is specific to my problem. First a comparator-generator, that is fed a collection of comparators: (defn compare-many [comps] (fn [xs ys] (if-let [result (first (drop-while zero? (map (fn [f x y] (. f (compare x y))) comps xs ys)))] result 0))) It uses the same trick as sort-by does, namely the fact that all functions implement Comparator. This means that I can pass in a predicate instead of a comparator, if it makes sense: user= ((compare-many [ compare]) [4 beta] [4 alpha]) 1 user= ((compare-many [ compare]) [4 beta] [3 gamma]) -1 Next, a convenience function that takes a collection of keyfns, a collection of comparators (or predicates), and a collection to sort, passing it to sort-by: (defn sort-by-many [keyfns comps coll] (sort-by (apply juxt keyfns) (compare-many comps) coll)) It's called like this: user= (sort-by-many [:a :b] [ compare] [{:a 4 :b beta} {:a 4 :b alpha} {:a 3 :b gamma} {:a 5 :b delta}]) ({:a 5, :b delta} {:a 4, :b alpha} {:a 4, :b beta} {:a 3, :b gamma}) And finally a function specific to my problem domain. It takes a sort order map and the collection to sort (note that I use (comp - compare) to get the inverse sort order): (defn sort-by-map [m coll] (sort-by-many (keys m) (map #(case % 1 compare -1 (comp - compare) (throw (Exception. 1 or -1))) (vals m)) coll)) It's called like this: user= (sort-by-map (array-map :name 1 :age -1) [{:name zack :age 25} {:name amanda :age 19} {:name zack :age 20} {:name zack :age 21}]) ({:age 19, :name amanda} {:age 25, :name zack} {:age 21, :name zack} {:age 20, :name zack}) The collection doesn't have to contain maps: user= (sort-by-map (array-map first 1 second -1) [[zack 25] [amanda 19] [zack 20] [zack 21]]) ([amanda 19] [zack 25] [zack 21] [zack 20]) Is there anything that I've missed? Improvements? -- -- 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.
Re: How to structure a Clojure day for noobs?
I used an early version of Clooj in a workshop some time ago, but got burned by some bug that rendered the REPL crazy and shredding people's code. That scared me away. Probably much better now, though. On Wednesday, 19 December 2012 20:38:05 UTC+1, Nando Breiter wrote: What about Clooj? http://dev.clojure.org/display/doc/getting+started+with+Clooj Is it too buggy, or lacking in features, to start out with? On Tue, Dec 18, 2012 at 11:27 AM, ulsa ulrik.s...@gmail.com javascript: wrote: Good point. I really would like themselves to be able to set up their own environment. I think it gives them a sense of control. However, as a fallback, it would be great with a virtual machine with everything working. I'll consider that. I believe you can get a similar level of interactivity in both IntelliJ and Eclipse, but I agree that Emacs is still the master. On Tuesday, 18 December 2012 04:31:32 UTC+1, Peter wrote: 1. install Leiningen and learn the basics 2. get everyone an editing environment, with the option of using either Emacs, IntelliJ, or Eclipse I would have people do this in advance, or provide a canned environment that has a better chance of just working. There's decent odds that these two steps will eat up a bunch of your time and leave people feeling left out when their install/editor/integration is not quite right. Personally I found the C-x-e of evaluating an s-exp in emacs to be the magic that makes clojure a bajillionty times better than any other programming language, so I'm partial to something like the emacs starter kit. But something like labrepl or eclipse+counterclockwise might be easier for people to start with. On Mon, Dec 17, 2012 at 3:26 AM, Marko Topolnik marko.t...@gmail.comwrote: I think, however, that there is a risk of a disconnect, where newcomers don't really grasp that there is a JVM running and that code is actually compiled and injected into it, and that it's for real. They are used to mickey mouse interactive tools that don't provide the real thing, and struggle to bridge the apparent gap between running code in the REPL and properly compiling and running files. There is no gap, but one needs to explain that, I think. I think this is a pivot point for everything in Clojure. The harder the mental switch, the more important to make it right away. Without understanding that, it will be very hard to maintain a clear picture of how everything fits together, especially when you start changing functions and reloading them. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@**googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://groups.google.com/group/clojure?hl=en -- The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Nando Breiter *Aria Media via Rompada 40 6987 Caslano Switzerland * -- 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
Re: How to structure a Clojure day for noobs?
I have used the isBlank example in presentations. It's not a bad starting point. Might look at how it could be used in a workshop. Thanks. On Thursday, 20 December 2012 17:16:19 UTC+1, Thomas wrote: If you need to touch on the why of Clojure I found the example in the beginning Stuart Halloways book quite a good one. the isBlank in Java and the one line blank? equivalent in Clojure. Show them the Java, talk it through with them and then highlight some of its downsides (multiple if statements, the loop, local variables, the fact that the two statements in the first if with can only be ordered in that way etc). and then show them the clojure code, talk them through that and show them what it better (even if functionally completely equivalent) about it. just a thought, Thomas -- 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
Re: How to structure a Clojure day for noobs?
I also suspect that the IDE is important. These guys are experienced people, and I think that once they have an environment that works and they have some control over, they will have a foundation. I think they need and want to know how namespaces work, so that they can see how to modularize code. Then again, Brian's view that the REPL can be the basis for a whole book is also compelling. I must choose a path here. My hope is that, given a whole day, I can spend some time on the environment issue and still hopefully have time for both some basics and also an end-to-end example, even if it's just a tiny little web app. The plan is to give them a sense of controlling the process from the IDE, setting up a project, incrementally building it using the IDE, and then deploying it in the cloud. There are probably millions of good ways to structure such a workshop. What I'm trying to express in these posts is the lack of seeing a clear way through the features: what to start with, what to elaborate on so that they don't get too puzzled on the way to the next feature, and what to end with so that they get a sense of achievement. On Friday, 21 December 2012 03:55:46 UTC+1, Seth Chandler wrote: I would spend A LOT of time on working with the IDE be it Eclipse/Counterclockwise, IntelliJ or whatever. In my limited experience the main impediment to Clojure is not Clojure itself, which is very sensible, but in dealing with file locations, dependency management, projects, Leiningen, all of which are -- with due respect -- very difficult, particularly for people not coming from an Eclipse or similar background. Once you have the confidence that comes with understanding your IDE, you can learn Clojure by playing and by reading idiomatic code. Until then, however, Clojure development can be VERY frustrating . Maybe this will all go away once we have better IDEs (LightTable, Session) full developed, but until then don't just assume that people understand the IDE. On Saturday, December 15, 2012 4:13:21 PM UTC-6, ulsa wrote: In a couple of months, I'll have a whole day of teaching Clojure to ten of my colleagues. They are experienced Java programmers, but otherwise Clojure rookies. Any tips on how to structure such a workshop day? -- 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
Re: How to structure a Clojure day for noobs?
This is good advice. I think you can cover a lot of ground using this approach, which I guess you need to do when writing a book. As I mentioned in another post, I believe I have to choose between covering a lot of ground and building them a foundation that they can experiment on further. On Friday, 21 December 2012 04:14:41 UTC+1, Brian Marick wrote: On Dec 20, 2012, at 8:55 PM, Seth Chandler chandl...@gmail.comjavascript: wrote: but in dealing with file locations, dependency management, projects, Leiningen, all of which are -- with due respect -- very difficult, particularly for people not coming from an Eclipse or similar background. In my book, I decided to have everyone work at the repl, using only cutting-and-pasting or `load-file`. It's a 325-page book that never talks about namespaces or the `ns` macro. The beginning instructions about how to do the exercises looks like this: You can copy and paste Clojure text into the repl. It handles multiple lines just fine. [… a note about possible glitches when copying from a PDF] If you want to use a Clojure command to load a file like (for example) `solutions/add-and-make.clj`, use this: {:lang=clojure} ~~ user (load-file solutions/add-and-make.clj) ~~ *Warning*: I'm used to using `load` in other languages, so I often reflexively use it instead of `load-file`. That leads to this puzzling message: {:lang=clojure} ~~ user= (load sources/without-class-class.clj) FileNotFoundException Could not locate sources/without-class-class. clj__init.class or sources/without-class-class.clj.clj on classpath: clojure.lang.RT.load (RT.java:432) ~~ The clue to my mistake is the .clj.clj on the next-to-last line. These instructions seem to work well for my readers. Occasional consulting on programming technique Contract programming in Ruby and Clojure Latest book: /Functional Programming for the Object-Oriented Programmer/ https://leanpub.com/fp-oo -- 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
Re: How to structure a Clojure day for noobs?
Good point. I really would like themselves to be able to set up their own environment. I think it gives them a sense of control. However, as a fallback, it would be great with a virtual machine with everything working. I'll consider that. I believe you can get a similar level of interactivity in both IntelliJ and Eclipse, but I agree that Emacs is still the master. On Tuesday, 18 December 2012 04:31:32 UTC+1, Peter wrote: 1. install Leiningen and learn the basics 2. get everyone an editing environment, with the option of using either Emacs, IntelliJ, or Eclipse I would have people do this in advance, or provide a canned environment that has a better chance of just working. There's decent odds that these two steps will eat up a bunch of your time and leave people feeling left out when their install/editor/integration is not quite right. Personally I found the C-x-e of evaluating an s-exp in emacs to be the magic that makes clojure a bajillionty times better than any other programming language, so I'm partial to something like the emacs starter kit. But something like labrepl or eclipse+counterclockwise might be easier for people to start with. On Mon, Dec 17, 2012 at 3:26 AM, Marko Topolnik marko.t...@gmail.comjavascript: wrote: I think, however, that there is a risk of a disconnect, where newcomers don't really grasp that there is a JVM running and that code is actually compiled and injected into it, and that it's for real. They are used to mickey mouse interactive tools that don't provide the real thing, and struggle to bridge the apparent gap between running code in the REPL and properly compiling and running files. There is no gap, but one needs to explain that, I think. I think this is a pivot point for everything in Clojure. The harder the mental switch, the more important to make it right away. Without understanding that, it will be very hard to maintain a clear picture of how everything fits together, especially when you start changing functions and reloading them. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- The king’s heart is like a stream of water directed by the Lord; He guides it wherever He pleases. -- 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
Re: How to structure a Clojure day for noobs?
Good points, thanks. It's so easy to overload them, because one wants to teach them every little piece of gold that's in there. I think it was in one of the old XP books, where there was this graph that showed which practices were supported by or enabled other practices. I would love to see something similar for the capabilities in Clojure. It would make it easier to see what can and can not be cut out from an introduction course. My plan was to do something like this: *First half of the day* 1. install Leiningen and learn the basics 2. get everyone an editing environment, with the option of using either Emacs, IntelliJ, or Eclipse 3. teach the basics and let everyone follow along in their own environment *Second half of the day* Either: solve a smaller problem, like Game of Life, Langton's ant, or something similar or: just build a Compojure web app, and incrementally improve this, and have it deployed in CloudBees or Heroku There are a few basic things that I think they need to see: - how do I get started - how is code modularized and packaged - how can it be deployed and executed - how does Java interop work - how do I handle the regular problems I have previously used for-loops to solve On Saturday, 15 December 2012 23:57:48 UTC+1, Marko Topolnik wrote: There is one advice I can give from my teaching experience: don't overwhelm them with data. A person can assimilate only so many concepts in a day, no matter whether the workshop lasts two or eight hours. Pick a few key concepts and spend much time on approaching each concept from many different angles. Have everyone involved with exercises. Make layered exercises: each of those ten people is going to progress at their own pace. Allow enough time for the slowest ones to get through the basic part of the exercise, but have a stash of extra stuff for the quicker ones, so they don't get bored and frustrated while waiting on others. On Saturday, December 15, 2012 11:13:21 PM UTC+1, ulsa wrote: In a couple of months, I'll have a whole day of teaching Clojure to ten of my colleagues. They are experienced Java programmers, but otherwise Clojure rookies. Any tips on how to structure such a workshop day? -- 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
Re: How to structure a Clojure day for noobs?
Thanks, I won't forget the REPL. I think, however, that there is a risk of a disconnect, where newcomers don't really grasp that there is a JVM running and that code is actually compiled and injected into it, and that it's for real. They are used to mickey mouse interactive tools that don't provide the real thing, and struggle to bridge the apparent gap between running code in the REPL and properly compiling and running files. There is no gap, but one needs to explain that, I think. When in doubt, lein repl. On Sunday, 16 December 2012 21:44:33 UTC+1, Marko Topolnik wrote: My plan was to do something like this: *First half of the day* 1. install Leiningen and learn the basics 2. get everyone an editing environment, with the option of using either Emacs, IntelliJ, or Eclipse 3. teach the basics and let everyone follow along in their own environment *Second half of the day* Either: solve a smaller problem, like Game of Life, Langton's ant, or something similar or: just build a Compojure web app, and incrementally improve this, and have it deployed in CloudBees or Heroku Given this choice I'd go with the web app because it - has greater impact (a publicly visible app) and - doesn't involve the dullness of desktop GUI There are a few basic things that I think they need to see: - how do I get started - how is code modularized and packaged - how can it be deployed and executed - how does Java interop work - how do I handle the regular problems I have previously used for-loops to solve Quite a good plan. Of course, don't forget the REPL :) -- 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
Re: How to structure a Clojure day for noobs?
Interesting idea. Let me ponder that. When one starts pulling on a thread like metadata for example, all kinds of interesting facets pop up. That's what I meant with my comment about the XP practices graph thing. Different Clojure capabilities support and enable other capabilities, and you need to be prepared to explain those other capabilities. They're all (well maybe not all) interconnected and I think it's hard to know which thread to start pulling on. On Sunday, 16 December 2012 22:58:56 UTC+1, Devin Walters (devn) wrote: I think showing people how metadata works usually makes people start dreaming, and exposes them to docstrings and arglists which I think is crucial to self-directed learning. So, I think I'd show them: (doc ...), and then show how that is metadata, and for quicker folks you could show how to add metadata, use ns-publics which means introducing var-quote, etc. There's a lot in that exercise that's exciting IMHO. If you want help organizing something like that ping me privately. Cheers, '(Devin Walters) On Dec 16, 2012, at 2:44 PM, Marko Topolnik marko.t...@gmail.comjavascript: wrote: My plan was to do something like this: *First half of the day* 1. install Leiningen and learn the basics 2. get everyone an editing environment, with the option of using either Emacs, IntelliJ, or Eclipse 3. teach the basics and let everyone follow along in their own environment *Second half of the day* Either: solve a smaller problem, like Game of Life, Langton's ant, or something similar or: just build a Compojure web app, and incrementally improve this, and have it deployed in CloudBees or Heroku Given this choice I'd go with the web app because it - has greater impact (a publicly visible app) and - doesn't involve the dullness of desktop GUI There are a few basic things that I think they need to see: - how do I get started - how is code modularized and packaged - how can it be deployed and executed - how does Java interop work - how do I handle the regular problems I have previously used for-loops to solve Quite a good plan. Of course, don't forget the REPL :) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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 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
How to structure a Clojure day for noobs?
In a couple of months, I'll have a whole day of teaching Clojure to ten of my colleagues. They are experienced Java programmers, but otherwise Clojure rookies. Any tips on how to structure such a workshop day? -- 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