Re: function to perform operations on adjacent values

2010-01-21 Thread Michael Wood
2010/1/21 Chris Kent : > partition creates a sequence of sequences of adjacent values > > user=> (partition 2 (range 1 7)) > ((1 2) (3 4) (5 6)) > > and you can apply reduce to each of the sequences using map > > user=> (map #(reduce + %) (partition 2 (range 1 7))) > (3 7 11) > > or > > user=> (map

Re: Dependency management

2010-01-21 Thread Richard Newman
How do people deal with this? How can one simultaneously use two libraries which have hardwired dependencies on two different Clojure versions, each of which might be mutually incompatible? What's the community protocol around locally installing Clojure 1.2, and adding that as a dependency for a

Re: Dependency management

2010-01-21 Thread Phil Hagelberg
Richard Newman writes: > Adjusting the lein script to use my local Clojure install gave me a > great error: > > Caused by: java.lang.NoSuchMethodError: clojure.lang.RestFn.(I)V > > How do people deal with this? How can one simultaneously use two > libraries which have hardwired dependencies on tw

Re: What's the best way to do this?

2010-01-21 Thread David Nolen
Oops you're right :) And better written as well :D On Fri, Jan 22, 2010 at 1:26 AM, Richard Newman wrote: > I agree, one possible improvement would be short circuiting on the first >> false pred. >> > > every? does short-circuit. > > user=> (every? #(% 5) > (list >

Re: What's the best way to do this?

2010-01-21 Thread Richard Newman
I agree, one possible improvement would be short circuiting on the first false pred. every? does short-circuit. user=> (every? #(% 5) (list (fn [a] (println "First a: " a) false) (fn [a] (println "Second a: " a) true))) First a: 5 false -- Yo

Re: Dependency management

2010-01-21 Thread Richard Newman
We're not all jumping on Leiningen, some of us are sticking with maven, using the maven-clojure-compiler plugin, and also the experimental Maven Polyglot Clojure build support: It's not the "Leiningen" that's important, it's the "jumping": away from Ant, not Maven. Every library I use had an A

Re: What's the best way to do this?

2010-01-21 Thread David Nolen
I agree, one possible improvement would be short circuiting on the first false pred. (defn combine-preds [pred & others] (fn [v] (loop [result true pred pred others others] (if (not result) result (if (nil? pred) result (recur (pred v) (first others)

Re: Dependency management

2010-01-21 Thread Mark Derricutt
We're not all jumping on Leiningen, some of us are sticking with maven, using the maven-clojure-compiler plugin, and also the experimental Maven Polyglot Clojure build support: http://polyglot.sonatype.org/clojure.html (disclojure - both of these are my projects so I'm somewhat biased) -- Pu

Re: Debugging in Clojure

2010-01-21 Thread David Nolen
I find that injecting print statements is painful if you're not using something like paredit (Emacs). With paredit it's quite simple. On Thu, Jan 21, 2010 at 8:27 PM, ajay gopalakrishnan wrote: > Is this the preferred way of debugging in Clojure? > > > On Thu, Jan 21, 2010 at 5:25 PM, Richard New

Parallel activities

2010-01-21 Thread tsuraan
What is the clojure idiom for running multiple (in this case IO bound) functions simultaneously? My use case is the parallel activities are coordinated, basically running in lockstep. I've been using (.start (Thread. myfn)). It works, but I'm wondering if there's a better way. The data shared b

Re: Dependency management

2010-01-21 Thread wlr
On Jan 21, 8:37 pm, Sean Devlin wrote: > Clojure stresses immutability, and dependencies should be no > different.  I'd say it's bad form to force a dependency on an > unreleased version of Clojure, because it's a moving target.  Granted, BTW, Clojure also stresses *controlled mutability*. I'd

Proposal: New fn assoc-in-with

2010-01-21 Thread Sean Devlin
Sometimes you don't want assoc-in to create a hash-map. Sometimes you wish it could create a sorted map. Just finished working on something with Alexy Khrabrov & Chouser on IRC, and the three of us are wondering if the result might be generally useful. (defn assoc-in-with "supply a default-map

Re: Debugging in Clojure

2010-01-21 Thread ataggart
Logging side-effects usually occur within a do block, or the equivalent, e.g., when, catch. For production code, I'd suggest a logging library instead of filling your code with printlns. Contrib has a logging lib that delegates to common java logging libraries, but allows for writing them in a mo

Re: Debugging in Clojure

2010-01-21 Thread .Bill Smith
I don't know about *the* preferred way, but it's my preferred way. It's a no-brainer to add print statements. I believe there is at least one logging library available too. On Jan 21, 7:27 pm, ajay gopalakrishnan wrote: > Is this the preferred way of debugging in Clojure? > > On Thu, Jan 21, 201

Re: Dependency management

2010-01-21 Thread Sean Devlin
> What's the community protocol around locally installing Clojure 1.2,   > and adding that as a dependency for a published library? I'll take a shot at this question. Clojure stresses immutability, and dependencies should be no different. I'd say it's bad form to force a dependency on an unrelea

Re: Debugging in Clojure

2010-01-21 Thread ajay gopalakrishnan
Is this the preferred way of debugging in Clojure? On Thu, Jan 21, 2010 at 5:25 PM, Richard Newman wrote: > I usually debug by adding println statements. How can I achieve the same >> effect in Clojure. I don't think I can introduce println at arbitrary places >> to figure out at which step is t

Re: Debugging in Clojure

2010-01-21 Thread Richard Newman
I usually debug by adding println statements. How can I achieve the same effect in Clojure. I don't think I can introduce println at arbitrary places to figure out at which step is the algorithm failing. Sure you can. You might need to add a (do ) block if you're wanting to add them in an (

Dependency management

2010-01-21 Thread Richard Newman
Hi folks, Apparently everyone is jumping on the Leiningen bandwagon and deleting their build.xml files. I guess that means I'm moving, too. Now, I like to keep track of Clojure master. Right now, Clojure reports "Clojure 1.2.0-master-SNAPSHOT". (I don't see that in Maven Central or in Clo

Debugging in Clojure

2010-01-21 Thread ajay gopalakrishnan
Hi, I usually debug by adding println statements. How can I achieve the same effect in Clojure. I don't think I can introduce println at arbitrary places to figure out at which step is the algorithm failing. Thanks, Ajay -- You received this message because you are subscribed to the Google Grou

loss-free print/read

2010-01-21 Thread dodo
Hello, Is there a way to do a loss free print/read loop in clojure?! I know that data structures like maps, vectors, .. maybe printed and read without the loss of information but it does not work for functions. Does clojure provide a the possibility to retrieve the data structure that represents

Re: Replacing " with \" in a string.

2010-01-21 Thread j DeSeno
You have your arguments out of order, try: (= (.replaceAll "a" "\"" "\\\"") (.replaceAll "\\a" "\"" "\\\"")) On Thu, Jan 21, 2010 at 2:40 PM, CuppoJava wrote: > Hi, > I'm trying to write a simple function to replace every " inside the > string with \", but am having an extremely difficult ti

Re: Replacing " with \" in a string.

2010-01-21 Thread Sean Devlin
Your second "\\a" should probably be "\"a". On Jan 21, 5:40 pm, CuppoJava wrote: > Hi, > I'm trying to write a simple function to replace every " inside the > string with \", but am having an extremely difficult time. > > Can someone enlighten me as to why the following is returning true? > > (=

Replacing " with \" in a string.

2010-01-21 Thread CuppoJava
Hi, I'm trying to write a simple function to replace every " inside the string with \", but am having an extremely difficult time. Can someone enlighten me as to why the following is returning true? (= (.replaceAll "\"" "\\\"" "a") (.replaceAll "\"" "\\\"" "\\a")) Thanks a lot -Patrick --

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread Heinz N. Gies
On Jan 21, 2010, at 19:08 , CuppoJava wrote: > The last point that interested me was: I heard someone mention that > applications written using the Apple Java-Cocoa bridge was also > noticeably less responsive than native applications in Objective-C, > that person said it's because of java's GC th

Re: What's the best way to do this?

2010-01-21 Thread Sean Devlin
Not as a macro I hope. You lose apply. On Jan 21, 3:49 pm, Richard Newman wrote: > > I think it's easier to think about combining predicates separately > > from your file-filtering code. I'd use a higher-order function like > > the following > > >  (defn combine-preds > >    [& preds] > >    (fn

Re: What's the best way to do this?

2010-01-21 Thread Richard Newman
I think it's easier to think about combining predicates separately from your file-filtering code. I'd use a higher-order function like the following (defn combine-preds [& preds] (fn [& args] (every? #(apply % args) preds))) I've noticed that most uses of this kind of thing are for fixed

Re: What's the best way to do this?

2010-01-21 Thread Sean Devlin
I agree with Perry. I've found I have to write two versions of combine-preds often (defn every-pred? "Mimics AND" [& preds] (fn [& args] (every? #(apply % args) preds))) (defn any-pred? "Mimics OR" [& preds] (fn [& args] (some #(apply % args) preds))) They're very handy,

Re: What's the best way to do this?

2010-01-21 Thread Perry Trolard
I think it's easier to think about combining predicates separately from your file-filtering code. I'd use a higher-order function like the following (defn combine-preds [& preds] (fn [& args] (every? #(apply % args) preds))) then filter files like (filter (combine-preds pred1 pred2)

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread Raoul Duke
> Often you will also get better behavior by using appropriate -Xms/-Xmx > options. The above are just examples of course and not "the" way to do > it or anything. i would like a JVM that has a "hot spot jit" for GC tweaking. -- You received this message because you are subscribed to the Google G

Re: What's the best way to do this?

2010-01-21 Thread nwalex
Brilliant. Thanks Dan, that did the trick. On Jan 21, 8:01 pm, Dan Schmidt wrote: > I don't know how efficient it is (or how idiomatic it really is), but > this should work: > > (defn find-files >  "Find files in directory that match predicates pred & others" >  [in-dir pred & others] >  (reduce

Re: What's the best way to do this?

2010-01-21 Thread Dan Schmidt
I don't know how efficient it is (or how idiomatic it really is), but this should work: (defn find-files "Find files in directory that match predicates pred & others" [in-dir pred & others] (reduce (fn [xs f] (filter f xs)) (file-seq in-dir) (cons pred others))) Dan On Thu, Jan 21, 2010 at 2:

Re: What's the best way to do this?

2010-01-21 Thread Sean Devlin
I'm not quite sure what you're getting at. Maybe split-with will do what you want? http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/split-with On Jan 21, 2:47 pm, nwalex wrote: > I'm very new to Clojure, and to functional programming in general. Can > anyone tell me the i

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread Peter Schuller
> It seems the consensus is that the slow responsiveness of Java apps is > mostly due to an issue with Swing and how it is used rather than with > garbage collection. That sounds very encouraging. Determining whether the GC is responsible is pretty easy. Just runt with -verbose:gc (or -XX:+PrintGC

What's the best way to do this?

2010-01-21 Thread nwalex
I'm very new to Clojure, and to functional programming in general. Can anyone tell me the idiomatic way to implement this function? (defn find-files "Find files in directory that match predicates pred & others" [in-dir pred & others] (filter pred (file-seq in-dir))) What is the best way to

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread CuppoJava
Thanks for the responses. It seems the consensus is that the slow responsiveness of Java apps is mostly due to an issue with Swing and how it is used rather than with garbage collection. That sounds very encouraging. The last point that interested me was: I heard someone mention that applications

Re: Autodoc for the masses

2010-01-21 Thread Jeff Rose
Just a quick note about getting setup with Leiningen. The documentation you posted says to use [autodoc "0.7.0-SNAPSHOT"] in the dev dependencies, but that is not a valid package on clojars. Using [autodoc "0.7.0"] instead works fine though. No downloading of jars necessary. Just add that, run

Agents of Swing ported to Jwt

2010-01-21 Thread rb
Hi, After reading Stuart Sierra's post titled "Agents of Swing" [1] I couldn't wait to try and port it to Jwt [2]. I finally had the time and documented it in a blog post at http://www.nsa.be/index.php/eng/Blog/From-Swing-to-Jwt I thought this could be of interest to some people here, expecially

Re: Suggest slime-redirect-inferior-output be default for Swank clojure

2010-01-21 Thread Chris Jenkins
Seconded. I found this very confusing when I first started with Clojure. 2010/1/21 Alex Stoddard > Hello, > > As detailed in Bradford Cross' blog, (http:// > measuringmeasures.blogspot.com/2010/01/agony-of-clojurehadoop-logging- > and-how.html) the rebinding of *out* done in the swank/slime repl

Re: function to perform operations on adjacent values

2010-01-21 Thread Scott
Thanks! On Jan 21, 7:07 am, Meikel Brandmeyer wrote: > Hi, > > On Jan 20, 8:03 pm, Scott wrote: > > > (reduce-n + (range 7)  2) > > => (3 7 11) > > user=> (map #(reduce + %1) (partition 2 (range 1 7))) > (3 7 11) > > Sincerely > Meikel -- You received this message because you are subscribed to

ANN: leiningen war plugin

2010-01-21 Thread Saul Hazledine
There is a plugin for leiningen that creates war files for use with servlet containers: http://github.com/alienscience/leiningen-war/ http://clojars.org/uk.org.alienscience/leiningen-war To use it include the following dev-dependency in project.clj :dev-dependencies [[uk.org.alienscience/leining

Suggest slime-redirect-inferior-output be default for Swank clojure

2010-01-21 Thread Alex Stoddard
Hello, As detailed in Bradford Cross' blog, (http:// measuringmeasures.blogspot.com/2010/01/agony-of-clojurehadoop-logging- and-how.html) the rebinding of *out* done in the swank/slime repl can be very confusing to folk who don't already know slime. This is because so many java libraries output to

Re: Promise/Deliver use cases

2010-01-21 Thread Sean Devlin
Promises (and dataflow programming in general) are really useful with interacting with physical devices, especially robots. Suppose you have a 200 ton press, with a safety sensor. You have the following code: (def is-it-safe? (promise)) (defn activate-press [] (if @is-it-safe? (go!))) (d

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread Stuart Sierra
On Jan 21, 3:20 am, Joonas Pulakka wrote: > In general, accusing garbage collection of being culprit for sluggish > GUI performance is plain wrong. Swing GUIs can be quite snappy when > done right - but surely there are lots of not-so-right done apps out > there. >From my limited experience with

Re: Autodoc for the masses

2010-01-21 Thread Sean Devlin
Tom, Thanks for providing this great tool. I was able to install it last night, it just plain works. Keep hacking! Sean On Jan 20, 12:51 pm, Tom Faulhaber wrote: > Now your project can have the same documentation as Clojure, clojure- > contrib, and Incanter! > > The standalone autodoc tool is n

Using docs effectively (Ratio)

2010-01-21 Thread Jacek Generowicz
Clojure has a Ratio type; presumably there should be an easy way to find the numerator and denominator of a Ratio object. I didn't have much luck on clojure.org or with find-doc, but (show 1/2) taught me that there are numerator and denominator methods on Ratio's underlying Java implementati

Re: Case-insensitive map?

2010-01-21 Thread C. Florian Ebeling
> I think you misread the source of fnmap. Of course it creates a new > map in the beginning just as hash-map does. Then assoc/dissoc/etc. > just delegates to the underlying map with the appropriate fiddling > with the setter/getter. > > If you already have a map you can do something like: > > (req

Re: update-in! (?)

2010-01-21 Thread Gabi
I don't think zipper would help in this case On Jan 21, 12:40 am, brianh wrote: > Any chance you could rethink your approach & use a zipper? > > On Jan 20, 9:32 am, Gabi wrote: > > > I posted a question on SO about it. Interesting > > discussion:http://stackoverflow.com/questions/2102606/algori

Re: Case-insensitive map?

2010-01-21 Thread Meikel Brandmeyer
Hi, On Jan 21, 11:01 am, "C. Florian Ebeling" wrote: > This is actually a very cool approach and it fits my ideas quite well. > The only problem I have with it is that it constructs a whole new map > from keyvals. Maybe it is possible do something similar which just wraps > over an existing map.

Re: function to perform operations on adjacent values

2010-01-21 Thread Meikel Brandmeyer
Hi, On Jan 20, 8:03 pm, Scott wrote: > (reduce-n + (range 7)  2) > => (3 7 11) user=> (map #(reduce + %1) (partition 2 (range 1 7))) (3 7 11) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clo

Re: Eval troubles

2010-01-21 Thread Meikel Brandmeyer
Hi, On Jan 20, 11:10 pm, Bryce wrote: > What am I missing? Try ` instead of '. eval evaluates the expression with a different ns. Since y is not properly quoted it is not found. ` will resolve y to its qualified name and everything will work out. Standard Disclaimer: this is only one subtle go

Re: Eval troubles

2010-01-21 Thread kreso
Hi, > (defn y [a b] (+ a b)) > (def x '(y 1 2)) > > (defn -main [] >   (println (eval x))) > > which yields > > "Unable to resolve symbol: y in this context (NO_SOURCE_FILE:7)" > etc. > What am I missing? The problem is namespace inside the function used by gen-class (and it this case your -main

Re: function to perform operations on adjacent values

2010-01-21 Thread Chris Kent
partition creates a sequence of sequences of adjacent values user=> (partition 2 (range 1 7)) ((1 2) (3 4) (5 6)) and you can apply reduce to each of the sequences using map user=> (map #(reduce + %) (partition 2 (range 1 7))) (3 7 11) or user=> (map (partial reduce + ) (partition 2 (range 1 7

Re: function to perform operations on adjacent values

2010-01-21 Thread Konrad Hinsen
On 20.01.2010, at 20:03, Scott wrote: looking for something very similar to reduce, but sequentially operate on adjacent values for example if (defn reduce-n [f col n]) (reduce-n + (range 7) 2) => (3 7 11) ie 1+2, 3+4, 5+6 ideas? That's (range 1 7) instead of (range 7), right? In that ca

Re: Multimethod attribute maps

2010-01-21 Thread RandyHudson
The attr-map adds key-value pairs to the metadata for the function symbol. The doc for 'defn' makes this clearer. On Jan 20, 8:02 am, Jacek Generowicz wrote: > In Clojure 1.1.0, the documentation states: > > clojure.core/defmulti > ([name docstring? attr-map? dispatch-fn & options]) > Macro >   C

Re: Multimethod attribute maps

2010-01-21 Thread Jacek Generowicz
On Jan 20, 1:02 pm, Jacek Generowicz wrote: > clojure.core/defmulti > ([name docstring? attr-map? dispatch-fn & options]) > What is the purpose of the attribute map [...] ? Answering my own question: It's not specific to multimethods. It's the metadata, and most def- forms have such an optional

Eval troubles

2010-01-21 Thread Bryce
I'm a clojure newbie, but bear with me; I'm trying to save an expression that contains a function I've defined earlier, and then selectively evaluate it later. (The idea is that I will swap out the function later in the code). Something like (defn y [a b] (+ a b)) (def x '(y 1 2)) (defn -main [

Re: Multimethod attribute maps

2010-01-21 Thread Meikel Brandmeyer
Hi, Am 20.01.2010 um 14:02 schrieb Jacek Generowicz: > In Clojure 1.1.0, the documentation states: > > clojure.core/defmulti > ([name docstring? attr-map? dispatch-fn & options]) > Macro > Creates a new multimethod with the associated dispatch function. > The docstring and attribute-map are op

function to perform operations on adjacent values

2010-01-21 Thread Scott
looking for something very similar to reduce, but sequentially operate on adjacent values for example if (defn reduce-n [f col n]) (reduce-n + (range 7) 2) => (3 7 11) ie 1+2, 3+4, 5+6 ideas? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To pos

Re: Autodoc for the masses

2010-01-21 Thread Rich Hickey
On Wed, Jan 20, 2010 at 12:51 PM, Tom Faulhaber wrote: > Now your project can have the same documentation as Clojure, clojure- > contrib, and Incanter! > > The standalone autodoc tool is now available. It can be run from the > command line and it integrates with Leiningen and ant. (Maven still to

Re: Promise/Deliver use cases

2010-01-21 Thread Laurent PETIT
In a nutshell, those are the building blocks for the "dataflow programming paradigm". It's an easy way to make a computation done in thread A (and using a pre-declared promise) block until thread B has delivered the promise (given it its value). The book CTM covers dataflow programming : http://w

Promise/Deliver use cases

2010-01-21 Thread Baishampayan Ghose
Hello, I am trying to understand the use-cases of the new promise/deliver feature in Clojure. I have tried using them, and they seem to be pretty straight-forward to use, but unfortunately I haven't been able to understand its use-cases. It would be great if someone pointed out some example usage

Re: Case-insensitive map?

2010-01-21 Thread C. Florian Ebeling
> There's a library in clojure.contrib which allows to create your own > getters / setters for maps : > > http://richhickey.github.com/clojure-contrib/fnmap-api.html This is actually a very cool approach and it fits my ideas quite well. The only problem I have with it is that it constructs a whole

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread Joonas Pulakka
In general, accusing garbage collection of being culprit for sluggish GUI performance is plain wrong. Swing GUIs can be quite snappy when done right - but surely there are lots of not-so-right done apps out there. Also, the amount of GC required depends a lot on what you're doing, and how. Typical