Re: Can I make this faster?

2010-02-18 Thread Jason Wolfe
Hey Aria, If you really want a mutable Counter, IMO you might as well do things your "Java" way with a HashMap ... or at least that's how I would do it. A more Clojure way would be a totally safe, functional counter: (deftype ClojureCounter2 [counts total] Counter (getCount [k] (get counts

Re: jmx with auth

2010-02-18 Thread Stuart Halloway
Hi Drz, Just pushed a fix, let me know if it works for you. http://github.com/richhickey/clojure-contrib/commit/6f2b1d73b50b7b9f0d753aa0f5fd343b67f75bf6 Stu I am just starting to play around with clojure. I was trying to use the clojure.contrib.jmx library to connect to remote java vms that

side effects in fn passed to filter

2010-02-18 Thread Rowdy Rednose
The filter documentation reads: "Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects." So that means I should not write a function like this: (defn unique [sc] "Returns a lazy sequence with all consecutive duplicates removed" (le

Re: side effects in fn passed to filter

2010-02-18 Thread Rowdy Rednose
I just noticed I put the doc string in the wrong place. So this would be the correct way: (defn unique "Returns a lazy sequence with all consecutive duplicates removed" [sc] (let [last (atom (Object.))] (filter #(let [ok (not= @last %)] (reset! last %) ok) sc))) On Feb 18, 11:04 pm, Row

Re: side effects in fn passed to filter

2010-02-18 Thread Sean Devlin
The first thing I can think of is that filter is lazy. You side effects won't occur when you think they will. Generally if you're dealing with side-effects over a sequence, it's time to think about using a macro, such as doseq. In your specific case, I'd recommend using a custom form of reduce,

Re: side effects in fn passed to filter

2010-02-18 Thread Stuart Halloway
(use 'clojure.contrib.seq-utils) (def by-pairs (partial partition-all 2 1)) ; ignores possibility of nil (exercise for reader) (defn matched-pair? [[a b]] (= a b)) ; I think this is very literate (println (let [x [1 2 3 4 5 5 5 6]] (->> (by-pairs x) (remove matc

Re: side effects in fn passed to filter

2010-02-18 Thread Meikel Brandmeyer
Hi, On Feb 18, 3:04 pm, Rowdy Rednose wrote: > "Returns a lazy sequence of the items in coll for which (pred item) > returns true. pred must be free of side-effects." > > So that means I should not write a function like this: > > (defn unique [sc] >   "Returns a lazy sequence with all consecutiv

Re: side effects in fn passed to filter

2010-02-18 Thread Stuart Halloway
Rowdy's question asks for less than what core/distinct delivers--he only wanted to remove *adjacent* duplicates. That said, core/distinct is a better demo of "how do I maintain state across a lazy sequence without requiring any mutation?" Stu Hi, On Feb 18, 3:04 pm, Rowdy Rednose wrote:

bug? #'separate in seq-utils

2010-02-18 Thread reynard
ok, the following works as expected. user> (separate (fn [n] (= n 2)) '(1 2 3 4 5)) [(2) (1 3 4 5)] now, I want to randomly select a number from '(1 2 3 4 5), I change the function to the following, and the result is NOT expected. user> (separate (fn [n]

http-agent usage in subsequent agent action question

2010-02-18 Thread sim
I have been using http-agents to grab a bunch of pages and then process them, my initial solutions involved partitioning a sequence of urls and then awaiting for that group before moving on. (I'm using clojure-1.1.0 and clojure-contrib-1.1.0) However the problem with that approach is that when on

Re: jmx with auth

2010-02-18 Thread Drz
Stu, Works for me. Thanks for the quick turn around. Drz On Feb 18, 5:27 am, Stuart Halloway wrote: > Hi Drz, > > Just pushed a fix, let me know if it works for > you.http://github.com/richhickey/clojure-contrib/commit/6f2b1d73b50b7b9f0... > > Stu > > > > > I am just starting to play around

Re: side effects in fn passed to filter

2010-02-18 Thread Sean Devlin
Well, if it's golf... (use 'clojure.contrib.seq-utils) (map first (partition-by identity [1 2 3 4 5 5 5 6])) On Feb 18, 9:34 am, Stuart Halloway wrote: > Rowdy's question asks for less than what core/distinct delivers--he   > only wanted to remove *adjacent* duplicates. > > That said, core/dist

Re: bug? #'separate in seq-utils

2010-02-18 Thread Stuart Halloway
You are using it incorrectly. Separate returns a vector of things that match, and a vector of things that don't match. Every time you call the function it matches against a different random number. Take a look at rand-elt in clojure.contrib.seq-utils. Maybe the docstring for separate should

Re: bug? #'separate in seq-utils

2010-02-18 Thread reynard
On Feb 18, 10:51 pm, Stuart Halloway wrote: > You are using it incorrectly. Separate returns a vector of things that   > match, and a vector of things that don't match. Every time you call   > the function it matches against a different random number. Take a look   > at rand-elt in clojure.contr

Re: side effects in fn passed to filter

2010-02-18 Thread Rowdy Rednose
Various interesting approaches to this problem... thanks guys! Stu, you're right, distinct builds up a set of all items encountered, which I don't need, and it's costly. But that function it is indeed a good model. So here's a side effects free version modeled after distinct: (defn better-unique

Re: side effects in fn passed to filter

2010-02-18 Thread Meikel Brandmeyer
Hi, On Feb 18, 4:34 pm, Rowdy Rednose wrote: > better-unique is not too far off from my initial approach, but still, > why no side effects? Here an example, where side-effects are the gotcha: http://groups.google.com/group/clojure/browse_thread/thread/d8fe58489e913433 (filter #(mod % (rand-int

Re: side effects in fn passed to filter

2010-02-18 Thread fra
You can try the following (defn unique[s] "Returns a lazy sequence with all consecutive duplicates removed" (filter identity (map #(when (not= %1 %2) %1) s (cons nil s) ))) On Feb 18, 3:04 pm, Rowdy Rednose wrote: > The filter documentation reads: > > "R

Re: side effects in fn passed to filter

2010-02-18 Thread eyeris
On Feb 18, 9:34 am, Rowdy Rednose wrote: > better-unique is not too far off from my initial approach, but still, > why no side effects? > Even though I do not know when the side-effects happen (lazily, > eagerly), shouldn't the order be fixed in case of filter? I think the term "must" in the doc

Re: side effects in fn passed to filter

2010-02-18 Thread Sean Devlin
Rowdy, Does your profiling test do any work? There aren't any duplicates in (range 100) Perhaps you should run a few more benchmarks to get a better idea of what is going on. Sean On Feb 18, 10:34 am, Rowdy Rednose wrote: > Various interesting approaches to this problem... thanks guys! > >

ANN: byte-spec-0.1

2010-02-18 Thread Jeff Rose
Just a quick announcement for a small library recently extracted from Project Overtone. It lets you specify binary formats and then serialize to and from clojure data structures. This was created to read and write SuperCollider synthesizer definition files, but it could be used for other binary f

Re: side effects in fn passed to filter

2010-02-18 Thread Rowdy Rednose
Yeah, the numbers depend a bit on the data, so distinct will look better if there are many dupes, and running tests against (mapcat vector (range 50) (range 50)) so we have 50% dupes, gave me these numbers: user=> (time (count (unique (mapcat vector (range 50) (range 50) "Ela

Re: ANN: byte-spec-0.1

2010-02-18 Thread David Nolen
Nice, overtone also looks really interesting :) On Thu, Feb 18, 2010 at 11:59 AM, Jeff Rose wrote: > Just a quick announcement for a small library recently extracted from > Project Overtone. It lets you specify binary formats and then > serialize to and from

Re: side effects in fn passed to filter

2010-02-18 Thread Sean Devlin
Thanks for running the second experiment. The more I think about it, getting "typical" performance numbers for something like this is very difficult, just like getting "typical" numbers for sorting algorithms is difficult. Beware the evils of micro-benchmarking. Does anyone have some ideas on ho

Re: side effects in fn passed to filter

2010-02-18 Thread Meikel Brandmeyer
Hi, On Thu, Feb 18, 2010 at 09:44:52AM -0800, Rowdy Rednose wrote: > Yeah, the numbers depend a bit on the data, so distinct will look > better if there are many dupes, and running tests against > > (mapcat vector (range 50) (range 50)) > > so we have 50% dupes, gave me these numbers:

Re: side effects in fn passed to filter

2010-02-18 Thread Sean Devlin
Wait... what's the problem we're trying to solve? On Feb 18, 1:56 pm, Meikel Brandmeyer wrote: > Hi, > > On Thu, Feb 18, 2010 at 09:44:52AM -0800, Rowdy Rednose wrote: > > Yeah, the numbers depend a bit on the data, so distinct will look > > better if there are many dupes, and running tests again

Re: side effects in fn passed to filter

2010-02-18 Thread Meikel Brandmeyer
On Thu, Feb 18, 2010 at 07:56:02PM +0100, Meikel Brandmeyer wrote: > You have to sort the collections with your unique. This is not counted > in the current benchmark. Forget that. > Any reason why not to use (concat (range ..) (range ..))? ;) There is a reason Sincerely Meikel -- You re

Re: REST library

2010-02-18 Thread Brandon Mason
This is also worth taking a look at: http://code.google.com/p/implementing-rest/wiki/ByLanguage Thanks for the link. I'm also starting a RESTful Clojure project. This looks like good reading for me. On Feb 17, 4:10 am, Shantanu Kumar wrote: > On Feb 17, 3:05 pm, Roman Roelofsen > wrote: > > > H

Does the Logo have a name?

2010-02-18 Thread mcpeterson
If not, I propose "the lambyang". - mcpeterson -- 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

commute misunderstanding

2010-02-18 Thread Аркадий Рост
Hi! I don't understand difference between commute and alter. In fact I don't understand how can I get different results by changing alter to commute in code.I've read that the in-transaction value with commute is that it may differ from the post-commit value, as the effect of commute is a function

Re: side effects in fn passed to filter

2010-02-18 Thread Meikel Brandmeyer
Hi, > Wait... what's the problem we're trying to solve? My mistake. I was confused. 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

Re: commute misunderstanding

2010-02-18 Thread Laurent PETIT
2010/2/18 Аркадий Рост : > Hi! > I don't understand difference between commute and alter. In fact I > don't understand how can I get different results by changing alter to > commute in code.I've read that the in-transaction value with commute > is that it may differ from the post-commit value, as t

Re: commute misunderstanding

2010-02-18 Thread Аркадий Рост
hmm..but in what way I can write code to demonstrate the difference? -- 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

Re: ANN: byte-spec-0.1

2010-02-18 Thread Jeff Rose
Yeah, Overtone is our real focus, but its in rapid development and there is minimal documentation so it hasn't gotten a real release yet. Feel free to mail the Overtone list if you need help getting setup though. -Jeff On Feb 18, 6:50 pm, David Nolen wrote: > Nice, overtone

Re: commute misunderstanding

2010-02-18 Thread Laurent PETIT
2010/2/18 Аркадий Рост : > hmm..but in what way I can write code to demonstrate the difference? You must reproduce the race conditions. An idea is to start 2 transactions in 2 different threads, while making the first one sleep sufficiently so you're sure the second one will commit first. Simply

Clojure box

2010-02-18 Thread Zeynel
Hello, I am totally new to Clojure. Do you recommend using Clojure Box for windows installation? I am not an expert user or programmer. Thank you. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegrou

Re: clojure-contrib on Windows

2010-02-18 Thread Ram
I was considering doing that, but I didn't know if people were aware of the compilation issue on Windows so I posted it. On Feb 17, 9:50 pm, kkw wrote: > Hi Ram, > >     If you all you want is the latest .jar file, and don't feel the > need to compile, consider bypassing the compilation and grab

Re: http-agent usage in subsequent agent action question

2010-02-18 Thread Timothy Pratley
On 18 February 2010 23:12, sim wrote: > I have been using http-agents to grab a bunch of pages and then > process them, my initial solutions involved partitioning a sequence of > urls and then awaiting for that group before moving on. Consider this alternative: (use 'clojure.contrib.duck-streams

Re: Clojure box

2010-02-18 Thread Brian Wolf
Zeynel wrote: Hello, I am totally new to Clojure. Do you recommend using Clojure Box for windows installation? I am not an expert user or programmer. Thank you. I use it all the time. And its a gentle introduction to emacs Brian -- You received this message because you are subscribed to

Re: newbie question: Please help me stop creating constructors

2010-02-18 Thread John Williams
I'm no Clojure guru myself, but one approach you may want to consider is nest all your auxiliary functions inside the main function, and use ordinary let-bindings the same way you've been trying to use global bindings: (defn sell-or-rent [{:keys [supplied-1 supplied-2]}] (let [derived-1 (+ 1 sup

Re: http-agent usage in subsequent agent action question

2010-02-18 Thread sim
Yes there are other alternatives, but consider this. (doseq [url urls] (let [agt (http-agent url)] (send-off agt some-action))) I think that some-action should be able to use string and result as the HTTP request is complete at this stage. However some-action can't as both string and resul

Re: http-agent usage in subsequent agent action question

2010-02-18 Thread Timothy Pratley
On 19 February 2010 13:35, sim wrote: > Yes there are other alternatives, but consider this. > > (doseq [url urls] >  (let [agt (http-agent url)] >    (send-off agt some-action))) Ok I understand better where you are coming from now... you want some-action to occur after http-agent tasks have run

Common Lisp's append

2010-02-18 Thread Mike K
Hey Clojurians, I'm a Clojure and Common Lisp newbie. I heard that Norvig's PAIP was a good book to study idiomatic CL code, so I've embarked on a project to translate the examples to / work the exercises in Clojure. I hope to complete this project before the end of this century :-) Regarding "a

Re: Common Lisp's append

2010-02-18 Thread Timothy Pratley
On 19 February 2010 15:18, Mike K wrote: > Hey Clojurians, > > I'm a Clojure and Common Lisp newbie. I heard that Norvig's PAIP was a > good book to study idiomatic CL code, so I've embarked on a project to > translate the examples to / work the exercises in Clojure.  I hope to > complete this pro

noobie library load

2010-02-18 Thread Brian Wolf
Hi, I have a self contained library let me call it "http_example.jar" (i assume the name of the jar file is irrelevant) and contains this is the root resource: com.example.clojure.http__init.class (I know its there) The file, "http_example.jar", to the best I can tell sits squarely in my cl

Re: Clojure box

2010-02-18 Thread Sean Devlin
Do you need to do a lot of Java work as well? If so, take a look at Enclojure (Netbeans) or Counter Clockwise (Eclipse). On Feb 18, 4:58 pm, Zeynel wrote: > Hello, > > I am totally new to Clojure. Do you recommend using Clojure Box for > windows installation? I am not an expert user or programme

Re: newbie question: Please help me stop creating constructors

2010-02-18 Thread Yaron
Way back when I was a wee lad I had been taught that a thunk is any function that takes no arguments. My definition for my derived values never took any arguments because they exclusively relied on global variables. For example: (defn months_actively_renting "The number of months during t

Re: noobie library load

2010-02-18 Thread Meikel Brandmeyer
Hi, On Feb 19, 5:26 am, Brian Wolf wrote: > I have a self contained library let me call it "http_example.jar" (i > assume the name of the jar file is irrelevant) > > and contains this is the root resource: > > com.example.clojure.http__init.class (I know its there) The file should be called com

Re: newbie question: Please help me stop creating constructors

2010-02-18 Thread Yaron
I spent a bunch of time reading and re-reading your mails. Michal Marczyk's mail (which I read every line of, thank you for taking the time to write it) was the one that made me get what Richard Newman has with utmost patience (THANK YOU!), I believe, been trying to gently beat into my head fr

Clojure function varargs (not Java interop varargs)

2010-02-18 Thread Julien
Dear Clojurists, Two questions: Question #1 I want to write a vararg function that does something like this: (map vector [1 2 3] [4 5 6]) which yields ([1 4] [2 5] [3 6]) I try to capture this as a function: (defn rotate[& x] (map vector x)) but (rotate [1 2 3] [4 5 6]) yields ([[1 2 3]]

Re: Clojure function varargs (not Java interop varargs)

2010-02-18 Thread Timothy Pratley
On 19 February 2010 18:04, Julien wrote: > Question #1 > > I want to write a vararg function that does something like this: > > (map vector [1 2 3] [4 5 6]) > which yields > ([1 4] [2 5] [3 6]) > > I try to capture this as a function: > > (defn rotate[& x] (map vector x)) > > but > > (rotate [1 2

Re: newbie question: Please help me stop creating constructors

2010-02-18 Thread Richard Newman
Richard Newman has with utmost patience (THANK YOU!), I believe, been trying to gently beat into my head from the start. No problem. Happy to help. Richard, your mails were extremely clear (and at this point I've read them all at least 2 or 3 times) but my head was so far away from the pr