Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
On Sun, Apr 3, 2011 at 1:04 AM, Andreas Kostler andreas.koestler.le...@gmail.com wrote: (map (fn [x y] [x y]) coll (rest coll)) What's your reason for using (fn [x y] [x y]) here instead of just vector? Is it more efficient because it isn't variable-arity? -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
@ Ken, Andreas Thank you for your nice implementations! As far as I can see, there are two main methods of comparing adjacent items of a list: 1) Take the first item of a coll. Compare the remaining items with an offset of 1: (map f coll (rest coll)) ;; apply some sort of filter 2) Take the first and the second item of a coll. Test if both items exists and then compare: (let [x (first coll), y (second coll)] (and x y (= (f x) (f y The first method works for *take-by*, but not for *drop-while* (or so I think). Using the second method *take-by* can be changed into *drop-by* by only changing the last two lines: (defn drop-by2 [f coll] (lazy-seq (when-let [s (seq coll)] (let [x (first s) y (second s)] (if (and x y (= (f x) (f y))) (drop 2 s) (drop 1 s)) I am curious to know if one of these methods is the preferred way of doing a comparison in Clojure (aka Python's one way of doing things). The sheer number of possible solutions to the same problem sometimes overwhelms me a bit, so that I'm looking for some orientation ;-) Best regards, Stefan -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
I can't answer that Ken, I guess I wasn't thinking of vec when I wrote it :) On 03/04/2011, at 5:17 PM, Ken Wesson wrote: On Sun, Apr 3, 2011 at 1:04 AM, Andreas Kostler andreas.koestler.le...@gmail.com wrote: (map (fn [x y] [x y]) coll (rest coll)) What's your reason for using (fn [x y] [x y]) here instead of just vector? Is it more efficient because it isn't variable-arity? -- 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 -- Test-driven Dentistry (TDD!) - Not everything should be test driven - Michael Fogus -- ** Andreas Koestler, Software Engineer Leica Geosystems Pty Ltd 270 Gladstone Road, Dutton Park QLD 4102 Main: +61 7 3891 9772 Direct: +61 7 3117 8808 Fax: +61 7 3891 9336 Email: andreas.koest...@leica-geosystems.com www.leica-geosystems.com* when it has to be right, Leica Geosystems Please consider the environment before printing this email. -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
Hi Stefan, I am overwhelmed by the 'freedom of choice' Clojure gives you, too. In that respect it's more like ruby than python. Nevertheless, I think if you can come up with an algorithm using the built in functions over sequences like map, reduce, filter, etc. you should do so. Either way, it doesn't really matter which way you do it, just do it right and then refine as you go (and gain more experience). Just be aware that you have to explicitly loop-recur for tail recursive processes, recursive processes might blow up your call stack pretty quickly. So that would cover 1) For 2) I can think of a straight forward tail-recursive process to do what you want: (defn drop-by [f coll] (loop [coll coll] (let [x (first coll) y (second coll)] (if (and x y (= (f x) (f y))) (recur (rest coll)) (rest coll) Maybe someone on this list can think of an implementation in terms of sequence functions. Cheers Andreas P.s. The most powerful tool that comes with Clojure is this community. Use it! On 03/04/2011, at 5:23 PM, Stefan Rohlfing wrote: @ Ken, Andreas Thank you for your nice implementations! As far as I can see, there are two main methods of comparing adjacent items of a list: 1) Take the first item of a coll. Compare the remaining items with an offset of 1: (map f coll (rest coll)) ;; apply some sort of filter 2) Take the first and the second item of a coll. Test if both items exists and then compare: (let [x (first coll), y (second coll)] (and x y (= (f x) (f y The first method works for take-by, but not for drop-while (or so I think). Using the second method take-by can be changed into drop-by by only changing the last two lines: (defn drop-by2 [f coll] (lazy-seq (when-let [s (seq coll)] (let [x (first s) y (second s)] (if (and x y (= (f x) (f y))) (drop 2 s) (drop 1 s)) I am curious to know if one of these methods is the preferred way of doing a comparison in Clojure (aka Python's one way of doing things). The sheer number of possible solutions to the same problem sometimes overwhelms me a bit, so that I'm looking for some orientation ;-) Best regards, Stefan -- 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 -- Test-driven Dentistry (TDD!) - Not everything should be test driven - Michael Fogus -- ** Andreas Koestler, Software Engineer Leica Geosystems Pty Ltd 270 Gladstone Road, Dutton Park QLD 4102 Main: +61 7 3891 9772 Direct: +61 7 3117 8808 Fax: +61 7 3891 9336 Email: andreas.koest...@leica-geosystems.com www.leica-geosystems.com* when it has to be right, Leica Geosystems Please consider the environment before printing this email. -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
On Sun, Apr 3, 2011 at 7:15 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 3 Apr., 12:24, Ken Wesson kwess...@gmail.com wrote: I don't. :) (defn drop-by [f coll] (let [fs (map f coll) ps (map = fs (rest fs)) zs (map list ps (rest coll))] (map second (drop-while first zs user= (drop-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42]) (2 99 103 42) I especially like the symmetry of using take-while for the one and drop-while for the other, under the hood. Or a bit less involved. (defn take-by [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) value (f fst)] (cons fst (take-while #(- % f (= value)) (rest s))) (defn drop-by [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) value (f fst)] (drop-while #(- % f (= value)) (rest s)) Less involved? -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
Hi, On 3 Apr., 13:18, Ken Wesson kwess...@gmail.com wrote: Less involved? Your solution combines 5 sequences with drop-while-first-map-second magic which I personally don't find very self-explaining at first sight. My solution does one step with only local impact and then delegates to a single well-known library function. For laziness there is some cost involved, I agree. Sincerely Meikel -- 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
Clojure Code Highlighting in Presentations
Hi everyone, not a clojure technical question but it has to do with the entire topic :). I know there have been some presentations about clojure already and would like to ask for some best practice experience regarding embedding Clojure code in a presentation. Any advice? What tools did you people use for coloring the code in slides? I'd be very thankful for some hints and pointers in the right direction so I don't have to reinvebt the wheel :). Best regards and thanks in advance, Heinz N. Gies smime.p7s Description: S/MIME cryptographic signature
Re: Clojure Code Highlighting in Presentations
On Sun, 3 Apr 2011 18:15:43 +0200 Heinz N. Gies he...@licenser.net wrote: Hi everyone, not a clojure technical question but it has to do with the entire topic :). I know there have been some presentations about clojure already and would like to ask for some best practice experience regarding embedding Clojure code in a presentation. Any advice? What tools did you people use for coloring the code in slides? I'd be very thankful for some hints and pointers in the right direction so I don't have to reinvebt the wheel :). I use enscript for highlighting source code - it can generate pretty nearly anything you'd ever want. I've got a state file for clojure you'll need if you want to highlight clojure code. mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Software developer/SCM consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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 use params in java?
Hello, Armando! do you can give me short example? I have some RuntimeExaptions :( On 3 апр, 01:31, Armando Blancas armando_blan...@yahoo.com wrote: You need to use a few more classes from jvm/clojure/lang. For example, with PersistentVector#create(Object...) and one of the Keyword#intern() calls you should be able to construct myParams. On Apr 2, 4:32 am, monyag monyag@gmail.com wrote: -- 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: Clojure Code Highlighting in Presentations
On Apr 3, 9:15 pm, Heinz N. Gies he...@licenser.net wrote: Hi everyone, not a clojure technical question but it has to do with the entire topic :). I know there have been some presentations about clojure already and would like to ask for some best practice experience regarding embedding Clojure code in a presentation. Any advice? What tools did you people use for coloring the code in slides? I'd be very thankful for some hints and pointers in the right direction so I don't have to reinvebt the wheel :). Type in either of Pastebin, Github gist or Bitbucket Wiki and then Paste-Special (preserve formatting) in the presentation software of your choice? Regards, Shantanu -- 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: using clojure for (java) code generation; advice sought
On Fri, Apr 1, 2011 at 22:18, B Smith-Mannschott bsmith.o...@gmail.com wrote: On Wed, Mar 30, 2011 at 15:00, Stuart Sierra the.stuart.sie...@gmail.com wrote: Take a look at http://www.stringtemplate.org/ for a Turing-complete, purely-functional, Java-based template language designed for code generation. Well, I've spent the weekend wrangling with StringTemplate (ST) and though I'd share my experiences so far. I'm sorry; this is a bit rambling. I chose to jump straight to ST 4, which came out at the end of March, figuring there was no point in learning 3.x since 4.0 seems to be where active development will go in the future. This was a mixed blessing because the practical examples available on the net and the majority of the documentation is actually still for 3.x, which is not completely compatible with 4.0. Also, I found ST's behavior with respect to syntax errors in templates to be less than helpful. Basically it'll throw a NullPointerException, or maybe an IllegalArgumentException or just puke some stuff on the console (generally hidden behind my emacs window). This is rough for a learner. Also, I'm generating java source code which includes uses of generics. This interacts hideously with ST's default of using and to delimit a template expression and and to delimit the beginning and end of a template definition. This can be customized, but the customization is not all I hoped for. At first I tried to customize to « and » but this breaks the ability to include comments in the string template group file. (Normally comments are ! ... !, presumably they would be «! ... !» when one has customized the delimiter characters like I had. But, the fact is neither syntax seemed to work. This cost me *hours* because while the console printed out a huge number of error messages, they were always the same error messages printed in such a way that the console never seemed to scroll, so I thought I was looking at old output and had fixed the problem (by changing ! to «!). The parse errors caused the non-comment comment caused all kinds of strange behavior in later templates, such as crashes. I found, for example, that: someTemplate(a,b) ::= « ... » «list1,list2:someTemplate()» which is roughly analogous to: (defn someTemplate [a b] ...) (map someTemplate list1 list2) Would crash complaining about not having definitions for i0 and i (these variables are something ST defines implicitly for iteration. I don't know the details.) I found I could fix that by changing the template definition to include i0 and i arguments, though I never used them in the template. This just seemed demented. It was at that point that I went to bed. This morning, I finally understood the comment problem and found that if I changed the delimiters to $ and $ and the comments to $! and !$ all was once again well with the world. It's annoying though that opening $ and closing $ are the same character, which doesn't aid readability. So, I've made some progress in my understanding of ST. Now that I sit down and try to re-implement my existing code emission using ST, I find a design question rearing its head. I'm not sure how much complexity to push into the templates and how much to leave in Clojure. I could have a large number of very simple templates and use Clojure to drive and assemble them. Alternatively, I could have a single entry point to a large set of templates which call each other internally. That means using Clojure to construct a data model (a map of lists of maps of ...) suitable for consumption by ST. First I through I'd take the first alternative, but then I decided to try the second one first, though now it's looking like I will go back to doing more in clojure and less in ST. I already have a perfectly serviceable model but it seems increasingly like I'd have to tear it apart and build it up completely differently to get it into a form that ST can consume in a reasonable fashion. Here's a simplified fragment of my model: { :class-name SomeEnum :id-field :id :records [{:id A, :payload 3}, {:id B, :payload 4}] } produces: enum SomeEnum { A(3), B(4); int payload; SomeEnum(int payload) { this.payload = payload; } } - I'm using keywords, but StringTemplate can't tolerate those as keys - ST's variable's can't contain -, so I can't just convert the keyword keys to strings, I have to rename them too. - the type of :payload is not stored explicitly anywhere, but it's a real java Integer in the model, so I just use (type) to figure out what it is. - I have an function (unbox) which gives me the unboxed equivalent where appropriate, otherwise identity. (ST provides Maps, as part of its template language which could almost do this for me, but not quite.) - I have logic to generate java literal versions of various values: i.e. 1.0M - BigDecimal.ONE; 11.0M - new BigDecimal(11.0) (ST supports ModelRenderers for this, I think). It's looking more and more like using ST is
Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
Isn't all this just a special case of partition-by? (defn drop-by [f coll] (apply concat (rest (partition-by f coll (defn take-by [f coll] (first (partition-by f coll))) user (drop-by (partial + 2) [2 2 2 3 3 4]) (3 3 4) user (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42]) (1 4 1 7 34 16 10) On Apr 3, 6:34 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 3 Apr., 13:18, Ken Wesson kwess...@gmail.com wrote: Less involved? Your solution combines 5 sequences with drop-while-first-map-second magic which I personally don't find very self-explaining at first sight. My solution does one step with only local impact and then delegates to a single well-known library function. For laziness there is some cost involved, I agree. Sincerely Meikel -- 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
bug report : cl-format
Hello, I don't know if there is a better way to file bug reports (if there is one, it's not easy to find). (use 'clojure.pprint) (let [x 111.1] (doseq [fmt [~3f~% ~4f~% ~5f~% ~6f~%]] (cl-format true fmt x))) ;; 111.1 ;; 111.1 ;; 111.1 ;; 111.11 There is clearly a problem in the first two cases, too many digits are being printed. For reference, this is what common lisp does: (let ((x 111.1)) (loop for fmt in '(~3f~% ~4f~% ~5f~% ~6f~%) do (format t fmt x))) ;; 111. ;; 111. ;; 111.1 ;; 111.11 Cheers, Carlos -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
There you go, symmetry and simplicity :) On 04/04/2011, at 6:35 AM, Alan wrote: Isn't all this just a special case of partition-by? (defn drop-by [f coll] (apply concat (rest (partition-by f coll (defn take-by [f coll] (first (partition-by f coll))) user (drop-by (partial + 2) [2 2 2 3 3 4]) (3 3 4) user (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42]) (1 4 1 7 34 16 10) On Apr 3, 6:34 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 3 Apr., 13:18, Ken Wesson kwess...@gmail.com wrote: Less involved? Your solution combines 5 sequences with drop-while-first-map-second magic which I personally don't find very self-explaining at first sight. My solution does one step with only local impact and then delegates to a single well-known library function. For laziness there is some cost involved, I agree. Sincerely Meikel -- 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 -- Test-driven Dentistry (TDD!) - Not everything should be test driven - Michael Fogus -- ** Andreas Koestler, Software Engineer Leica Geosystems Pty Ltd 270 Gladstone Road, Dutton Park QLD 4102 Main: +61 7 3891 9772 Direct: +61 7 3117 8808 Fax: +61 7 3891 9336 Email: andreas.koest...@leica-geosystems.com www.leica-geosystems.com* when it has to be right, Leica Geosystems Please consider the environment before printing this email. -- 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: Example to introspect a class
Thank you I'm still learning all the different forms so this is very helpful. On Apr 1, 10:13 pm, Ken Wesson kwess...@gmail.com wrote: On Fri, Apr 1, 2011 at 10:56 AM, Mushfaque Chowdhury mushfaque.chowdh...@googlemail.com wrote: Hi I'm trying to solve a introspection problem of the following type (def Region {'fields '((datatype x) (datatype y))}) (def Country {'fields '((int x) (double y {reference `Region}))}) I'd like to introspect the fields from Country and see {reference Region} replaced by (reference ((datatype x) (datatype y))) I can get as far as seeing this ((nth (nth (Country 'fields) 1) 2) 'reference) which gives (quote com.test.Common/Region) which is sort of close, but how do I now look at it's fields? First of all, that's not actually a class, it's a var. Second, does it actually need to be quoted a second level? Third, (second '(quote com.test.Common/Region)) will be the symbol com.test.Common/Region, and if you get that symbol into a local named foo, (ns-resolve *ns* foo) ought to yield up a Var object. And (@that-var 'fiels} then ought to cough up '((datatype x) (datatype y)). Indeed: user= (def Region {'fields '((datatype x) (datatype y))}) #'user/Region user= (def Country {'fields '((int x) (double y {reference `Region}))}) #'user/Country user= (@(ns-resolve (find-ns 'user) (nth ((nth (nth (Country 'fields) 1) 2) 'reference) 1)) 'fields) ((datatype x) (datatype y)) -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
Hi When I read this post in the morning I thought about how I would implement this function, and the result was: (defn take-by [f coll] (when-let [[x xs] (seq coll)] (let [n (f x)] (lazy-seq (cons x (take-while #(= n (f %)) xs)) I didn't post it, because I really am a beginner in clojure and functional programming and others had already given different answers that were far more 'complicated' than my solution. Now, my question is what's the improvement of (defn take-by [f coll] (let [fs (map f coll) ps (map = fs (rest fs)) zs (map #(if %1 %2 sentinel) ps (rest coll))] (cons (first coll) (take-while (partial not= sentinel) zs over (defn take-by [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) value (f fst)] (cons fst (take-while #(- % f (= value)) (rest s))) Sincerely Roman -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
I like your version, Roman. It seems as efficient as anything, and is easy to read. For what it's worth, I'd make a small rewrite: (defn take-by [f coll] (lazy-seq (when-let [[x xs] (seq coll)] (let [val (f x)] (cons x (take-while (comp #{val} f) xs)) On Apr 3, 5:45 am, Roman Sykora 4rt.f...@gmail.com wrote: Hi When I read this post in the morning I thought about how I would implement this function, and the result was: (defn take-by [f coll] (when-let [[x xs] (seq coll)] (let [n (f x)] (lazy-seq (cons x (take-while #(= n (f %)) xs)) I didn't post it, because I really am a beginner in clojure and functional programming and others had already given different answers that were far more 'complicated' than my solution. Now, my question is what's the improvement of (defn take-by [f coll] (let [fs (map f coll) ps (map = fs (rest fs)) zs (map #(if %1 %2 sentinel) ps (rest coll))] (cons (first coll) (take-while (partial not= sentinel) zs over (defn take-by [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) value (f fst)] (cons fst (take-while #(- % f (= value)) (rest s))) Sincerely Roman -- 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 use params in java?
I don't have any examples; using a Clojure lib like that is a real pain. As you can see, interop to Java doesn't just happens but it must be designed into a library. You may want to consider adding an interop layer on top that vijual thingy or use plain scripting for everything and not use invoke. On Apr 3, 11:18 am, monyag monyag@gmail.com wrote: Hello, Armando! do you can give me short example? I have some RuntimeExaptions :( On 3 апр, 01:31, Armando Blancas armando_blan...@yahoo.com wrote: You need to use a few more classes from jvm/clojure/lang. For example, with PersistentVector#create(Object...) and one of the Keyword#intern() calls you should be able to construct myParams. On Apr 2, 4:32 am, monyag monyag@gmail.com wrote: -- 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
April Showers Bring May Flowers - raindrop advice please
I am experimenting with Java Graphics and Clojure. I made a Gist that draws a frame with some text, grass and raindrops falling. I made a function that draws a raindrop falling and I created agents to send off the drawing of the raindrop. I then called pmap to send-off the agents to the draw-raindrop function. The problem is, that I can't seem to get more than one raindrop falling being drawn at one time. If anyone could help me understand whether what the problem is, I would appreciate it. https://gist.github.com/900809 Wishing for parallel raindrops and May flowers. - Carin Meier -- 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: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection
On Sun, Apr 3, 2011 at 8:45 AM, Roman Sykora 4rt.f...@gmail.com wrote: Now, my question is what's the improvement of (defn take-by [f coll] (let [fs (map f coll) ps (map = fs (rest fs)) zs (map #(if %1 %2 sentinel) ps (rest coll))] (cons (first coll) (take-while (partial not= sentinel) zs over (defn take-by [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) value (f fst)] (cons fst (take-while #(- % f (= value)) (rest s))) Sincerely Roman The former is shorter and, IMO, a bit clearer. The lattter though is probably more efficient at runtime. So the answer is really it depends. The partition-by implementations are even shorter and clearer, of course, but I thought it would be instructive to show a way of implementing that general type of thing (depending on successive elements of a single seq) without using an existing similar function (e.g. partition-by) -- where does the first such function come from? -- and using the basic sequence operations like map, filter, and reduce. The more versatilely you can use those sequence functions to solve problems, the better a Clojure programmer you are, quite frankly. And so ultimately having all the different variations posted here helps everyone reading this thread. There are even a couple of interesting bugs and their fixes in this thread. :) It's also true that the more you look at and understand code like what's in this thread, the more you can get into the functional mind-set, making patterns like (map foo x (rest x)) jump quickly to mind (as well as possibly higher-level functions like partition-by) when you see certain kinds of problem (like depending on successive members of a seq). Of course, part of thinking functionally includes thinking how patterns like that can be turned into useful abstractions, too. For example, to get groups of n consecutive elements in general. You could use (map vector x (rest x)) to get all the pairs of successive elements; then again we also have (partition 2 1 x) and the general (partition n 1 x) for this. What about generalizing (map foo x (rest x) (rest (rest x)) ...)? Well, the obvious is (map (partial apply foo) (partition n 1 x))) for this. You could grab this and define it as a function if you find you need it much: (defn map-nextn [f n s] (map (partial apply f) (partition n 1 s))) How would you implement this without partition? One possibility would be (defn map-nextn [f n s] (apply map f (take n (iterate rest s which, interestingly, is actually two characters *shorter*, though I wouldn't say it was clearer. :) Cheers. -- 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: April Showers Bring May Flowers - raindrop advice please
On Sun, Apr 3, 2011 at 5:10 PM, carinmeier gigasq...@yahoo.com wrote: I am experimenting with Java Graphics and Clojure. I made a Gist that draws a frame with some text, grass and raindrops falling. I made a function that draws a raindrop falling and I created agents to send off the drawing of the raindrop. I then called pmap to send-off the agents to the draw-raindrop function. The problem is, that I can't seem to get more than one raindrop falling being drawn at one time. If anyone could help me understand whether what the problem is, I would appreciate it. https://gist.github.com/900809 Wishing for parallel raindrops and May flowers. Do you have separate agents for each raindrop? And are you using send-off rather than send? -- 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: Clojure Code Highlighting in Presentations
Greetings, not a clojure technical question but it has to do with the entire topic :). I know there have been some presentations about clojure already and would like to ask for some best practice experience regarding embedding Clojure code in a presentation. Any advice? What tools did you people use for coloring the code in slides? I used a combination of S5 and Pygments, you can see a demo I did (and the scripts to create it) over at http://goo.gl/YCVUC (it's a Python presentation, but pygmentize can do Clojure as well). Another thing I did was screenshot of VIm showing the code, this we done in http://goo.gl/wAbXY HTH, -- Miki -- 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: April Showers Bring May Flowers - raindrop advice please
Ken, Yes, I have separate agents for the raindrops and I am using send- off ... Here is the code bit: (defn make-it-rain [g num-raindrops] (let [rainagents (vec (repeat num-raindrops (agent nil)))] (dorun (pmap #(send-off % draw-raindrop-fall g (rand-nth (range 0 500))) rainagents On Apr 3, 5:15 pm, Ken Wesson kwess...@gmail.com wrote: On Sun, Apr 3, 2011 at 5:10 PM, carinmeier gigasq...@yahoo.com wrote: I am experimenting with Java Graphics and Clojure. I made a Gist that draws a frame with some text, grass and raindrops falling. I made a function that draws a raindrop falling and I created agents to send off the drawing of the raindrop. I then called pmap to send-off the agents to the draw-raindrop function. The problem is, that I can't seem to get more than one raindrop falling being drawn at one time. If anyone could help me understand whether what the problem is, I would appreciate it. https://gist.github.com/900809 Wishing for parallel raindrops and May flowers. Do you have separate agents for each raindrop? And are you using send-off rather than send? -- 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: April Showers Bring May Flowers - raindrop advice please
On Sun, Apr 3, 2011 at 4:31 PM, carinmeier gigasq...@yahoo.com wrote: (let [rainagents (vec (repeat num-raindrops (agent nil)))] Wouldn't that create a vector with N copies of the same agent? Try: (let [rainagents (vec (map agent (repeat num-raindrops nil)))] (dorun (pmap #(send-off % draw-raindrop-fall g (rand-nth (range 0 500))) rainagents -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Railo Technologies, Inc. -- http://www.getrailo.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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: April Showers Bring May Flowers - raindrop advice please
You are exactly right! Thank you! On Apr 3, 8:27 pm, Sean Corfield seancorfi...@gmail.com wrote: On Sun, Apr 3, 2011 at 4:31 PM, carinmeier gigasq...@yahoo.com wrote: (let [rainagents (vec (repeat num-raindrops (agent nil)))] Wouldn't that create a vector with N copies of the same agent? Try: (let [rainagents (vec (map agent (repeat num-raindrops nil)))] (dorun (pmap #(send-off % draw-raindrop-fall g (rand-nth (range 0 500))) rainagents -- Sean A Corfield -- (904) 302-SEAN An Architect's View --http://corfield.org/ World Singles, LLC. --http://worldsingles.com/ Railo Technologies, Inc. --http://www.getrailo.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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: April Showers Bring May Flowers - raindrop advice please
I'd write it as (repeatedly num-raindrops #(agent nil)). On Apr 3, 5:27 pm, Sean Corfield seancorfi...@gmail.com wrote: On Sun, Apr 3, 2011 at 4:31 PM, carinmeier gigasq...@yahoo.com wrote: (let [rainagents (vec (repeat num-raindrops (agent nil)))] Wouldn't that create a vector with N copies of the same agent? Try: (let [rainagents (vec (map agent (repeat num-raindrops nil)))] (dorun (pmap #(send-off % draw-raindrop-fall g (rand-nth (range 0 500))) rainagents -- Sean A Corfield -- (904) 302-SEAN An Architect's View --http://corfield.org/ World Singles, LLC. --http://worldsingles.com/ Railo Technologies, Inc. --http://www.getrailo.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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: April Showers Bring May Flowers - raindrop advice please
Nice. Thanks. It is also interesting now to see the graphical difference in running send-off vs send for my raindrops. send gives me a nice drizzle, while send-off gives me a sudden downpour :) On Apr 3, 9:29 pm, Alan a...@malloys.org wrote: I'd write it as (repeatedly num-raindrops #(agent nil)). On Apr 3, 5:27 pm, Sean Corfield seancorfi...@gmail.com wrote: On Sun, Apr 3, 2011 at 4:31 PM, carinmeier gigasq...@yahoo.com wrote: (let [rainagents (vec (repeat num-raindrops (agent nil)))] Wouldn't that create a vector with N copies of the same agent? Try: (let [rainagents (vec (map agent (repeat num-raindrops nil)))] (dorun (pmap #(send-off % draw-raindrop-fall g (rand-nth (range 0 500))) rainagents -- Sean A Corfield -- (904) 302-SEAN An Architect's View --http://corfield.org/ World Singles, LLC. --http://worldsingles.com/ Railo Technologies, Inc. --http://www.getrailo.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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 use params in java?
I don't need concrete example with vijual, I don't understand how to use this parameters whatever vijual -( Thanks for the help, Armando, I'm trying do this. On 4 апр, 06:07, Armando Blancas armando_blan...@yahoo.com wrote: I don't have any examples; using a Clojure lib like that is a real pain. As you can see, interop to Java doesn't just happens but it must be designed into a library. You may want to consider adding an interop layer on top that vijual thingy or use plain scripting for everything and not use invoke. On Apr 3, 11:18 am, monyag monyag@gmail.com wrote: -- 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