Re: All subsets of a vector
Or my current favorite take-while iterate combo: C:\clojure-1.2.0java -jar clojure.jar Clojure 1.2.0 user= (take-while seq (iterate rest [1 2 3 4])) ([1 2 3 4] (2 3 4) (3 4) (4)) user= (take-while seq (iterate butlast [1 2 3 4])) ([1 2 3 4] (1 2 3) (1 2) (1)) user= On Nov 9, 4:52 pm, Alex Baranosky alexander.barano...@gmail.com wrote: Dang, I just logged in in-flight just so I could post my solution with reductions :) (defn doit [coll] (rest (reductions conj [] coll))) -- 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: Newbie help in pitching in
I would recommend adding examples to clojuredocs.org and adding new problems to 4clojure.com. On Oct 19, 4:32 pm, Rett Kent rett.k...@gmail.com wrote: Hi all, Now that I have my shiny new, clojure-dev membership, I'd like to pitch in. I took a look at the pages describing how to contribute. http://clojure.org/contributinghttp://clojure.org/patches The process for contributing is pretty clear, but I'm finding it hard to find anything appropriate to my skill level and familiarity with the Clojure / clojure-contrib source to work on. Even finding an appropriate issue from a 'process' perspective is difficult, e.g. I ran a JIRA search on open, unassigned, issues and found that many of them already had patches associated with them, were waiting for someone do something or had comments that seemed to imply that someone was already working on the issue or perhaps was no longer even an issue. To say nothing of the difference between an issue being assigned to backlog, approved backlog, and the various releases. I'm wondering if anyone has some suggestions on tasks that might be useful for a newbie to work on -- documentation or grunt programming tasks would be fine. Maybe updating or expanding test cases? -- 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 Empty A Tree or Returning The Skelton of A Tree Without Leaves
I am confused by your question. If you are looking for help on a 4clojure problem, you may post to the new Google 4clojure group (http://groups.google.com/group/4clojure). If not, please give more details on the skeleton of a tree problem and I'm sure someone here can help. On Sep 7, 3:38 pm, octopusgrabbus octopusgrab...@gmail.com wrote: When I started learning Clojure, I did not want to be a casual user that shyed away from Clojure's native syntax, preferring to do as much as possible in Java. To that end, I discovered some graduate computer science Clojure exercises and started working them. I know about 4Clojure, but these exercises made my head hurt, but as the Gary Larson cartoon told it, it was a good kind of hurt. By forgoing the use of flatten and trying to roll my own, I gained some insights of how sequences are constructed and what they actually are. However, coming across the exercise to return the skeleton of a tree, I immediately thought of meta data, but I'm not sure this exercise was designed to encourage the students to use the clojure.zip routines. So, my question is, using elementary primitives, is it reasonable to return a list without its leaves, or do you really need the clojure.zip functions? Thanks. -- 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: is there a 4Clojure forum anywhere?
Hint: use the take function. On Aug 27, 8:45 pm, Shree Mulay shreemu...@gmail.com wrote: yeah, i'm stuck on the nth without cheating problem myself... would be cool if there were forums for this site! :) -- 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: is there a 4Clojure forum anywhere?
Is there a recovery group for 4clojure.com addicts? Stop now! Don't go further before it's too late and you are checking the website every five minutes waiting for the next problem, obsessing over every character in your code so you can get one of the best code golf scores, etc. But seriously, one of the greatest websites of its kind and kudos to the creators! I don't know of any discussion forums and probably would have stumbled on one over the past few weeks if there was one. On Aug 26, 3:53 pm, chepprey chepp...@gmail.com wrote: I've just started going through the problems onhttp://4clojure.com. Very fun. Does anyone know if there's a discussion forum dedicated to that site? I've searched but nothing jumps out. I'm looking for a hint on how to solve the Nth Element problem (without cheating and using the nth function). -- 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: Creating a map algorithmically
user= (def n 5) #'user/n user= (zipmap (range 2 (inc n)) (repeat true)) {5 true, 4 true, 3 true, 2 true} user= As a start... On Aug 9, 10:50 am, Kevin Sookocheff kevin.sookoch...@gmail.com wrote: Hi, I have a question regarding the map data structure. I'm trying to program a Sieve of Eratosthenes using the algorithm at Wikipedia: *Input*: an integer *n* 1 Let *A* be an array of bool values, indexed by integers 2 to *n*, initially all set to *true*. *for* *i* = 2, 3, 4, ..., *while* *i*^2 ≤ *n*: *if* *A*[*i*] is *true*: *for* *j* = *i*^2, *i*^2 + *i*, *i*^2 + 2*i*, ..., *while* *j* ≤ *n*: *A*[*j*] = *false* Now all *i* such that *A*[*i*] is *true* are prime. I'm having a problem creating the data structure A. What I want to do is create a map of integers from 2 to n all initialized to true that I can then prune using the algorithm. Any ideas? Thank you, Kevin -- 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: Argument is not an array, in a function inside deftype
I don't get any errors when I run your code. This is the output: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Are you sure you are using the latest Clojure 1.2 version and not an early beta, etc.? Process finished with exit code 0 On Dec 29, 11:25 pm, Jarl Haggerty fictivela...@gmail.com wrote: What is wrong with my code(bottom of post)? I keep getting this error. Line 24 is (get-cell [x r c] 1)) in the Matrix deftype and 36 is (print (get-cell one r c) )) in the first nested doseqs. I'm on Windows 7 with Clojure 1.2. Exception in thread main java.lang.IllegalArgumentException: Argument is not an array (core.clj:0) at clojure.lang.Compiler.eval(Compiler.java:5440) at clojure.lang.Compiler.load(Compiler.java:5857) at clojure.lang.Compiler.loadFile(Compiler.java:5820) at clojure.main$load_script.invoke(main.clj:221) at clojure.main$script_opt.invoke(main.clj:273) at clojure.main$main.doInvoke(main.clj:354) at clojure.lang.RestFn.invoke(RestFn.java:409) at clojure.lang.Var.invoke(Var.java:365) at clojure.lang.AFn.applyToHelper(AFn.java:163) at clojure.lang.Var.applyTo(Var.java:482) at clojure.main.main(main.java:37) Caused by: java.lang.IllegalArgumentException: Argument is not an array at java.lang.reflect.Array.get(Native Method) at clojure.core$aget.invoke(core.clj:2994) at clojure.lang.AFn.applyToHelper(AFn.java:165) at clojure.lang.RestFn.applyTo(RestFn.java:133) at clojure.core$apply.invoke(core.clj:542) at clojure.core$aget.doInvoke(core.clj:2996) at clojure.lang.RestFn.invoke(RestFn.java:443) at com.curious.scratch.core.Matrix2D.get_cell(core.clj:24) at com.curious.scratch.core$eval122.invoke(core.clj:36) at clojure.lang.Compiler.eval(Compiler.java:5424) ... 10 more (def float-array-class (class (float-array 1))) (defprotocol Matrix (matrix-data [x]) (matrix-height [x]) (matrix-width [x]) (matrix-add [x] [x y] [x y args]) (get-cell [x r] [x r c])) (deftype Matrix2D [data height width] Matrix (matrix-data [x] data) (matrix-height [x] height) (matrix-width [x] width) (matrix-add [x] x) (matrix-add [x y] (let [x-data (matrix-data x) y-data (matrix-data y) z-data (amap ^floats x-data index z-data (+ (aget ^floats x-data index) (aget ^floats y-data index)))] (Matrix2D. z-data (matrix-width x) (matrix-height x (matrix-add [x y args] (reduce matrix-add (matrix-add x y) args)) (get-cell [x r] (get-cell x r 0)) (get-cell [x r c] 1)) (defn matrix [data height width] (if (instance? float-array-class data) (Matrix2D. data height width) (Matrix2D. (float-array data) height width))) (def one (matrix (range 10) 5 2)) (def two (matrix-add one one)) (doseq [r (range (matrix-height one))] (doseq [c (range (matrix-width one))] (print (get-cell one r c) )) (println)) (doseq [r (range (matrix-height two))] (doseq [c (range (matrix-width two))] (print (get-cell two r c) )) (println)) -- 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
Weird result for (get max key)
I had a bug in my code where I meant to type: (get map key) and instead typed: (get max key) It seems that any function name I put in for max always returns nil. user= (get max 3) nil user= (get min 3) nil user= (get maxx 3) java.lang.Exception: Unable to resolve symbol: maxx in this context (NO_SOURCE_FILE:10) user= Any ideas? Thanks. -- 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: Why so?
I've been programming in large OO applications since about 1993. One problem is that a lot of useful code gets buried way deep in an OO class hierarchy, where you are forced to create lots of intermediate objects just to get to the useful functions. This really hurts the re-usability, unit testabilty, and a lot of other ilities. On Sep 3, 12:50 am, vishy vishalsod...@gmail.com wrote: It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures. -- Alan Perlis Why so? How is it advantageous? -- 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 can I create Java generic classes from Clojure?
Sorry, that was TOO easy. Too many years as a Java programmer have rotted my brain!. --~--~-~--~~~---~--~~ 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 can I create Java generic classes from Clojure?
If I have a Java function that uses ListInteger or MapString,Integer, is there anyway to create these in Clojure the same way I can create vectors or maps? For example, if a function signature is: void foobar(List x, Map y) I can pass standard vectors and maps to it, but I can't figure out how to do the same for this function: void foobar(ListInt x, MapString,Integer y) Thanks. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---