Re: Jython Interoperability problem

2010-11-08 Thread Dilvan
Hi, Thanks a lot for your reply. I thought Java interoperability was one of the key points for Clojure a language for the JVM, having a pure Clojure version that limits interoperability in the JVM isn't quite in this spirit. The first project (clj-ds) seems quite what I need now, but I

Re: clojure-contrib 1.3.0-alpha3 deployed to build.clojure.org

2010-11-08 Thread Stuart Sierra
Hi Sean, Not sure I understand the question. If you're designing a library, you probably want to test on both. -S On Nov 7, 3:57 pm, Sean Corfield seancorfi...@gmail.com wrote: Thanx Stuart! As a general point of protocol, would the Clojure team prefer folks test against the Alpha builds

Re: Python is way faster than Clojure on this task

2010-11-08 Thread Gijs S.
Indeed I was not using the transients correctly. Transients are not designed to be bashed in-place. (http://clojure.org/transients) The gist is updated with a version that first worked without the transients and then had the transient operations added. (https:// gist.github.com/666228) The times

Re: Macro help

2010-11-08 Thread Sunil S Nandihalli
Hi Miki, Just to elaborate on what I said before, session# creates a new symbol using gensym with a prefix session. It avoids accidental variable capture. Sunil. On Mon, Nov 8, 2010 at 8:40 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: use session# instead of session .. I think

Re: Macro help

2010-11-08 Thread Alan
This. Macros, unless you do some gymnastics, always generate fully- qualified names, which is a Good Thing. You can't bind qnames, in let or function arguments or anywhere else. But clojure provides you with a very useful var# syntax: this creates a new symbol which is guaranteed to be unique, and

Re: Macro help

2010-11-08 Thread Miki
As in the below (which doesn't work). (defmacro def-dispatcher-test [test-name state command body] `(deftest ~test-name (let [session (test-session ~state)] (dispatcher ~command session) ~...@body))) (def-dispatcher-test user-test :authorization USER bugs (is (= (:user

Error in 1.3 alpha 3 - Only long and double primitives are supported

2010-11-08 Thread Mike Anderson
Hi all, I was testing some code under Clojure 1.3 alpha 3 that works correctly in Clojure 1.2 and got the following error: CompilerException java.lang.IllegalArgumentException: Only long and double primitives are supported For some reason I don't get a full stack trace saying where the error

Re: Error in 1.3 alpha 3 - Only long and double primitives are supported

2010-11-08 Thread Eric Lavigne
Also - I'm a bit worried as the message suggests that Clojure won't support int and float primitives for some purposes - which are pretty essential for Java interop - surely that can't be true? Or is this just a temporary thing during the Alpha development? longs and doubles will be the

Re: Macro help

2010-11-08 Thread Laurent PETIT
Hi, session will be fully qualified. this is the default behavior. If you really want it, then you can treat it as the result of the unquoting of a value which resolves to a symbol. So you'll use ~ to say you want the value of (quote session) (quote session returns the symbol session when

Re: Error in 1.3 alpha 3 - Only long and double primitives are supported

2010-11-08 Thread lprefontaine
Sticking to long and double gets away from Java semantic but it is done to improve numeric performances. You can actually hint in 1,3 on the return type of a function to avoid automatic boxing and have your code work entirely with a native type. Boxing if I recall correctly will convert

Re: Macro help

2010-11-08 Thread Ken Wesson
On Mon, Nov 8, 2010 at 2:01 PM, Laurent PETIT laurent.pe...@gmail.com wrote: Hi, session will be fully qualified. this is the default behavior. If you really want it, then you can treat it as the result of the unquoting of a value which resolves to a symbol. So you'll use ~ to say you want

Re: Macro help

2010-11-08 Thread Miki
Great, that did it. Thanks. On Nov 8, 11:01 am, Laurent PETIT laurent.pe...@gmail.com wrote: Hi, session will be fully qualified. this is the default behavior. If you really want it, then you can treat it as the result of the unquoting of a value which resolves to a symbol. So you'll use ~

Re: Macro help

2010-11-08 Thread Miki
that is, use ~'session instead of just session. What you really want in this case is a binding. Try this: ... The added parameter just before the body specifies a name to bind the session object to; this name can then be used in the body. This is good a well, but I prefer to dark magic

Re: Macro help

2010-11-08 Thread Alan
Yes, those are the two choices. Ken's suggestion is the cleanest, and you definitely should do that in cases where it's not burdensome. Here, where it's a macro for private testing, and you are certain not to forget that it's magically binding session for you, then go ahead and use Laurent's

Re: Python is way faster than Clojure on this task

2010-11-08 Thread Benny Tsai
I played with this some more, and it seems like for accessing an element in a vector, (v idx) is a bit faster than (nth v idx). If you replace this line (line 52 in the gist)... fl (nth freq-layer layer)] with: fl (freq-layer layer)] ...the total time needed to compute frequencies for all 92

How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
So... I tried, and failed, to use transients properly. The function below, new-gen, takes a sequence of nodes and creates a new generation of nodes out of them using the functions transform-left and transform-right. Each node in the sequence has two children, one is created with

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Laurent PETIT
2010/11/8 Greg g...@kinostudios.com So... I tried, and failed, to use transients properly. It's also, somehow, a fail of using clojure datastructures functionally. I mean, transients must be used as you would used their persistent counterparts. Generally, you would first write the code without

Re: clojure-contrib 1.3.0-alpha3 deployed to build.clojure.org

2010-11-08 Thread Sean Corfield
On Mon, Nov 8, 2010 at 5:45 AM, Stuart Sierra the.stuart.sie...@gmail.com wrote: Not sure I understand the question.  If you're designing a library, you probably want to test on both. I meant more from the point of view of providing feedback to the Clojure team. If someone is comfortable

Re: Macro help

2010-11-08 Thread Laurent PETIT
2010/11/8 Alan a...@malloys.org Yes, those are the two choices. Ken's suggestion is the cleanest, and you definitely should do that in cases where it's not burdensome. Here, where it's a macro for private testing, and you are certain not to forget that it's magically binding session for you,

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Paul Mooser
One thing you could do is to use loop and recur as your looping construct - every time you enter into the loop, your variable will be re-bound to the value you used in recur - in this fashion, you can avoid bashing the transient in place. On Nov 8, 1:45 pm, Greg g...@kinostudios.com wrote: So...

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 2:45 PM, Paul Mooser wrote: One thing you could do is to use loop and recur as your looping construct - every time you enter into the loop, your variable will be re-bound to the value you used in recur - in this fashion, you can avoid bashing the transient in place. Yes, I

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 1:59 PM, Laurent PETIT wrote: I would invite you to try write your code with predicate-based hofs such as iterate-while, filter, remove, reduce, map, etc. I did attempt this, but the algorithm doesn't seem to lend itself nicely to this approach, which is why I was hoping

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Ken Wesson
(defn new-gen [a] (loop [a a t (transient [])] (if (empty? a) (distinct #(= (:val %1) (:val %2)) (persistent! t)) (let [f (first a)] (recur (rest a) (loop [c [(transform-left f) (transform-right f)] t t] (if (empty? c) t

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Ken Wesson
(defn new-gen [a] (distinct #(= (:val %1) (:val %2)) (for [f a n [(transform-left f) (transform-right f)] :when (not (contains? #(= (:val n) %) (map :val (parents n] n))) is more functional but possibly slower. If you really just want the first one in

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Meikel Brandmeyer
Yeah, golfing at late night.. (defn distinct-by [keyfn coll] (let [step (fn step [xs seen] (lazy-seq ((fn [[f :as xs] seen] (when-let [s (seq xs)] (if (contains? seen (keyfn f))

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Meikel Brandmeyer
Hi again, Am 09.11.2010 um 00:24 schrieb Meikel Brandmeyer: (defn new-gen [a] (- a (mapcat (juxt transform-left transform-right)) (remove (fn [n] (some #(= (:val n) (:val %)) (parents n (distinct-by :val))) Maybe you also want to exchange the distinct-by and remove.

Re: Python is way faster than Clojure on this task

2010-11-08 Thread Gijs S.
I also get consistent better times with (freq-layer layer) vs. (nth freq-layer layer). Gist updated: https://gist.github.com/666228 -Gijs -- 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

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Laurent PETIT
out of curiosity, if 2 siblings have the same value for their :value attribute, you just keep the first one you encounter, and throw away the others with the same :value attribute ? Is it because they also have the same attributes altogether, or because you're relying on an importance criteria

Re: could clojure be androids joker card

2010-11-08 Thread Nick Brown
One problem I've heard with creating Android apps in languages such as Clojure or Scala is the dependencies (in Clojure's case, probably clojure.jar and clojure-contrib.jar) that are brought in increase the size of the app. Those dependencies may be very small when deployed as a server app or on

Re: could clojure be androids joker card

2010-11-08 Thread Aaron Bedra
There are several forces at play here that work against clojure on android being a huge force. The size of hello world in clojure is currently 4.21MB. This is roughly 4 for clojure and .21 for the app. This is compared to the same app in java at .2MB. Bring in c.c and you have a whole lot

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
(Thanks everyone for all the replies! I'll address each response individually). Awesome, thanks Ken! This solution is really cool, and it is what I was attempting to go for but my inexperience with this sort of functional style prevented me from seeing it. Of the solutions presented though, I

Re: Macro help

2010-11-08 Thread Alan
Yeah, I know you wouldn't make such a dreadful recommendation without prompting. I just want to make sure *he* knows that this is considered a little smelly: Clojure gives you the power to do stuff like this, and it's appropriate to use it sometimes, but you should be careful - it's hard for a

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 3:11 PM, Ken Wesson wrote: (defn new-gen [a] (distinct #(= (:val %1) (:val %2)) (for [f a n [(transform-left f) (transform-right f)] :when (not (contains? #(= (:val n) %) (map :val (parents n] n))) is more functional but possibly slower.

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
Thanks Meikel! This is a really neat way of writing it, I'm going to need to study this one as it uses some functions I'm not super familiar with (so thanks very much for introducing me to them and coming up with this elegant example!). The only thing is that while your distinct-by function

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 3:37 PM, Laurent PETIT wrote: out of curiosity, if 2 siblings have the same value for their :value attribute, you just keep the first one you encounter, and throw away the others with the same :value attribute ? Yes. Is it because they also have the same attributes

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Ken Wesson
On Mon, Nov 8, 2010 at 8:34 PM, Greg g...@kinostudios.com wrote: On Nov 8, 2010, at 3:11 PM, Ken Wesson wrote: (defn new-gen [a]  (distinct #(= (:val %1) (:val %2))    (for [f a          n [(transform-left f) (transform-right f)]          :when (not (contains? #(= (:val n) %) (map :val

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Ken Wesson
On Mon, Nov 8, 2010 at 8:55 PM, Greg g...@kinostudios.com wrote: I'm currently in the process of learning Clojure, and as an ex cerise Did you mean exercise? An ex cerise would be something that used to be a cherry. :) The gears are initially set to 3,3,3. Pull the right lever and the top two

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 6:04 PM, Ken Wesson wrote: On Mon, Nov 8, 2010 at 8:55 PM, Greg g...@kinostudios.com wrote: I'm currently in the process of learning Clojure, and as an ex cerise Did you mean exercise? An ex cerise would be something that used to be a cherry. :) Hehehe... Yes... that was

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Ken Wesson
On Mon, Nov 8, 2010 at 9:08 PM, Greg g...@kinostudios.com wrote: Ah, I see that this wasn't immediately clear from my explanation: they change by 1, but 3 wraps to 1. I.e. the chain is:        3 = 1 = 2 = 3 = 1 = etc... I assume only the first two and last two can be changed together. If the

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 6:29 PM, Ken Wesson wrote: On Mon, Nov 8, 2010 at 9:08 PM, Greg g...@kinostudios.com wrote: Ah, I see that this wasn't immediately clear from my explanation: they change by 1, but 3 wraps to 1. I.e. the chain is: 3 = 1 = 2 = 3 = 1 = etc... I assume only the

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Greg
On Nov 8, 2010, at 7:49 PM, Greg wrote: So I'm unclear on what 3 (mod 3) means... I may have answered my own question, let me know: 6 = 3 (mod 3) That means that *both* sides are modulo 3, in which case 0 = 0. Whereas, (a + c) = 3 != 2 (mod 3) Makes sense because: 0

Re: IntelliJ IDEA/La Clojure with Clojure 1.2?

2010-11-08 Thread Greg
Hey Shantanu, I mention how to do this here: http://gregslepak.posterous.com/clojure-development-with-intellijs-la-clojure - Greg On Nov 7, 2010, at 12:10 PM, Shantanu Kumar wrote: For now I just went ahead and replaced existing LaClojure/clojure.jar (1.1) with clojure-1.2.0.jar

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Ken Wesson
On Mon, Nov 8, 2010 at 10:58 PM, Greg g...@kinostudios.com wrote: On Nov 8, 2010, at 7:49 PM, Greg wrote: So I'm unclear on what 3 (mod 3) means... I may have answered my own question, let me know:        6 = 3 (mod 3) That means that *both* sides are modulo 3, in which case 0 = 0.

Re: Macro help

2010-11-08 Thread Miki
I just want to make sure *he* knows that this is considered a little smelly: Clojure gives you the power to do stuff like this, and it's appropriate to use it sometimes, but you should be careful - it's hard for a reason. I know it smells, and regularly I won't use such a thing (didn't like

Re: IntelliJ IDEA/La Clojure with Clojure 1.2?

2010-11-08 Thread Shantanu Kumar
Ah, I got it. Thanks! It's surprising how non-intuitive it is though to switch to another Clojure version in La Clojure. Regards, Shantanu On Nov 9, 9:01 am, Greg g...@kinostudios.com wrote: Hey Shantanu, I mention how to do this here:        

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Meikel Brandmeyer
Hi, On 9 Nov., 02:42, Greg g...@kinostudios.com wrote: The only thing is that while your distinct-by function doesn't seem to work... Bleh. :( It *was* late in the night... (defn distinct-by [keyfn coll] (let [step (fn step [xs seen] (lazy-seq ((fn [[f :as xs] seen]

Re: Python is way faster than Clojure on this task

2010-11-08 Thread Meikel Brandmeyer
Hi, On 9 Nov., 00:31, Gijs S. gijsstuur...@gmail.com wrote: I also get consistent better times with (freq-layer layer) vs. (nth freq-layer layer). This is to be expected, because (freq-layer layer) acts directly on the datastructure, while (nth freq-layer layer) goes through another function.

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Rasmus Svensson
2010/11/9 Greg g...@kinostudios.com: I think to answer both questions I should explain the context of this problem. I'm currently in the process of learning Clojure, and as an ex cerise to assist in this endeavor I set about solving a problem presented in the classic game called Myst. One of

ANN: slice (a web library for writing and composing snippets of html, css, and js that are written in Clojure)

2010-11-08 Thread Scott Jaderholm
Slice is an experimental not-production-ready web library for writing and composing snippets of html, css, and js that are written in Clojure. The motivation is that I wanted the html, css, and js for a slice of a webpage to be next to each other in the source, not in three separate files, and

Re: How to rewrite code to avoid bashing transients in-place?

2010-11-08 Thread Rasmus Svensson
For fun, I made my own code for proving your result: https://gist.github.com/668830 (contains? (reachable-states [3 3 3]) [2 2 1]) = false //raek -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to