Re: PATCH: AFn.java, RestFN.java (a better throwArity message)
On Tue, Oct 27, 2009 at 2:33 PM, Emeka emekami...@gmail.com wrote: John, That is why I asked that question because I figured out that the problem has nothing to do with Vector but with #() read macro. I wanted to correct the impression that the problem was from Vector. That was correct. I just wanted to avoid any confusion between the #() read macro and anonymous functions; the read macro is one way of writing an anonymous function but it is not the only way so the two aren't quite interchangeable. --~--~-~--~~~---~--~~ 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-nth
On Tue, Oct 27, 2009 at 9:50 PM, Josh Daghlian daghl...@gmail.com wrote: The docs could use clarification, but it looks like take-nth is doing what's advertised. I don't see anything odd about the behavior of take-nth in regards to indexing: user= (take 10 (take-nth 1 (range 100))) (0 1 2 3 4 5 6 7 8 9) user= (take 10 (take-nth 2 (range 100))) (0 2 4 6 8 10 12 14 16 18) user= (take 10 (take-nth 3 (range 100))) (0 3 6 9 12 15 18 21 24 27) It always starts with the zeroth item and skips ahead however many elements were specified. The second argument is the n in every nth item. (You can think of it as the index of the SECOND item to take, so (take-nth 3 foo) takes index 0 of foo, then index 3, and so on.) Is there ever a case (I can't think of one) where a programmer really wants to feed this function a non-positive n? That is, should take-nth crap out if ( n 1)? Probably. Right now, it just seems to fail to advance through the sequence (interestingly, not just with n=0) so it never terminates. Even with an explicitly finite sequence input: user= (take 10 (take-nth 0 [1 2 3 4 5])) (1 1 1 1 1 1 1 1 1 1) Perhaps it should just return a length-1 sequence of just the first element of the input, for zero, and bomb for negative? Or retain its current behavior for zero and bomb for negative. I'd recommend it just bombing for both. The correct interpretation of taking every zeroth item until the end IS to return an infinite sequence of just the first element (the one at index 0), but it's also perturbing to have an operation that normally produces a no-longer sequence produce an infinite one from a finite one. --~--~-~--~~~---~--~~ 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-nth
On Oct 28, 6:04 pm, John Harrop jharrop...@gmail.com wrote: It always starts with the zeroth item and skips ahead however many elements were specified. The second argument is the n in every nth item. (You can think of it as the index of the SECOND item to take, so (take-nth 3 foo) takes index 0 of foo, then index 3, and so on.) Yes I agree it makes perfect sense, but I don't think the doc string really says that. It is probably just be my obtuseness but attached is a very minor patch which might be more clear. As to what should happen with an argument of 0 or less - I have no idea! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- From 4fb354475629f16065fa68bfa43f0dd5475ee891 Mon Sep 17 00:00:00 2001 From: tpratley timothyprat...@gmail.com Date: Fri, 2 Oct 2009 09:53:30 +1000 Subject: [PATCH] Fixed broken test --- test/clojure/test_clojure/compilation.clj | 10 -- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/clojure/test_clojure/compilation.clj b/test/clojure/test_clojure/compilation.clj index fba781c..1d3a78a 100644 --- a/test/clojure/test_clojure/compilation.clj +++ b/test/clojure/test_clojure/compilation.clj @@ -38,6 +38,12 @@ (deftest test-embedded-constants (testing Embedded constants -(are [t] (eval `(= t ~t/TYPE))) - Boolean Byte Character Double Float Integer Long Short)) +(is (eval `(= Boolean/TYPE ~Boolean/TYPE))) +(is (eval `(= Byte/TYPE ~Byte/TYPE))) +(is (eval `(= Character/TYPE ~Character/TYPE))) +(is (eval `(= Double/TYPE ~Double/TYPE))) +(is (eval `(= Float/TYPE ~Float/TYPE))) +(is (eval `(= Integer/TYPE ~Integer/TYPE))) +(is (eval `(= Long/TYPE ~Long/TYPE))) +(is (eval `(= Short/TYPE ~Short/TYPE) -- 1.6.0.4 From 1da1aef4a80e63e799fd1a569d8185c20e2d0341 Mon Sep 17 00:00:00 2001 From: tpratley timothyprat...@gmail.com Date: Wed, 28 Oct 2009 19:13:08 +1100 Subject: [PATCH] Trivial docstring update to take-nth --- src/clj/clojure/core.clj |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 90e3f76..91f7923 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -2727,7 +2727,7 @@ (.removeAlias (the-ns ns) sym)) (defn take-nth - Returns a lazy seq of every nth item in coll. + Returns a lazy seq of every nth item in coll, starting at the 0th. [n coll] (lazy-seq (when-let [s (seq coll)] -- 1.6.0.4
Re: take-nth
On Wed, Oct 28, 2009 at 4:20 AM, Timothy Pratley timothyprat...@gmail.comwrote: On Oct 28, 6:04 pm, John Harrop jharrop...@gmail.com wrote: It always starts with the zeroth item and skips ahead however many elements were specified. The second argument is the n in every nth item. (You can think of it as the index of the SECOND item to take, so (take-nth 3 foo) takes index 0 of foo, then index 3, and so on.) Yes I agree it makes perfect sense, but I don't think the doc string really says that. They probably thought it didn't need to, because the function name does say that. :) --~--~-~--~~~---~--~~ 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: PATCH: AFn.java, RestFN.java (a better throwArity message)
Hi, On Oct 28, 7:56 am, John Harrop jharrop...@gmail.com wrote: That was correct. I just wanted to avoid any confusion between the #() read macro and anonymous functions; the read macro is one way of writing an anonymous function but it is not the only way so the two aren't quite interchangeable. #() is intended only for short anonymous functions like #(instance? Foo %). It is not a replacement for fn. #() does not nest. Here you also see why it works the way it works: #((instance? Foo %)) would a) look weird and b) give a wrong impression, that you call the return value of instance?. So for anything more complicated you should use fn instead of #(). 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 -~--~~~~--~~--~--~---
Infinite sequences hang sets and maps
and it's not hard to guess, and then prove, why: user= (defn fibs [] (map first (iterate (fn [[a b]] [b (+ a b)]) [1 1]))) #'user/fibs user= (take 10 (fibs)) (1 1 2 3 5 8 13 21 34 55) user= (.hashCode 12) 12 user= (.hashCode foo) 101574 user= (.hashCode (take 10 (fibs))) -1796812414 user= (.hashCode (fibs)) hangs Probably the seq .hashCode should consider only the first N elements for some maximum N and if two longer (or even infinite) sequences collide so be it. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Embedding Clojure in NetKernel
Hi Everybody this is my first post to this group so please tell me If I'm posting in the wrong place. I've been looking at integrating Clojure into NetKernel as language runtime library but I'm struggling a bit for a lack of examples. There are two things I'm trying to achieve: 1) start and stop the Clojure runtime on demand. I need to do this so that new versions can be deployed whilst the server is live. Looking at the latest version (1.0.0) I see that I no longer need to call RT.init() and that startup is done statically. That's fine but is there a way to cleanly shutdown. I.e. stop threads, and enable a full garbage collection of the Clojure libraries? 2) is there a way to ensure isolation of functionality in one runtime? I can see how I can use namespaces to avoid naming collisions but is it possible to enforce tighter security across namespaces or is there another technique? I'm quite new to closure so sorry if that is a stupid question - the trouble is I want to get it running inside NetKernel as good environment to explore the language - horse before the cart! When Clojure scripts execute inside NetKernel environment it is important that they act like pure functions with no side-effects on others. Thanks in advance for you advice, Tony --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
This is basically the behavior I would expect. I expect that when I put two sequences into a set, they are compared for equality, which is clearly impossible if they are infinite. I don't think I'd want some automatically truncated comparison. If I really wanted truncated comparison, there are ways to achieve that. --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
agreed, I'm not sure how meaningful it would be to compare two infinite things. On Wed, Oct 28, 2009 at 12:05 PM, Mark Engelberg mark.engelb...@gmail.com wrote: This is basically the behavior I would expect. I expect that when I put two sequences into a set, they are compared for equality, which is clearly impossible if they are infinite. I don't think I'd want some automatically truncated comparison. If I really wanted truncated comparison, there are ways to achieve that. -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ 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: Is it time to move the mailing list off of Google Groups?
I think John made some very good points in that blog post. I am running a Google Group and I am finding for smaller groups it is possible to give a few people moderator rights so that any new members are able to get their posts in at a reasonable time. Still, the points that John raises are valid. I suggested that he do the following. 1) Shut down posting from non-admins for the group ( limit to announcements and summaries ) 2) Direct people to ask questions on StackOverflow.com (SO) and tag the questions appropriately (jQuery in John's case, Clojure for this group) 3) Aggregate all new questions on SO regularly (every 4 hours?) to create a summary post on this group A group is useful because it gives you a central place to keep everyone up to date by sending out announcements. Since spam can get through when they are mixing in with a large number of members who have rights to post messages it seems Google Groups has a problem with preventing spam. So this hybrid approach may be the best option for now. I have found that SO is a great solution for getting quick answers which tend to be good quality answers. Their who system for rating answers and awarding community points has been working very well. There is no such thing for Google Groups. On the flip side, there is no way to indicate group membership with Clojure or jQuery on SO that I know about. Being able to send out an announcement to a group that is following a tag could be a way to eliminate a need for Google Groups altogether. I do not know if this is on the SO feature list. Brennan On Oct 27, 12:01 pm, Howard Lewis Ship hls...@gmail.com wrote: John Resig (the guy behind jQuery) thinks so: http://ejohn.org/blog/google-groups-is-dead/ I've noticed some amount of spam creeping into this list ... the question is how much effort is being put into moderating out that spam. John notes that GG has some gaping holes in it ... very easy to spoof and makes a damning case that GG is inherently flawed (not that it is not fixable, but that Google has shown no inclination to fixing it). -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210http://howardlewisship.com --~--~-~--~~~---~--~~ 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: Embedding Clojure in NetKernel
Tom Hicks has just pointed me to an old thread which answers questions about namespaces and isolation. Let me read and absorb all that work first - I suspect it answers a lot of my questions. Cheers, Tony On Oct 28, 11:43 am, Tony Butterfield t...@1060.org wrote: Hi Everybody this is my first post to this group so please tell me If I'm posting in the wrong place. I've been looking at integrating Clojure into NetKernel as language runtime library but I'm struggling a bit for a lack of examples. There are two things I'm trying to achieve: 1) start and stop the Clojure runtime on demand. I need to do this so that new versions can be deployed whilst the server is live. Looking at the latest version (1.0.0) I see that I no longer need to call RT.init() and that startup is done statically. That's fine but is there a way to cleanly shutdown. I.e. stop threads, and enable a full garbage collection of the Clojure libraries? 2) is there a way to ensure isolation of functionality in one runtime? I can see how I can use namespaces to avoid naming collisions but is it possible to enforce tighter security across namespaces or is there another technique? I'm quite new to closure so sorry if that is a stupid question - the trouble is I want to get it running inside NetKernel as good environment to explore the language - horse before the cart! When Clojure scripts execute inside NetKernel environment it is important that they act like pure functions with no side-effects on others. Thanks in advance for you advice, Tony --~--~-~--~~~---~--~~ 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: Scientific computing
On 27.10.2009, at 18:07, Rock wrote: these things. Why? Because they're just that: nested vectors. They're not truly multidimensional vectors, and the more I think about them, the more they really suck from that point of view. For instance, first of all they're not that safe to use (for these purposes): you could potentially have a RAGGED nested vector, which you might end up passing to a function that's expecting a true multidimensional array! That's indeed one of the arguments against the use of multidimensional Java arrays (which are nested arrays) for this purpose. What is one to do? Implement checks all over the place just to make sure that it's ok? Don't like that. All over the place would be a call to a single test function. But this need is not specific to a nested vector representation. Basically, there are two approaches to dealing with Clojure data structures representing multidimensional arrays: 1) Make them an abstract data structure. Client programs are not supposed to know the internal representation, they create arrays exclusively by calling factory functions provided for this purpose. Functions that expect array arguments can then assume that the data structure is consistent and needn't do any checks. The tightness of the abstraction can be enforced to various degrees, but that's a different issue. 2) Expose the internal representation to client code. Since any representation in terms of standard Clojure data structures could be invalid, all array functions need to do some check on their arguments. In fact, the second approach would be the best argument for the use of nested vectors, as it is a rather simple and intuitive representation from the user's perspective. With the first approach, the internal representation would be chosen exlusively for the convenience of the implementation. But it gets worse. I imagine, when dealing with nested vectors, that there's no guarantee that the data will be contiguous as when you're dealing with a linear vector. So, as far as efficiency is concerned, maybe they're not that good, but I'm not sure about that (don't know the implementation details.) I don't think there is a difference. A Clojure vector is never a contiguous block of storage. Konrad. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Constructing Java Interop calls
Hi, Sorry for the newbie question, but I am trying to understand how to construct and call java dynamically from clojure. As an example, imagine that there is a bean property called Bla and one wants to set Bla to 1 on object x, which has that property. So, the objective would be to construct, the following java equivalent x.setBla(1); I defined a macro called setProperty like this: (setProperty Bla x 1) And the definition is (very wrong): (defmacro setProperty [field obj value] `(let [cct# (symbol (.concat .set ~field))] (cct# ~obj ~value) ) ) If I do (println (setProperty Bla x 1)) I get 1 (the setBla is a void, so I should not get 1). bla is never set to 1, by the way :( Note that I am not trying to sort the particular case of beans. I am trying to understand the general mechanism to construct symbols (java interop) and execute them with a set of parameters over a java object. Thanks a lot and sorry for the newbie question, T -- The hottest places in hell are reserved for those who, in times of moral crisis, maintain a neutrality. - Dante --~--~-~--~~~---~--~~ 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: Constructing Java Interop calls
Is there a reason you don't want to use doto? http://clojure.org/java_interop#toc15 ie (doto Bla (.setProperty x 1)) 2009/10/28 Tiago Antão tiagoan...@gmail.com: Hi, Sorry for the newbie question, but I am trying to understand how to construct and call java dynamically from clojure. As an example, imagine that there is a bean property called Bla and one wants to set Bla to 1 on object x, which has that property. So, the objective would be to construct, the following java equivalent x.setBla(1); I defined a macro called setProperty like this: (setProperty Bla x 1) And the definition is (very wrong): (defmacro setProperty [field obj value] `(let [cct# (symbol (.concat .set ~field))] (cct# ~obj ~value) ) ) If I do (println (setProperty Bla x 1)) I get 1 (the setBla is a void, so I should not get 1). bla is never set to 1, by the way :( Note that I am not trying to sort the particular case of beans. I am trying to understand the general mechanism to construct symbols (java interop) and execute them with a set of parameters over a java object. Thanks a lot and sorry for the newbie question, T -- The hottest places in hell are reserved for those who, in times of moral crisis, maintain a neutrality. - Dante -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
On Wed, Oct 28, 2009 at 12:05 PM, Mark Engelberg mark.engelb...@gmail.comwrote: This is basically the behavior I would expect. I expect that when I put two sequences into a set, they are compared for equality, which is clearly impossible if they are infinite. I don't think I'd want some automatically truncated comparison. If I really wanted truncated comparison, there are ways to achieve that. Yes, I doubt equals can be made to work, but hashCode can, and equals can do something a bit more reasonable for (some) infinite sequences such as throw an exception. --~--~-~--~~~---~--~~ 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: Constructing Java Interop calls
On Wed, Oct 28, 2009 at 7:34 PM, Wilson MacGyver wmacgy...@gmail.com wrote: Is there a reason you don't want to use doto? http://clojure.org/java_interop#toc15 ie (doto Bla (.setProperty x 1)) I really want to do something different: (def x (new StringBuffer )) (doto x (.setLength 2)) But my point is to be able to construct the method name in runtime. Using doto, I still have the same problem: (defmacro setProperty [field obj value] `(let [cct# (symbol (.concat .set ~field))] (doto ~obj (cct# ~value)) ) ) If I do: (def sb (new StringBuffer )) (setProperty Length sb 2) sb I get (It should be aa). Again, the point here is to be able to construct method names (full call signatures, really) on runtime. I am lost. As in newbie clueless :( Thanks a lot, T --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
On Wed, Oct 28, 2009 at 3:56 PM, Tim Clemons tclem...@gmail.com wrote: How about having hashCode() on infinite sequences drill down into the composite infinite sequences until we arrive at the generative function? Given that values are generated on demand, the generators themselves can be compared. This runs into problems with things like (repeatedly rand) though. --~--~-~--~~~---~--~~ 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: Is it time to move the mailing list off of Google Groups?
2009/10/28 Kyle Schaffrick k...@raidi.us: Don't forget those of us who dislike web-forum software and prefer to interact with the group via email: I very seldom use the GG site itself. I find threaded email is a *very* good way of following discussions. I can have a I didn't know that moment delivered to my inbox every day, without having to visit a website and contend with the interface of yet-another-web-forum. +1 -- Michael Wood esiot...@gmail.com --~--~-~--~~~---~--~~ 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: feedback on this code
I second Tim's comment regarding holding onto calculated values. That's at best a performance optimization, and likely an unnecessary one. Also, by using the product itself as a key simplifies the case where you try to add the same product as multiple line-items (though this may be what you want if there are other considerations at play). But as to the code you have, I'd suggest using some higher-level functions. For example, change this: (defn add-line-item [cart line-item] (assoc cart :line-items (conj (cart :line-items) line-item) :total (+ (cart :total) (line-item :subtotal to this: (defn add-line-item [c li] (- c (update-in [:line-items] conj li) (update-in [:total] + (:subtotal li Likewise, you could change this: (defn update-line-item [line-items product qty] (cond (empty? line-items) () (= ((first line-items) :product) product) (cons (assoc (first line-items) :qty qty :subtotal (* qty (((first line- items) :product) :price))) (rest line-items)) :else (cons (first line-items) (update-line-item (rest line-items) product qty to this: (defn update-line-item [cart product qty] (- cart (assoc :line-items (filter #(= product (:product %)) cart)) (add-line-item (create-line-item product qty Etc... On Oct 27, 4:41 am, Timothy Pratley timothyprat...@gmail.com wrote: Hi Robert On Oct 27, 9:48 pm, Robert Campbell rrc...@gmail.com wrote: Hey guys, I'm looking for _any_ feedback/thoughts on this Clojure code I wrote. I just feel like the entire thing is way too complex, but I'm not sure about how to simplify it. I wanted to try something real world so I made a simple shopping cart ref to put in a session: Great, an open invitation! structs are really no different from maps except as a performance optimisation (and not a huge one). So dropping the structs would remove some boilerplate if simplicity is your goal. Also why not make the cart a map of products to qty and forget about subtotal... subtotal and total are easily calculated by separate functions for view or checkout... something like (untested at all): (defn add-to-cart [product qty] (if (pos? qty) (dosync (alter cart update-in [product] #(+ qty (if % % 0) (defn update-cart [product qty] (dosync (alter cart assoc product qty))) (defn remove [product] (dosync (alter cart dissoc product))) (defn subtotal [product] (* (@cart product) (price product))) (defn total [] (reduce + (map subtotal @cart))) But in a real-world example I'm not sure a ref would be the best way to deal with the state... wouldn't you have the cart sent up in the request and a new cart returned? ie: you wouldn't need to maintain a ref on the server, just provide the hooks for building a cart and checking out. So the functions might be better if they take a cart as input and return a cart. Doing that pretty much makes them empty functions: (defn remove [cart product] (dissoc cart product)) So do you even need a remove function? Maybe not. Just some thoughts - I'm no web-shop programmer so disclaimer attached. Regards, Tim. Regards, Tim. --~--~-~--~~~---~--~~ 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: Constructing Java Interop calls
2009/10/28 Tiago Antão tiagoan...@gmail.com: [...] Again, the point here is to be able to construct method names (full call signatures, really) on runtime. I am lost. As in newbie clueless :( I suspect you want reflection, but I don't know off hand how to do it. -- Michael Wood esiot...@gmail.com --~--~-~--~~~---~--~~ 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: Constructing Java Interop calls
Hi, Am 28.10.2009 um 20:46 schrieb Tiago Antão: But my point is to be able to construct the method name in runtime. You'll need reflection for that. AFAIU method calls are wired in the bytecode and hence the method name must be known at compile time. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Scientific computing
Your analysis is crystal clear and very helpful Konrad. But you haven't addressed the issue of dealing with useful information regarding the data structure itself. What if, for example, a function wanted to know the rank and dimensions of a multidimensional array it was being passed, and that array were represented by means of a nested vector? Suppose we're dealing with rank n objects. Do you think it would be an easy task to figure all that out dealing with nested vectors? And by the way, How would you go about implementing in detail a check to see if a nested vector is actually an authentic multidimensional array or not? I personally can't come up with a simple straightforward solution. I imagine you'd have to scan each dimension one by one, and make sure the various lengths are consistent. Not a tremendously efficient perspective especially when you're dealing with huge data sets, and you're forced to perhaps redundantly check the same objects over and over during operations. I honestly prefer your first case scenario. Seems much more efficient, less resource-consuming, and just straightforward. But I really would like to know what your preference is. If you had to choose, which way would you go? Thanks so much for your help. Rock On Oct 28, 7:54 pm, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 27.10.2009, at 18:07, Rock wrote: these things. Why? Because they're just that: nested vectors. They're not truly multidimensional vectors, and the more I think about them, the more they really suck from that point of view. For instance, first of all they're not that safe to use (for these purposes): you could potentially have a RAGGED nested vector, which you might end up passing to a function that's expecting a true multidimensional array! That's indeed one of the arguments against the use of multidimensional Java arrays (which are nested arrays) for this purpose. What is one to do? Implement checks all over the place just to make sure that it's ok? Don't like that. All over the place would be a call to a single test function. But this need is not specific to a nested vector representation. Basically, there are two approaches to dealing with Clojure data structures representing multidimensional arrays: 1) Make them an abstract data structure. Client programs are not supposed to know the internal representation, they create arrays exclusively by calling factory functions provided for this purpose. Functions that expect array arguments can then assume that the data structure is consistent and needn't do any checks. The tightness of the abstraction can be enforced to various degrees, but that's a different issue. 2) Expose the internal representation to client code. Since any representation in terms of standard Clojure data structures could be invalid, all array functions need to do some check on their arguments. In fact, the second approach would be the best argument for the use of nested vectors, as it is a rather simple and intuitive representation from the user's perspective. With the first approach, the internal representation would be chosen exlusively for the convenience of the implementation. But it gets worse. I imagine, when dealing with nested vectors, that there's no guarantee that the data will be contiguous as when you're dealing with a linear vector. So, as far as efficiency is concerned, maybe they're not that good, but I'm not sure about that (don't know the implementation details.) I don't think there is a difference. A Clojure vector is never a contiguous block of storage. Konrad. --~--~-~--~~~---~--~~ 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: Constructing Java Interop calls
you can always just construct the call as a string or as a datastructure and pass it through read/eval On Wed, Oct 28, 2009 at 2:04 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 28.10.2009 um 20:46 schrieb Tiago Antão: But my point is to be able to construct the method name in runtime. You'll need reflection for that. AFAIU method calls are wired in the bytecode and hence the method name must be known at compile time. Sincerely Meikel -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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: ANN: Clojure live-repl
Under Linux I had to fix the paths in liverepl.sh to include the build folder: java -cp $LIVEREPL_HOME/build/*:$JDK_HOME/lib/tools.jar net.djpowell.liverepl.client.Main $CLOJURE_JAR $LIVEREPL_HOME/build/ liverepl-agent.jar $LIVEREPL_HOME/build/liverepl-server.jar $@ --~--~-~--~~~---~--~~ 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: Scientific computing
maps could also be an option. you can use vectors of ints as keys. (and you can stick dimensions and such in there with keywords) i'm not sure how that compares to nested vectors for perforance. you have the overhead of the hash function, but you don't have any nesting. it's also pretty handy if you want to represent a sparse matrix. --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
On Oct 28, 1:34 pm, John Harrop jharrop...@gmail.com wrote: This runs into problems with things like (repeatedly rand) though. How so? The repeatedly function returns a lazy sequence that (presumably) stores a reference to repeatedly as its generator function. That instance of repeatedly would, in turn, have to store a reference to the rand function in order to call it as necessary. So when the resulting lazy sequence has its hash code requested, it could return a value similar to the following: (+ (.hashCode rand) (* 37 (.hashCode repeatedly))) --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
So when the resulting lazy sequence has its hash code requested, it could return a value similar to the following: (+ (.hashCode rand) (* 37 (.hashCode repeatedly))) I think John's point is this: user= (take 3 (repeatedly rand)) (0.07020342855887218 0.590736243072285 0.04997104958104426) user= (take 3 (repeatedly rand)) (0.6445602419794128 0.12488917903865004 0.5784287452848529) Different sequences, even if the generators are the same. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
bugs in cl-format.clj
Hello, I've encountered a couple of issues with the cl-format function included in contrib.pprint (cl-format nil ~1,1$ -12.0) ;; = 12.0 the sign is lost I think the problem is the following assignment in the dollar-float function add-sign (and (:at params) (not (neg? arg))) ;; wrong (the sign is only printed when the colon modifier is present and only for positive numbers) that should read, if I understand correctly the logic, add-sign (or (:at params) (neg? arg)) The second issue is not so straightforward to solve: (cl-format true ~1,1$~% 0.001) ;; = String index out of range: -1 I've tracked down the bug into the function round-str (the variable round-pos will be negative and this case is not handled properly), but I don't understand the code well enough to propose a fix. 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: pointfree library
Would love to see some examples usages of these On Sun, Oct 25, 2009 at 4:16 PM, harrison clarke notall...@gmail.comwrote: so i was using haskell, and the pointfree stuff is fun, so naturally i had to implement some of it in clojure. this is what i have so far. library and examples within: http://github.com/hclarke/pointfree-clojure it has , , ***, +++, |||, and others they take functions as arguments and return functions for those that don't know: composes functions in reverse order. it basically pipes them together left to right maps functions over a single value (haskell's takes two functions, this takes any number) *** maps functions over a sequence (as above, this takes any number of functions) +++ takes a choice ([bool, x]), and applies f1 if f2 if false ([bool, (f x)]) ||| same as above, but just returns the (f x) part. drops the bool there's also: fst applies function to the first element. same as (*** f id id id...) snd applies function to the second element. same as (*** id f id id id...) ttt same as (+++ f id). same as haskell's left fff same as (+++ id f). same as haskell's right III takes [i x] and applies the ith function (starting from 0), returning [i (f x)] iii same as above, but drops the bool curry makes a function keep returning a function until you pass it enough arguments to evaluate (default is 2 args) see curry example on github for how it works at this point, names, and pretty much everything, are likely to change. thoughts, questions, suggestions, etc.? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
cannot cast error java char-array to java string
What is wrong with this code? I want to instantiate a Java String from a Java character-array. But I want it to be fast, hence the need to cast per the warn on reflection message. user= (set! *warn-on-reflection* true) true user= (new String #^[C (make-array Character/TYPE 3 \a )) java.lang.ClassCastException: [[C cannot be cast to [C (NO_SOURCE_FILE:0) This seems to be correct if I correctly understood this thread. http://groups.google.com/group/clojure/browse_thread/thread/6a2821394d0099a4/0f4dfef688b40a9b?lnk=gstq=String+character+array+cast#0f4dfef688b40a9b As we all know, this is brain-dead easy in POJ (aside from the initial 'a' value in the array). char foo[] = new String[3]; // do something here String foo = new String( foo ); // voila ! Chick, chick, chickee --~--~-~--~~~---~--~~ 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: ANN: Clojure live-repl
Under Linux I had to fix the paths in liverepl.sh to include the build folder: java -cp $LIVEREPL_HOME/build/*:$JDK_HOME/lib/tools.jar net.djpowell.liverepl.client.Main $CLOJURE_JAR $LIVEREPL_HOME/build/liverepl-agent.jar $LIVEREPL_HOME/build/liverepl-server.jar $@ I think liverepl.sh gets copied to the build folder, so the intent is to run that copy of the liverepl.sh script. (Though I haven't really tested the .sh script) -- Dave --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
On Oct 28, 4:33 pm, Richard Newman holyg...@gmail.com wrote: I think John's point is this: user= (take 3 (repeatedly rand)) (0.07020342855887218 0.590736243072285 0.04997104958104426) user= (take 3 (repeatedly rand)) (0.6445602419794128 0.12488917903865004 0.5784287452848529) Different sequences, even if the generators are the same. Ah, right. My gut response to that is if the users are calling hashCode() on lazy sequences, then they should expect a value which based on how the sequence is generated. If they want a hash code based on the actual values of the sequence, it should be evaluated with a doall and have hashCode called on the resulting non-lazy sequence. This would also make the user consciously face the possibility of evaluating an infinite sequence rather than it being a gotcha hidden away in hashCode's internals. That said, I haven't read enough Clojure code in the wild to get a feel of how upsetting such a change would be. Creating a hashmap with lazy sequences as keys seems unintuitive. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Java 7, nio, and createFile
Howdy all, I'm trying to call the createFile method from the Path class specified here: http://java.sun.com/javase/7/docs/api/java/nio/file/Path.html The following text: The following code snippet creates a file with default attributes: Path file = ...; try { file.createFile(); //Create the empty file with default permissions, etc. } catch (FileAlreadyExists x) { System.err.format(file named %s already exists%n, file); } catch (IOException x) { //Some other sort of failure, such as permissions. System.err.format(createFile error: %s%n, x); } from: http://java.sun.com/docs/books/tutorial/essential/io/file.html describes how you can call createFile without any parameters even though the method signature in the api only has one version of the method taking a FileAttribute object. When I try and call createFile from clojure: (.createFile path) I get an exception that there is no field named createFile. This makes perfect sense to me since there is no public method with an explicit signature taking zero args, so clojure is looking for a field. However, based on a test program in java and the tutorial text, the method works great without any parameters. Is there any way to force clojure to try and call the method? Passing nil as an argument gets a null pointer exception. I could create a FileAttribute object easily if I was running on a Posix filesystem, but I'd like this to work on DOS as well. Thanks! Carl --~--~-~--~~~---~--~~ 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: Infinite sequences hang sets and maps
John Harrop wrote: Probably the seq .hashCode should consider only the first N elements for some maximum N and if two longer (or even infinite) sequences collide so be it. I strongly disagree. Choosing some arbitrary magic cutoff point just seems cause for trouble and much confusion. Putting something in a hash set or using it as a map key implies evaluating it -- you'd expect summing or printing an infinite sequence to hang, so why shouldn't hashing it also hang? Also to those suggesting treating infinite sequences differently to regular ones: it's impossible to determine (in the general case) whether a sequence is infinite or not as it would involve solving the halting problem. Throwing an exception in some specific cases would require changing things like (repeat x) to use a different seq implementation class. I think this would gain you very little since there's only a couple of cases where this can be done and as soon as you do something with the seq you don't know whether it's infinite anymore. --~--~-~--~~~---~--~~ 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: Constructing Java Interop calls
Tiago Antão wrote: Again, the point here is to be able to construct method names (full call signatures, really) on runtime. I am lost. As in newbie clueless :( As others have suggested you need to use either Java's reflection or Clojure's eval. Here's some examples: Using reflection: (let [obj some string method (.getDeclaredMethod (class obj) substring (into-array Class [Integer/TYPE]))] (.invoke method obj (to-array [2]))) = me string If you want to know more about what you can do with reflection, consult: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html Using eval (which will also work for dynamically calling Clojure functions): (let [obj some string fname .substring] (eval (list (symbol fname) obj 2))) = me string --~--~-~--~~~---~--~~ 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: cannot cast error java char-array to java string
Chick Corea wrote: What is wrong with this code? I want to instantiate a Java String from a Java character-array. But I want it to be fast, hence the need to cast per the warn on reflection message. user= (set! *warn-on-reflection* true) true user= (new String #^[C (make-array Character/TYPE 3 \a )) java.lang.ClassCastException: [[C cannot be cast to [C (NO_SOURCE_FILE:0) Note the exception, [[C means a two-dimensional arary. (make-array Character/TYPE 3 \a) actually means (make-array Character/TYPE 3 97) so a 3 by 97 two-dimensional array (new char[3][97] in java syntax). What you probably want is: user (String. #^[C (into-array Character/TYPE (repeat 3 \a))) aaa --~--~-~--~~~---~--~~ 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: cannot cast error java char-array to java string
Also you can substitute #^[C with the more legible #^chars. On Oct 28, 7:27 pm, Alex Osborne a...@meshy.org wrote: Chick Corea wrote: What is wrong with this code? I want to instantiate a Java String from a Java character-array. But I want it to be fast, hence the need to cast per the warn on reflection message. user= (set! *warn-on-reflection* true) true user= (new String #^[C (make-array Character/TYPE 3 \a )) java.lang.ClassCastException: [[C cannot be cast to [C (NO_SOURCE_FILE:0) Note the exception, [[C means a two-dimensional arary. (make-array Character/TYPE 3 \a) actually means (make-array Character/TYPE 3 97) so a 3 by 97 two-dimensional array (new char[3][97] in java syntax). What you probably want is: user (String. #^[C (into-array Character/TYPE (repeat 3 \a))) aaa --~--~-~--~~~---~--~~ 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: ANN: Clojure live-repl
David Powell wrote: Under Linux I had to fix the paths in liverepl.sh to include the build folder: java -cp $LIVEREPL_HOME/build/*:$JDK_HOME/lib/tools.jar net.djpowell.liverepl.client.Main $CLOJURE_JAR $LIVEREPL_HOME/build/liverepl-agent.jar $LIVEREPL_HOME/build/liverepl-server.jar $@ I think liverepl.sh gets copied to the build folder, so the intent is to run that copy of the liverepl.sh script. (Though I haven't really tested the .sh script) Yeah, that's how I did it (based on what the batch file was doing). --~--~-~--~~~---~--~~ 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: Java 7, nio, and createFile
youngblood.carl wrote: When I try and call createFile from clojure: (.createFile path) I get an exception that there is no field named createFile. If I remember correctly variable argument Java methods, which is what that ... syntax means: abstract Path createFile(FileAttribute?... attrs) {} are actually just syntactic sugar for an array argument: abstract Path createFile(FileAttribute?[] attrs) {} so try: (.createFile path (make-array FileAttribute 0)) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---