Re: Translating Java code with nested for loops

2011-06-29 Thread David Sletten
On Jun 29, 2011, at 1:45 AM, David Sletten wrote: (defn compute-contrib [daily-values total-values] (loop [contrib [] daily-values daily-values total-values total-values] (if (empty? daily-values) contrib (recur (conj contrib (* (first daily-values)

Aw: Translating Java code with nested for loops

2011-06-29 Thread Meikel Brandmeyer
Hi, just for fun another variation. The two reverse calls are ugly, but necessary to get the order right for the reductions call. (defn contribution [daily-values total-values] (let [weights (- (rest total-values) (map #(/ % 100.0)) reverse

Re: Translating Java code with nested for loops

2011-06-29 Thread hci
How about this one? (defn calc [total-values daily-values] (map-indexed (fn [i daily] (* daily (reduce #(* %1 (inc (/ %2 100.0))) 1.0 (nthnext total- values (inc i) daily-values)) Happy coding. -huahai On Jun 28, 10:11 pm, Justin Kramer jkkra...@gmail.com

Re: Translating Java code with nested for loops

2011-06-29 Thread Alan Malloy
If you're already doing a bunch of multiplication in the reduce, you don't need to do it outside as well, do you? And because reduce doesn't care about laziness, you can use drop instead of nthnext (which I think is clearer in almost all cases). (defn calc [total-values daily-values]

Re: Translating Java code with nested for loops

2011-06-29 Thread Ken Wesson
On Wed, Jun 29, 2011 at 3:53 AM, Alan Malloy a...@malloys.org wrote: This layout makes it fairly clear that the first element of total- values is never being used, but it would be nice if we could say so explicitly. So finally, we can wrap the whole thing in a let: (defn calc [total-values

Re: Guide to Programming in Clojure for Beginners

2011-06-29 Thread Shantanu Kumar
This is very nice indeed. Thanks for putting it up. Regards, Shantanu On Jun 29, 3:21 am, Tim Robinson tim.blacks...@gmail.com wrote: I'm fairly new to Programming, Clojure and Blogging, but I did manage to write a few posts about Clojure in my spare time.

Re: Translating Java code with nested for loops

2011-06-29 Thread Alan Malloy
On Jun 29, 12:55 am, Ken Wesson kwess...@gmail.com wrote: On Wed, Jun 29, 2011 at 3:53 AM, Alan Malloy a...@malloys.org wrote: This layout makes it fairly clear that the first element of total- values is never being used, but it would be nice if we could say so explicitly. So finally, we

Presentation of the Lacij graph visualization library

2011-06-29 Thread Pierre Allix
Hello, I have uploaded a short presentation of the Lacij graph visualization library. It can be found here: https://docs.google.com/present/view?id=dsjwfrk_1js9ptkcd Lacij is on GitHub: https://github.com/pallix/lacij -- You received this message because you are subscribed to the Google

Re: Tutorial about web development with Clojure

2011-06-29 Thread Tarantoga
Dmitry Gutov has improved the tutorial. The code looks much better now! -- 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

Where's old contrib string, str-utils and str-utils2

2011-06-29 Thread Timothy Washington
Hi there, I'm starting to dig into 1.3 and the associated libraries. I know the monolithic contrib library is no longer supported. But in the old contrib library, there were the *string*, *str-utils* and *str-utils2* libs. I don't see those or their corresponding functions in the new

Re: Translating Java code with nested for loops

2011-06-29 Thread Huahai Yang
The multiplication outside the reduce is required because it is part of the original logic: contrib[i] = sum * dailyValues[i];. Using the drop function is a very good call though. -huahai On Jun 29, 12:53 am, Alan Malloy a...@malloys.org wrote: If you're already doing a bunch of multiplication

Aw: Where's old contrib string, str-utils and str-utils2

2011-06-29 Thread Meikel Brandmeyer
Hi, I think they moved to clojure.string. 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

Re: Where's old contrib string, str-utils and str-utils2

2011-06-29 Thread Timothy Washington
That's what I thought too, but I didn't see it in the sourcehttps://github.com/clojure/clojure/blob/master/src/clj/clojure/string.clj. I also fired up the repl and tried some of the functions from str-utils2, and they weren't there... *$ lein repl * *user= (require 'clojure.string) * *nil *

Re: Where's old contrib string, str-utils and str-utils2

2011-06-29 Thread B Smith-Mannschott
On Wed, Jun 29, 2011 at 17:45, Timothy Washington twash...@gmail.com wrote: That's what I thought too, but I didn't see it in the source. I also fired up the repl and tried some of the functions from str-utils2, and they weren't there... $ lein repl user= (require 'clojure.string) nil user=

Re: Idiomatic way to reference a bundled data file from Clojure source?

2011-06-29 Thread Shantanu Kumar
The idiomatic way may be to include the file(s) in the classpath and there is already a `resource` function in clojure.java.io that can load it from the classpath: $ lein new foo $ cd foo $ mkdir resources $ catresources/test.txt hello world foo bar ^D $ # edit src/foo/core.clj as follows (ns

RE: Translating Java code with nested for loops

2011-06-29 Thread Bhinderwala, Shoeb
Thanks to all for the excellent and quick responses. David - you are right the variable should be called product not sum. This is just some poorly written Java code that I am translating to Clojure. Justin - thanks for the idea on how to visualize such algorithms and the picture you shared.

date-clj clojure date/time library

2011-06-29 Thread Islon Scherer
Hello people. I've created date-clj, a date/time library for clojure. I know there's clj-time already but I was thinking about something less javaish and more like date.js. Some examples: (date :day 25 :month :november :year 2000) - #Date Sat Nov 25 00:00:00 BRST 2000 (- (today) (set-date

Re: Tutorial about web development with Clojure

2011-06-29 Thread Sergey Didenko
Nice to see so documented example! A few remarks: 1) IMHO sandbar's approach to authorization is better that this ad-hoc one: it places auth data just in the routes instead of controllers, see https://github.com/brentonashworth/sandbar/wiki/Authentication-and-Authorization 2) It would be nice

Re: date-clj clojure date/time library

2011-06-29 Thread Laurent PETIT
java.util.Date instances aren't immutable. 2011/6/29 Islon Scherer islonsche...@gmail.com: Hello people. I've created date-clj, a date/time library for clojure. I know there's clj-time already but I was thinking about something less javaish and more like date.js. Some examples: (date :day

Re: date-clj clojure date/time library

2011-06-29 Thread Laurent PETIT
Or to be more constructive: maybe set-date al should be renamed set-date! ... ... the more clojurish a library will look like, the more expectations people will have on it (principle of least surprise) even before verifying their assumptions are true (e.g. a pure clojure library = works with

Re: Is there anything other than gen-class I can use if deftype comes just slightly short?

2011-06-29 Thread Chas Emerick
There's absolutely no shame in, where appropriate, writing a dash of Java if your Java interop requirements are simultaneously specific and unshakable. You could write a Java class with a single static factory method that returns an instance of the deftype class and that does whatever

Re: date-clj clojure date/time library

2011-06-29 Thread Islon Scherer
Thanks for the critic Laurent. set-date is not destructive, it creates a new date and returns it, the original is unaltered, but I agree that the documentation and the function name may be deceiving, I'll think about a better name and change the docs. Islon On Jun 29, 5:29 pm, Laurent PETIT

Re: Hygenic approach for using Java2D from Clojure?

2011-06-29 Thread Mikhail Kryshen
Here are some ideas I used in Indyvon (https://bitbucket.org/kryshen/ indyvon). * Methods that modify graphics context (java.awt.Graphics2D instance) are wrapped in with- macros, e.g. with-color sets the current color to the specified value, executes body in try block, and resets the color to the

Other way to express (((m2) 2) 1)?

2011-06-29 Thread Antonio Recio
Is there other way to express (((m2) 2) 1)? (def m [1 2 [21 22 [221 222 223] 23] 3]) (((m 2) 2) 1) ;- 222 -- 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

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread David Nolen
On Wed, Jun 29, 2011 at 7:00 PM, Antonio Recio amdx6...@gmail.com wrote: (def m [1 2 [21 22 [221 222 223] 23] 3]) (((m 2) 2) 1) One my favorites. (get-in m [2 2 1]) David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group,

Re: Guide to Programming in Clojure for Beginners

2011-06-29 Thread Sean Corfield
On Tue, Jun 28, 2011 at 8:21 PM, Tim Robinson tim.blacks...@gmail.com wrote: http://blackstag.com/blog.posting?id=5 I have now have a newly found appreciation for how much effort this kind of stuff can be :) Really nice set of posts - thank you for your effort!! -- Sean A Corfield -- (904)

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread Antonio Recio
(get-in m [2 2 1]) is great! Which are the others ones? Is there something like (- m [2 2 1])? -- 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

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread Tom Hicks
Sortof, but not as concisely, since the op is repeated each time: (- m (nth 2) (nth 2) (nth 1)) -tom On Jun 29, 4:20 pm, Antonio Recio amdx6...@gmail.com wrote: (get-in m [2 2 1]) is great! Which are the others ones? Is there something like (- m [2 2 1])? -- You received this message

Re: Complement to clojure survey

2011-06-29 Thread Milton Silva
At this point there are 69 responses, I think they are enough to draw some conclusions but I'll keep the survey open till later today(to see if we can get around 100 responses). As soon I close it, the results will be available for everyone. On Jun 23, 9:22 pm, Milton Silva milton...@gmail.com

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread Dmitry Gutov
You can use 'reduce': (reduce nth m [2 2 1]) ;; or, for the general case (reduce #(%1 %2) m [2 2 1]) On Jun 30, 3:20 am, Antonio Recio amdx6...@gmail.com wrote: (get-in m [2 2 1]) is great! Which are the others ones? Is there something like (- m [2 2 1])? -- You received this message because

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread David Nolen
On Wed, Jun 29, 2011 at 8:54 PM, Dmitry Gutov raa...@gmail.com wrote: You can use 'reduce': (reduce nth m [2 2 1]) ;; or, for the general case (reduce #(%1 %2) m [2 2 1]) or (reduce get m [2 2 1]) -- You received this message because you are subscribed to the Google Groups Clojure

Re: Translating Java code with nested for loops

2011-06-29 Thread Alan Malloy
(* daily (reduce * 1 coll)) ;; is exactly equal to (reduce * daily coll) My point is you can start with daily instead of with 1, and thus not have to special-case it in at the end. On Jun 29, 8:22 am, Huahai Yang huahai.y...@gmail.com wrote: The multiplication outside the reduce is required

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread Scott Jaderholm
(defmacro -f like - but f is threaded at pos 0 instead of 1 ([f] f) ([f x] `(~f ~x)) ([f x more] `(-f (~f ~x) ~@more))) (-f m 2 2 1) Scott On Wed, Jun 29, 2011 at 7:00 PM, Antonio Recio amdx6...@gmail.com wrote: Is there other way to express (((m2) 2) 1)? (def m [1 2 [21 22

Re: Other way to express (((m2) 2) 1)?

2011-06-29 Thread Scott Jaderholm
Here's another, perhaps very controversial, solution: (in m.2.2.1) ;; in (defn flexible-get ([map key] (or (let [k (read-string key)] (and (number? k) (get map k))) (get map (keyword key)) (get map (name key ([map key more] (apply

Continuations or monads or something

2011-06-29 Thread Dave Ray
Hi, Yesterday I read this article [1] on asynchronous UI workflows in F#. Basically, taking a sequential set of steps in a UI that would normally be spread across a bunch of event handlers, and making it look like sequential code in one place. So tonight I took a stab at implementing something

Russ olsen's Clojure Book

2011-06-29 Thread flebber
Just wanted to put a shout out to Russ Olsen to see what would be needed to get a Russ Olsen book on clojure to happen. I am reading design principles in Ruby and its a great read, I feel I am learning much moe than just Ruby which is why I am reading it. I woould absolutely love to read how

Re: bootclasspath

2011-06-29 Thread Kevin Downey
I have attached a patch to the jira issue http://dev.clojure.org/jira/browse/CLJ-673 it checks for a null classloader before calling methods, if the classloader is null it uses ClassLoader.getSystemResource or ClassLoader.getSystemResourceAsStream On Sat, Nov 6, 2010 at 2:04 PM, Phil Hagelberg

Re: Russ olsen's Clojure Book

2011-06-29 Thread Vivek Khurana
On Thu, Jun 30, 2011 at 8:39 AM, flebber flebber.c...@gmail.com wrote: Just wanted to put a shout out to Russ Olsen to see what would be needed to get a Russ Olsen book on clojure to happen. I am reading design principles in Ruby and its a great read, I feel I am learning much moe than just

Re: Translating Java code with nested for loops

2011-06-29 Thread Huahai Yang
Missed that one. Yeah, that's much nicer. -huahai On Jun 29, 6:39 pm, Alan Malloy a...@malloys.org wrote: (* daily (reduce * 1 coll)) ;; is exactly equal to (reduce * daily coll) My point is you can start with daily instead of with 1, and thus not have to special-case it in at the end. On

RE: Translating Java code with nested for loops

2011-06-29 Thread Bhinderwala, Shoeb
Hi Alan I really liked the way you kept refactoring the original solution by Huahai to make it more and more logical and elegant. I verified that each refactored function produced the correct results. Thanks for sharing your valuable thoughts and techniques. Shoeb -Original Message-