Re: agents sending-off to other agents blocks?
2010/6/12 Dan Larkin d...@danlarkin.org Does anyone have insight as to the reasoning here? Is it a bug? If it's intended behavior is there something I can do to circumvent it? I do think this is intentional. Agents holding on to their sends until its state transition function is done can be a useful thing. Either the function completes and the actions get sent, or (maybe due to an exception being thrown) the function fails, the agent doesn't change its state and the pending sends are dropped. This results in a everything-or-nothing update model for agents, somewhat similar to transactions (which are also holding on to sends, btw). If this wasn't the default behaviour, I think it would be very tedious to write code that needs it. One solution to the sleep problem could perhaps be to let the agent send this to it self: (fn [state millis] (Thread/sleep millis) state) // raek -- 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: agents sending-off to other agents blocks?
Hi, On Jun 16, 12:56 pm, Rasmus Svensson r...@lysator.liu.se wrote: One solution to the sleep problem could perhaps be to let the agent send this to it self: (fn [state millis] (Thread/sleep millis) state) With this one has to keep in mind, that maybe someone else has already sent another action to the agent. So the sleep might happen after some further computation and not immediately. 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
Re: agents sending-off to other agents blocks?
Yup, I think the transactional semantics are the main cause of this behavior. Aren't send and send-off doing the same thing during a real transaction in a ref? To fight the issue of repeating send if the transaction gets retried. On Wed, Jun 16, 2010 at 1:05 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Jun 16, 12:56 pm, Rasmus Svensson r...@lysator.liu.se wrote: One solution to the sleep problem could perhaps be to let the agent send this to it self: (fn [state millis] (Thread/sleep millis) state) With this one has to keep in mind, that maybe someone else has already sent another action to the agent. So the sleep might happen after some further computation and not immediately. 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 -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com/profiles/ulrich.moritz -- 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: Serious problem with underive (for hierarchies), an attempt to fix, and request for code review.
Hi Rob, Thanks for tracking this down. If you will execute a CA [1], I would love to get a patch (with tests) that fixes this. I have created a ticket at [2] to track it. I would prefer something along the lines of the simpler fix shown below, unless anybody pops up on this thread with a real-world use case for performance-critical underive. Stu [1] http://clojure.org/contributing [2] https://www.assembla.com/spaces/clojure/tickets/382-fix-underive-for-multiple-inheritance As an alternative, if we're willing to rebuild the entire hierarchy, not just the subgraph that's affected by the underivation, we can just do this: (defn easy-underive [h child parent] (let [oldParents (:parents h) childsParents (disj (clojure.set/union #{} (child oldParents)) parent) newParents (if (not-empty childsParents) (assoc oldParents child childsParents) (dissoc oldParents child)) derivation-seq (flatten (map #(cons (key %) (interpose (key %) (val %))) (seq newParents)))] (reduce #(apply derive (cons %1 %2)) (make-hierarchy) (partition 2 derivation-seq It's less efficient, because it tosses out all of the information in the ancestor and descendant sets. But it is a good deal simpler -- 10 lines of code instead of 60 or so. For small hierarchies this would be fine. If anyone were to make large hierarchies which had to be modified efficiently, though, I think something like in the first message would be required. On Jun 15, 4:29 pm, Rob Lachlan robertlach...@gmail.com wrote: Oh God. What broken formatting. Sorry about that. On Jun 15, 4:24 pm, Rob Lachlan robertlach...@gmail.com wrote: I think that the underive function for removing hierarchy relationships between keywords is broken. I'll illustrate with an example and describe what I think the problems are. I've got some code for a function which (I hope!) performs underive correctly, and I'd love it if people had a look. Consider a hierarchy with child-parent relationships: :c - :p1, :c - :p2, :p1 - :a1, :p1 - :a2, :p2 - :a2 Which I'll illustrate with the world's worst ascii art: a1a2 | / | | / | | / | p1p2 | / | / | / c ; creating this hierarchy: user (def h (reduce #(apply derive (cons %1 %2)) (make-hierarchy) [[:p1 :a1] [:p1 :a2] [:p2 :a2] [:c :p2] [:c :p1]])) #'user/h user h {:parents {:c #{:p1 :p2}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :ancestors {:c #{:p1 :p2 :a2 :a1}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :descendants {:p1 #{:c}, :p2 #{:c}, :a2 #{:p1 :p2 :c}, :a1 #{:p1 :c}}} Now the underive: user (underive h :c :p1) {:parent {:c #{:p2}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :ancestors {:c #{:p2}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :descendants {:p1 #{}, :p2 #{:c}, :a2 #{:p1 :p2}, :a1 #{:p1}}} Problems: Most seriously, it is incorrect: :c should still show up as a descendant of :a2, since :c is a child of :p2, and :p2 a child of :a2. Note that the parent map is correct, so it is the ancestor and descendant maps which are inconsistent. Also, notice that the key for the parent map has changed from :parents to :parent, which causes calls to the parents function to return nil. Also, keys which map to empty sets are left in each of the maps (parents, descendants and ancestors), with the result that equality tests could fail in some cases in which they would be true. Potential fix, and request for code review: I've written an underive-new function which appears to fix these problems, at least in the tests that I've done. http://pastebin.com/eRiz5ihw My approach is to identify the sets of tags in the hierarchy whose ancestors or descendants may be affected, remove their ancestor or descendant mappings, then rebuild them. In a call (underive h child parent), the child and all the child's descendants will need to have their ancestor mappings fixed. Similarly, the parent and all of the parent's ancestors will need to have their descendant mappings rebuilt. (As an aside, the problem here is that our hierarchy can be a DAG rather a tree, because multiple inheritance is allowed. And therefore, for any ancestor/descendant relationship it's comparatively expensive to determine whether a particular parent-child edge is essential or not.) Next, the two sets of interest (child + child's descendants, and parent + parent's ancestors) are sorted topologically. For the child + child's descendants, we can now rebuild the ancestor mappings by taking a tag from the top of the set, setting its ancestors to the union of tag's parents and parents' ancestors, and repeating the process on the next tag in topologically sorted order until all tags are consumed. The parent + parent's ancestors can be done in a similar way, except that a children function is
Re: Non-tail recursion (Clojure way to hierarchies)
Thanks James. If any one else is as new to functional stuff as me then I found this in Paul Graham's book which enables me to reason logically about the matter (hopefully) A good compiler can compile a tail call into a goto, and so can compile a tail recursive function into a loop. In typical machine language code, when control arrives for the first time at the segment of instructions representing len (a local fn) there is information on the stack saying what to do upon returning. Because nothing remains to be done after the recursive call, this information remains valid for the second call as well On Jun 15, 11:28 pm, James Reeves jree...@weavejester.com wrote: On 15 June 2010 22:56, Quzanti quza...@googlemail.com wrote: Thanks Mike. So does is the only kind of recursion optimisation tail recursion? Can you only eliminate stack calls in tail calls? No, you can also eliminate stack calls using lazy-seq or trampolines. If you provide some example code of what you are currently doing, it would be easier to gauge what is the most suitable approach. You might not even need to bother eliminating stack calls, if you know you're never going to recurse very far. Having some sort of hint about this in the recur documentation might be helpful? Well, the docs do say recur in other than a tail position is an error, though that does assume the reader knows what the tail position of a function is. - James -- 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
Gwt-Clojure - lightweight browser implementation
Gwt-Clojure is a subset of the Clojure language which was developed for scripting GWT (Google Windows Toolkit) widgets in the browser environment. It is designed to be able to share code with Clojure running on the server. The current deployment size is about 145kb of Javascript - including the interpreter and several GWT widget classes. Test environment: http://wisperweb.appspot.com/ Gwt-Clojure blog post: http://framegen.wordpress.com/2010/06/15/gwt-clojure/ -- 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: working with agents and atoms - a beginner question
On Tue, Jun 15, 2010 at 12:23 PM, Shawn Hoover shawn.hoo...@gmail.com wrote: On Tue, Jun 15, 2010 at 12:01 PM, Ryan Waters ryan.or...@gmail.com wrote: I'm working with the code at the following gist and also pasted below: http://gist.github.com/421550 I'd like to have execution of a separate thread (agent) continue running until it sees the atom 'running' change to false. Unfortunately, the program doesn't return from the send-off but to my understanding it should. Why won't it return? I'm using clojure 1.1. TIA (ns nmanage) (def running (atom true)) (defn process [] (when @running (prn hi) (Thread/sleep 1000)) (recur)) ;;; (send-off (agent nil) (process)) (do (prn this won't print - execution doesn't make it this far) (Thread/sleep 2000) (reset! running false)) It looks like you're passing the result of calling (process) as an argument to send-off. Try just (send-off (agent nil) process) to pass the process fn as a value. Doh! I should have caught that : ) Thank you for your help! -- 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: working with agents and atoms - a beginner question
Thank you for pointing that out. I notice your style is similar to Rich's in his ant.clj [1] which seems like the kind of solution that might be used in other functional and/or lisp languages. Do you know if that's the case with self-calling functions and agents? However, isn't there more overhead with calls to send-off instead of recur? I understand functions sent to an agent will only run one at a time, fifo-style, but was under the impression *agent* was for the current main thread of the program. Does *agent* instead refer to whatever is the current thread in the function's runtime context? Hope that question makes sense. [1] http://clojure.googlegroups.com/web/ants.clj?gda=uyYClToAAADrLV-d6p24hYFcam_S99IgeBuuRL78NgAsI-ljfFHCWu9OU0NQiFWgQuhmPR7veGf97daDQaep90o7AOpSKHW0 On Tue, Jun 15, 2010 at 3:03 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, besides the answer you got from Shawn, I'd like to question your use of the agent system. This is not the way it is supposed to be used. To model a processing loop with agents you should send the action back to the agent itself. (def running? (atom true)) (defn process [agent-state step] (when @running? (send-off *agent* process (inc step))) (+ agent-state step)) (def a (agent 0)) (send-off a process 1) (Thread/sleep 100) (reset! running? false) Note: in an action *agent* refers to the current agent. 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
Re: Complex type in clojure
Mathematicians traditionally use i and engineers traditionally use j to represent the square root of -1. Travis undoubtedly wanted to keep both happy. -- Eric Krohn Sorry I may have missed the reason for this earlier: What's the reason for allowing both 'i' and 'j' to indicate the imaginary part? Is the intention to also later have 'k' to support quaternions? Just curious. Thanks. Carson -- 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: New Clojure web application launched: DocuHarvest
Thanks, very helpful. I hadn't heard of clutch before your announcement, so I appreciate the introduction. The clojure view server sounds especially interesting! Jim On Tue, Jun 15, 2010 at 12:51 PM, Chas Emerick cemer...@snowtide.com wrote: Last I looked (and it appears to be the same way after a quick glance just now), clojure-couchdb isn't as complete as clutch. The latter provides: - bulk update support - view support (both existing and temporary views) - rudimentary couchapp support - a clojure view server (which we don't need right now, but that'll come in handy if and when that changes) - _changes support There might be more. FWIW, I'm a committer on the clutch project, so I'm naturally biased, but I think the above is a fair statement of features that I know we'd miss in a CouchDB API (notwithstanding our not using the clojure view server in production (yet?)). - Chas On Jun 13, 2010, at 11:57 AM, Moritz Ulrich wrote: Yup, I would like to know why you chose clutch over clojure-couchdb too. (I don't want to insinuate that clojure-couchdb is the better lib) On Thu, Jun 10, 2010 at 9:39 PM, Jim Blomo jim.bl...@gmail.com wrote: On Thu, Jun 10, 2010 at 4:32 AM, Chas Emerick cemer...@snowtide.com wrote: - Clutch to interface to CouchDB (which we abuse as a message queue, among other things) Can you comment on the choice of Clutch over clojure-couchdb? I've found clojure-couchdb to be reliable and straightforward. the-kenny's (Moritz Ulrich) branch is being actively maintained and he's been helpful getting it working for me. Jim -- 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 -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com/profiles/ulrich.moritz -- 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 -- 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 -- 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: Complex type in clojure
We Electrical Engineers are quite annoying in this regard, but historically, there is much variation out there: Python uses j, MATLAB accepts i or j. Apache Commons allows the user to specify the specific character to use, but defaults to i I believe. Eventually, I would suggest this be a localizable field. Please see: http://en.wikipedia.org/wiki/Imaginary_unit#Alternative_notations -Travis On Jun 15, 4:22 pm, James Reeves jree...@weavejester.com wrote: On 15 June 2010 23:26, Carson c.sci.b...@gmail.com wrote: Sorry I may have missed the reason for this earlier: What's the reason for allowing both 'i' and 'j' to indicate the imaginary part? Is the intention to also later have 'k' to support quaternions? Just curious. Thanks. j is used by electrical engineers to represent the imaginary part of a complex number, because I has already been taken to mean electrical current. Presumably this is the reason. - James -- 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: Can anyone create a simpler version of prime factors in Clojure?
Here's my awful terrible code which is a direct translation from a java version I wrote and needs a fast functional sieve: I prefer Cristophe Grande's. http://clj-me.cgrand.net/index.php?s=Everybody%20loves%20the%20Sieve%20of%20Eratosthenes The one in contrib is pretty good as well. (letfn [(n-p [n prime pow] (if (zero? (rem n prime)) (recur (/ n prime) prime (inc pow)) [n pow])) (get-primes [lim n primes] (let [p (first primes)] (cond (= n 1) (list) (or (empty? primes) ( (* p p) lim)) [[n 1]] :else (let [np (n-p n p 0)] (if (zero? (second np)) (recur lim n (rest primes)) (lazy-cat [[p (second np)]] (get-primes lim (first np) (rest primes] (defn prime-factors ([n primes] (if ( n 2) (list) (lazy-seq (get-primes n n primes ([n] (prime-factors n (take-while #(= (* % %) n) (primes)) On Jun 11, 2:15 pm, russellc russell.christop...@gmail.com wrote: Not sure it's better than Uncle Bobs version but it seems a little more idiomatic? (defn of [n] (letfn [(f [res k] (if (= 0 (rem (:n res) k)) (assoc (assoc res :n (quot (:n res) k)) :fs (conj (:fs res) k)) res))] (:fs (reduce f {:n n :fs []} (range 2 n) Uncle Bob version below (http://blog.objectmentor.com/articles/ 2010/05/15/clojure-prime-factors) (defn of ([n] (of [] n 2)) ([factors n candidate] (cond (= n 1) factors (= 0 (rem n candidate)) (recur (conj factors candidate) (quot n candidate) candidate) ( candidate (Math/sqrt n)) (conj factors n) :else (recur factors n (inc candidate)) ) ) ) -- 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: Serious problem with underive (for hierarchies), an attempt to fix, and request for code review.
The problems are real. Well done! -- 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: Serious problem with underive (for hierarchies), an attempt to fix, and request for code review.
Another apporach I think would be modifying the data structure of hierarchy itself. The idea is to add a counter to ancestors and descendants. :ancestors: { :c #{ [:a1 1] [:a2 2] } } So, the counter 2 on :a2 means how many paths can you get :c to reach :a2. When the counter reaches 0, you can remove it completely. Otherwise, decrement it. This approach requires to change all the functions related to hierarchy, and the data structure will be incompatible to the original one. But the speed is gonna be fast. -- 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: working with agents and atoms - a beginner question
On Wed, Jun 16, 2010 at 12:17 AM, Christophe Grand christo...@cgrand.net wrote: Hi Ryan, On Tue, Jun 15, 2010 at 6:01 PM, Ryan Waters ryan.or...@gmail.com wrote: I'm working with the code at the following gist and also pasted below: http://gist.github.com/421550 I'd like to have execution of a separate thread (agent) continue running until it sees the atom 'running' change to false. Unfortunately, the program doesn't return from the send-off but to my understanding it should. Why won't it return? I'm using clojure 1.1. It does return from send-off -- in your gist's version at last thanks to Shawn but there are still other errors. (ns nmanage) (def running (atom true)) (defn process [] A fn sent as an action to an agent must accept at least one arg: the agent's current value (if additional args are passed to args, the action fn must accept them too). So the above line should be [_] (_ to signify that you don't care about the value) instead of [] Thank you - I was unaware that a function sent to an agent had to accept at least one arg. (when @running (prn hi) (Thread/sleep 1000)) (recur)) Here your recur is misplaced, you want to recur when @running is true so the (recur) should be at the end of the when form and it should have an extra argument since we changed process to take one arg. However this when/recur pattern is what the while macro expands to. (defn process [_] (while @running (prn hi) (Thread/sleep 1000))) Very true - in this example, I totally agree. The example I put together is a simplified version of the program I'm working on which uses some file I/O. I'm wanting to tail a file and process its contents over time so I had a loop that would read the file until it started reading 'nil', then sleep, then try again, creating a loop within a loop (and polling the file for new contents). In trying to keep the example program faithful to the other, I ended up with some nonsensical clojure ; ) ;;; (send-off (agent nil) (process)) Here it should be (send-off (agent nil) process) but Shawn already pointed this out. I think that using an agent and not caring about its value is kind of an abuse, better use a future. (def running (atom true)) (future (while @running (prn hi) (Thread/sleep 1000))) Here my near total ignorance of futures comes into play. Thank you very much for pointing this out as a better way. I've been so eager to write a first program in clojure that I haven't gotten through all the 1.1 (and 1.0) language features yet. :D ;;; (do (prn this prints now - fixed thanks to Shawn Hoover) (Thread/sleep 2000) (reset! running false)) hth, Christophe -- European Clojure Training Session: Brussels, 23-25/6 http://conj-labs.eu/ Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) I appreciate yours and everyone's valuable time! -- 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: agents sending-off to other agents blocks?
Yeah, it's intended, just like what Ulrich showed. The same comment appears on the doc of release-pending-sends. In your case, the inner send-off doesn't rely on the result of the outter send-off. So, you can use release-pending-sends. The following code will have hey printed right away. (send (agent nil) (fn [_] (send (agent nil) (fn [_] (println Hey!))) (release-pending-sends) (Thread/sleep 4000))) (shutdown-agents) The interesting thing is, if you remove the call to (release-pending- sends) and the call to (shutdown-agents) will cause java.util.concurrent.RejectedExecutionException being thrown. This is because, I think, when the outter send-off has finished sleeping, shutdown-agents (which is really a call to shutdown on the thread-pool agents used) will take effect, and the thread-pool is shut down. Then, the inner send-off starts to work, but he will find that the thread pool has already been turned off. So the exception is thrown. I don't know how to NOT call the release-pending-sends function, and still be able to shutdown-agents. Would anyone tell me how? On Jun 13, 3:46 am, Moritz Ulrich ulrich.mor...@googlemail.com wrote: Sorry for the second mail, but here is the passage from clojure.org which mentions the behavior you've seen: 5. If during the function execution any other dispatches are made (directly or indirectly), they will be held until after the state of the Agent has been changed. Maybe it's done to prevent problems when the function the currently-active agent sent to another agent depends on the value of the original agent. On Sat, Jun 12, 2010 at 9:43 PM, Moritz Ulrich ulrich.mor...@googlemail.com wrote: I'm not sure why it's doing this, but I read about this in the api documentation - It's intended On Sat, Jun 12, 2010 at 9:41 PM, Dan Larkin d...@danlarkin.org wrote: Hey all, I've cooked up this example code to demonstrate a point: (send-off (agent nil) (fn [_] (send-off (agent nil) (fn [_] (println Hey!))) (Thread/sleep 4000))) ; Hey! isn't printed for 4 seconds (when the outer agent finishes). Which is that actions sent to an agent from another agent won't be started until the first agent returns from its current action. Does anyone have insight as to the reasoning here? Is it a bug? If it's intended behavior is there something I can do to circumvent it? Dan -- 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 -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com/profiles/ulrich.moritz -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com/profiles/ulrich.moritz -- 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
Passing Arguments From Java to Clojure
There's a canonical intro on how to call or embed Clojure into Java: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java While this is a great introduction, the only thing Java passes in to Clojure here is a string. I've tried methods where Java passes in ints, and those work fine too. What I'm primarily concerned with is if there is some way to pass in a list/vector/etc, if there's a particular way to format the argument on the Java side so it can be easily converted on the Clojure side without much hassle (via vector or something similar), or if I need to just suck it up, pass in a string of numbers, and write a function on the Clojure side that handles all that. To be specific, I would like to make a vector that would end up in pairs: [[1 2] [3 4] [5 6]]. For those of you familiar with Incanter, this will then become a dataset. Thanks in advance. -- 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: Why does clojure-http stores cookies in a ref instead of an atom
Thanks for the reply. I wasn't trying to be critical. I have a similar situation where I'm using an atom instead of a ref, and wanted to make sure I wasn't missing anything in my understanding of refs vs. atoms. I am using clojure-http currently and it works quite well, thank you! It's very easy to use. Also I've learned a lot by looking at the code, which is clear and well written. Steve On Mon, Jun 14, 2010 at 4:56 PM, Phil Hagelberg p...@hagelb.org wrote: On Fri, Jun 11, 2010 at 8:45 AM, Steve Molitor stevemoli...@gmail.com wrote: I'm a clojure newbie trying to understand when to use atoms versus refs. In clojure-http.resourcefully, if you use the with-cookies macro stores the cookies in a thread local ref. Why a ref and not an atom? My impression is that refs are for when you need to coordinate changes to more than one variable, or maybe if you need triggered validations. Actually you're correct; an atom would be better here. I wrote that code a long time ago and haven't used or looked at it since, but there's absolutely no reason to pull in the STM for state changes like that. -Phil -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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: working with agents and atoms - a beginner question
Hi, Am 15.06.2010 um 23:27 schrieb Ryan Waters: Thank you for pointing that out. I notice your style is similar to Rich's in his ant.clj [1] which seems like the kind of solution that might be used in other functional and/or lisp languages. Do you know if that's the case with self-calling functions and agents? However, isn't there more overhead with calls to send-off instead of recur? Yes, there is additional overhead. However hijacking a thread from agent thread pool (even if send-off) is misusing agents as Christophe said. Agents is about updating states. Not about (long running) threads. The typical solution for your problem would probably be: (- long-running-function-with-recur Thread. .start) This starts you function in a dedicated thread and you can save the overhead of send-off and use recur directly. I'm unsure about using future here. For me future is a thing, which returns something. Using it for a process which does return something useful seems dirty to me. I understand functions sent to an agent will only run one at a time, fifo-style, but was under the impression *agent* was for the current main thread of the program. Does *agent* instead refer to whatever is the current thread in the function's runtime context? Hope that question makes sense. *agent* is bound to the agent whose action we are currently running in this thread. So concurrently running actions see different *agent*s. Hope this helps. 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
Re: working with agents and atoms - a beginner question
On Wed, Jun 16, 2010 at 10:20 PM, Meikel Brandmeyer m...@kotka.de wrote: The typical solution for your problem would probably be: (- long-running-function-with-recur Thread. .start) This starts you function in a dedicated thread and you can save the overhead of send-off and use recur directly. I'm unsure about using future here. For me future is a thing, which returns something. Using it for a process which does return something useful seems dirty to me. I agree, it still feels a little dirty to use a future without caring about the return value but on the positive said you get an easy way to block and wait for the tread to finish (deref) and you also get future-done?, future-cancel and future-cancelled which can prove useful. Christophe -- European Clojure Training Session: Brussels, 23-25/6 http://conj-labs.eu/ Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) -- 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: working with agents and atoms - a beginner question
Hi, Am 16.06.2010 um 22:34 schrieb Christophe Grand: I agree, it still feels a little dirty to use a future without caring about the return value but on the positive said you get an easy way to block and wait for the tread to finish (deref) and you also get future-done?, future-cancel and future-cancelled which can prove useful. True. This infrastructure is an incentive to use future. Maybe one can wash away the dirty feeling by believing, that deref'ing is actually a syncronisation point of sorts and the return value just a side-effect. 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
Re: Gwt-Clojure - lightweight browser implementation
That looks really cool. I want to do some webstuff with clojure soon and I have to look at your stuff more then and I have to read a bit about GWT never heard of it until now. On 15 Jun., 20:48, pfisk peter.f...@gmail.com wrote: Gwt-Clojure is a subset of the Clojure language which was developed for scripting GWT (Google Windows Toolkit) widgets in the browser environment. It is designed to be able to share code with Clojure running on the server. The current deployment size is about 145kb of Javascript - including the interpreter and several GWT widget classes. Test environment:http://wisperweb.appspot.com/ Gwt-Clojure blog post:http://framegen.wordpress.com/2010/06/15/gwt-clojure/ -- 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: Serious problem with underive (for hierarchies), an attempt to fix, and request for code review.
Hi Stuart, I'll be mailing the agreement later today, and I'll work on a patch shortly. I've noticed that the unit tests file for multi-methods, where tests for derive and underive would be located, is essentially empty. So I thought I might put some tests in there for isa, parents, ancestors, etc. while I'm about it. I take your point on preferring a simpler version. I have a feeling that: -most people are using the global hierarchy -most people are using the hierarchy essentially statically which is a bit of a shame, since the hierarchy system is quite powerful. With independent hierarchies, you can confidently juggle several hierarchy relationships, and dynamically update them. I think their uses go beyond multi-methods. But for hierarchies which are largely static, and which will rarely underive, a simpler underive in core will be good. I'll probably put my complicated version together with some other convenience functions for hierarchies in a library of my own, in case anyone has a need for it. Rob p.s. Loved the book. On Jun 16, 7:54 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Hi Rob, Thanks for tracking this down. If you will execute a CA [1], I would love to get a patch (with tests) that fixes this. I have created a ticket at [2] to track it. I would prefer something along the lines of the simpler fix shown below, unless anybody pops up on this thread with a real-world use case for performance-critical underive. Stu [1]http://clojure.org/contributing [2]https://www.assembla.com/spaces/clojure/tickets/382-fix-underive-for-... As an alternative, if we're willing to rebuild the entire hierarchy, not just the subgraph that's affected by the underivation, we can just do this: (defn easy-underive [h child parent] (let [oldParents (:parents h) childsParents (disj (clojure.set/union #{} (child oldParents)) parent) newParents (if (not-empty childsParents) (assoc oldParents child childsParents) (dissoc oldParents child)) derivation-seq (flatten (map #(cons (key %) (interpose (key %) (val %))) (seq newParents)))] (reduce #(apply derive (cons %1 %2)) (make-hierarchy) (partition 2 derivation-seq It's less efficient, because it tosses out all of the information in the ancestor and descendant sets. But it is a good deal simpler -- 10 lines of code instead of 60 or so. For small hierarchies this would be fine. If anyone were to make large hierarchies which had to be modified efficiently, though, I think something like in the first message would be required. On Jun 15, 4:29 pm, Rob Lachlan robertlach...@gmail.com wrote: Oh God. What broken formatting. Sorry about that. On Jun 15, 4:24 pm, Rob Lachlan robertlach...@gmail.com wrote: I think that the underive function for removing hierarchy relationships between keywords is broken. I'll illustrate with an example and describe what I think the problems are. I've got some code for a function which (I hope!) performs underive correctly, and I'd love it if people had a look. Consider a hierarchy with child-parent relationships: :c - :p1, :c - :p2, :p1 - :a1, :p1 - :a2, :p2 - :a2 Which I'll illustrate with the world's worst ascii art: a1 a2 | / | | / | | / | p1 p2 | / | / | / c ; creating this hierarchy: user (def h (reduce #(apply derive (cons %1 %2)) (make-hierarchy) [[:p1 :a1] [:p1 :a2] [:p2 :a2] [:c :p2] [:c :p1]])) #'user/h user h {:parents {:c #{:p1 :p2}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :ancestors {:c #{:p1 :p2 :a2 :a1}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :descendants {:p1 #{:c}, :p2 #{:c}, :a2 #{:p1 :p2 :c}, :a1 #{:p1 :c}}} Now the underive: user (underive h :c :p1) {:parent {:c #{:p2}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :ancestors {:c #{:p2}, :p2 #{:a2}, :p1 #{:a2 :a1}}, :descendants {:p1 #{}, :p2 #{:c}, :a2 #{:p1 :p2}, :a1 #{:p1}}} Problems: Most seriously, it is incorrect: :c should still show up as a descendant of :a2, since :c is a child of :p2, and :p2 a child of :a2. Note that the parent map is correct, so it is the ancestor and descendant maps which are inconsistent. Also, notice that the key for the parent map has changed from :parents to :parent, which causes calls to the parents function to return nil. Also, keys which map to empty sets are left in each of the maps (parents, descendants and ancestors), with the result that equality tests could fail in some cases in which they would be true. Potential fix, and request for code review: I've written an underive-new function which appears to fix these problems, at least in the tests that I've done. http://pastebin.com/eRiz5ihw My approach is to identify the sets of tags in the hierarchy whose ancestors or descendants may be
basic help with netbeans/enclojure installation
Starting from scratch, both to try it myself and to know what to tell my students in the fall, when I'll want them all (regardless of background) to be able to set up a reasonable Clojure environment without hassles. I've never previously used netbeans. I'm doing this on a Mac running MacOS 10.6.3. I tried to follow the instructions at http://www.assembla.com/wiki/show/clojure/Getting_Started_with_Netbeans_and_Enclojure and this is what happened: - Install NetBeans You need only the Java SE version. Done -- no problem. - If you’ve just installed Netbeans, activate feature Java SE: - Activate features is on the Start page - or from Tools, Plugins, Installed I don't see Activate features on the start page. Poked around (there are three tabs...) but still didn't see it. Went to Tools, Plugins, Installed and saw that there wasn't just one Java SE item but rather many. Checked all of them. Now that I return to it I see that everything has a checkmark under Active, so perhaps it was all activated initially and I didn't notice? In any event I suppose it's all activated now. - Go to the Tools, Plugins and select the 'Settings' tab on the dialog - Click Add and call the Update Center Enclojure and use the following url: http://www.enclojure.org/file/view/Autoupdate_Site.xml.gz Done -- no problem. - Go to the 'Avalilable Plugins' tab and select the Enclojure Clojure Plugin and click Install When I do it fails with the following messages: - Some plugins require plugin Common Scripting Language API (new) to be installed. The plugin Common Scripting Language API (new) is requested in version = 1.14.1.1.1.1.2 (release version 1) but only 2.5.1.2.1.1.4 (of release version different from 1) was found. The following plugin is affected: Enclojure Clojure Plugin Some plugins require plugin Editor Library to be installed. The plugin Editor Library is requested in version = 1.44.1.9.2 (release version 1) but only 2.10.1.10.2 (of release version different from 1) was found. The following plugin is affected: Enclojure Clojure Plugin Some plugins require plugin org.netbeans.modules.templates to be installed. The plugin org.netbeans.modules.templates is requested in version 1.7.1. The following plugin is affected: Enclojure Clojure Plugin Some plugins not installed to avoid potential installation problems. - And then I'm stuck. Is there a simple way to take care of this? Thanks, -Lee -- Lee Spector, Professor of Computer Science School of Cognitive Science, Hampshire College 893 West Street, Amherst, MA 01002-3359 lspec...@hampshire.edu, http://hampshire.edu/lspector/ Phone: 413-559-5352, Fax: 413-559-5438 Check out Genetic Programming and Evolvable Machines: http://www.springer.com/10710 - http://gpemjournal.blogspot.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: Serious problem with underive (for hierarchies), an attempt to fix, and request for code review.
I like the reference counting idea, YD. I don't think that we want to go that route, though, if underive will be called comparatively rarely by most people. But it would be a good way to do it if that performance were needed. Rob On Jun 15, 10:39 pm, YD ydong.pub...@gmail.com wrote: Another apporach I think would be modifying the data structure of hierarchy itself. The idea is to add a counter to ancestors and descendants. :ancestors: { :c #{ [:a1 1] [:a2 2] } } So, the counter 2 on :a2 means how many paths can you get :c to reach :a2. When the counter reaches 0, you can remove it completely. Otherwise, decrement it. This approach requires to change all the functions related to hierarchy, and the data structure will be incompatible to the original one. But the speed is gonna be fast. -- 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: basic help with netbeans/enclojure installation
Which version of NetBeans did you install? Version 6.9 (the version linked to on the netbeans.org front page) was released very recently. It's unlikely that Enclojure has been updated for NetBeans 6.9. On Jun 16, 5:29 pm, Lee Spector lspec...@hampshire.edu wrote: Starting from scratch, both to try it myself and to know what to tell my students in the fall, when I'll want them all (regardless of background) to be able to set up a reasonable Clojure environment without hassles. I've never previously used netbeans. I'm doing this on a Mac running MacOS 10.6.3. I tried to follow the instructions athttp://www.assembla.com/wiki/show/clojure/Getting_Started_with_Netbea...and this is what happened: - Install NetBeans You need only the Java SE version. Done -- no problem. - If you’ve just installed Netbeans, activate feature Java SE: - Activate features is on the Start page - or from Tools, Plugins, Installed I don't see Activate features on the start page. Poked around (there are three tabs...) but still didn't see it. Went to Tools, Plugins, Installed and saw that there wasn't just one Java SE item but rather many. Checked all of them. Now that I return to it I see that everything has a checkmark under Active, so perhaps it was all activated initially and I didn't notice? In any event I suppose it's all activated now. - Go to the Tools, Plugins and select the 'Settings' tab on the dialog - Click Add and call the Update Center Enclojure and use the following url: http://www.enclojure.org/file/view/Autoupdate_Site.xml.gz Done -- no problem. - Go to the 'Avalilable Plugins' tab and select the Enclojure Clojure Plugin and click Install When I do it fails with the following messages: - Some plugins require plugin Common Scripting Language API (new) to be installed. The plugin Common Scripting Language API (new) is requested in version = 1.14.1.1.1.1.2 (release version 1) but only 2.5.1.2.1.1.4 (of release version different from 1) was found. The following plugin is affected: Enclojure Clojure Plugin Some plugins require plugin Editor Library to be installed. The plugin Editor Library is requested in version = 1.44.1.9.2 (release version 1) but only 2.10.1.10.2 (of release version different from 1) was found. The following plugin is affected: Enclojure Clojure Plugin Some plugins require plugin org.netbeans.modules.templates to be installed. The plugin org.netbeans.modules.templates is requested in version 1.7.1. The following plugin is affected: Enclojure Clojure Plugin Some plugins not installed to avoid potential installation problems. - And then I'm stuck. Is there a simple way to take care of this? Thanks, -Lee -- Lee Spector, Professor of Computer Science School of Cognitive Science, Hampshire College 893 West Street, Amherst, MA 01002-3359 lspec...@hampshire.edu,http://hampshire.edu/lspector/ Phone: 413-559-5352, Fax: 413-559-5438 Check out Genetic Programming and Evolvable Machines:http://www.springer.com/10710-http://gpemjournal.blogspot.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: Passing Arguments From Java to Clojure
Actually, just look at the main method (for testing) which has been commented out at the bottom - that will show you a better way to create and use it. On Jun 16, 9:37 am, allie allison.terr...@gmail.com wrote: There's a canonical intro on how to call or embed Clojure into Java:http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#I... While this is a great introduction, the only thing Java passes in to Clojure here is a string. I've tried methods where Java passes in ints, and those work fine too. What I'm primarily concerned with is if there is some way to pass in a list/vector/etc, if there's a particular way to format the argument on the Java side so it can be easily converted on the Clojure side without much hassle (via vector or something similar), or if I need to just suck it up, pass in a string of numbers, and write a function on the Clojure side that handles all that. To be specific, I would like to make a vector that would end up in pairs: [[1 2] [3 4] [5 6]]. For those of you familiar with Incanter, this will then become a dataset. Thanks in advance. -- 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: Passing Arguments From Java to Clojure
Do you really need a Clojure vector-of-vectors, or do you just want an indexed collection of indexed collections? If the latter, you can simply use Java arrays, or ArrayMaps. ; build a collection a Java programmer might have made ; (I am not really going to go into Java just for an example... :-) (def x (into-array (map into-array [[1 2] [3 4]]))) = #'user/x ; function that destructures positional args (defn foo [[[a b] [c d]]] [a b c d]) = #'user/foo ; ta da (foo x) = [1 2 3 4] There's a canonical intro on how to call or embed Clojure into Java: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java While this is a great introduction, the only thing Java passes in to Clojure here is a string. I've tried methods where Java passes in ints, and those work fine too. What I'm primarily concerned with is if there is some way to pass in a list/vector/etc, if there's a particular way to format the argument on the Java side so it can be easily converted on the Clojure side without much hassle (via vector or something similar), or if I need to just suck it up, pass in a string of numbers, and write a function on the Clojure side that handles all that. To be specific, I would like to make a vector that would end up in pairs: [[1 2] [3 4] [5 6]]. For those of you familiar with Incanter, this will then become a dataset. Thanks in advance. -- 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 -- 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: Hash-map destructuring
There's a disconnect between the function definition and the datastructures used by the caller. Either fix the data structure: (def args [:bar 2 :baz [:quux]]) then use apply Or change the function definition to take a map: (defn foo [x {:keys [bar baz]}] ...) On Jun 16, 4:00 pm, Brian Carper briancar...@gmail.com wrote: Given: (defn foo [x {:as args}] [x args]) (foo 1 :bar 2 :baz [:quux]) = [1 {:bar 2, :baz [:quux]}] If I have those rest-arguments already in a map, what's the most elegant way to call foo with them? (def args {:bar 2 :baz [:quux]}) (foo 1 ?) I feel like I may be missing some simple way of doing it. I find myself needing to do this pretty often, for example any time I have a chain of functions calling each other that all take keyword arguments on the end. (apply foo 1 (apply concat (seq args))) works, but that's awfully nasty. So this is what I've been doing: (defmacro apply* [ args] `(apply ~@(butlast args) (apply concat (seq ~(last args) (apply* foo 1 args) = [1 {:bar 2, :baz [:quux]}] Kind of hacky though. Is there a better/shorter/builtin way? I can go back to using [x args] in the function signature and (apply hash-map args) in the function body, but I love having the keyword destructuring in the function signature, since the user can see which keys are valid to pass in, whenever I use {:keys [...]}. Thanks --Brian -- 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: Passing Arguments From Java to Clojure
-- CallClojure.java -- import clojure.lang.RT; import clojure.lang.Var; import clojure.lang.PersistentVector; public class CallClojure { static PersistentVector toVec(int[][] arr) { PersistentVector pv = PersistentVector.EMPTY; for (int[] a : arr) { PersistentVector temp = PersistentVector.EMPTY; for (int n : a) { temp = temp.cons(n); } pv = pv.cons(temp); } return pv; } public static void main(String[] args) throws Exception { RT.loadResourceScript(foo.clj); Var gimmie_vec = RT.var(foo, gimmie-vec); int[][] ar = {{1, 2}, {3, 4}, {5, 6}}; Object result = gimmie_vec.invoke(toVec(ar)); System.out.println(result); } } -- foo.clj -- (ns foo) (defn gimmie-vec [v] (println class: (class v)) (println v: v)) -- 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: agents sending-off to other agents blocks?
Ah thanks for pointing out release-pending-sends, I didn't know about that; it's exactly what I need in my case. On Jun 16, 2010, at 9:52 AM, YD wrote: Yeah, it's intended, just like what Ulrich showed. The same comment appears on the doc of release-pending-sends. In your case, the inner send-off doesn't rely on the result of the outter send-off. So, you can use release-pending-sends. The following code will have hey printed right away. -- 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: Hash-map destructuring
On Jun 16, 2010, at 7:07 PM, ataggart wrote: There's a disconnect between the function definition and the datastructures used by the caller. Either fix the data structure: (def args [:bar 2 :baz [:quux]]) then use apply Or change the function definition to take a map: (defn foo [x {:keys [bar baz]}] ...) That's a pretty flippant answer. I have run into this same issue; it's not always desirable to have your function take a map, and if you get the data structure from elsewhere (say loaded from a config file), then you have to resort to either re-building the arg list manually or doing (apply concat ...). Regarding Brian's original question: as far as I know, there is no built-in version of apply that works with keyword args contained in a map. But note that you can eliminate the call to seq, since (apply concat args) works the same as (apply concat (seq args)). -- 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
Problems with URL params and http-agent
Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a) http://RESTful/path/to/xml b) http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] However, using clojure, If I try the same call, d) in this case will NOT work. c) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml;) ; works d) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']) ; doesn't work I've tried url-encoding the url using the below function, but that doesn't help either. (defn url-encode [text] (URLEncoder/encode text UTF-8)) Is the something obvious I'm missing? Thanks -- 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
Recommendations on prepping a library for 1.2 release?
I guess I'm mostly wondering where to get the best (continually update-able best) version of 1.2 core (and contrib?) before it's released. I'd rather not go Lein or Maven2 - just a vanilla checkout and Ant if that's still a supported build option. Everything's on github - right? The simplest commands to grab the core (and contrib?) from github as well as the commands to keep updating every week or so until release would be fantastic. All of this is assuming, hopefully incorrectly, that there's no automated nightly JAR that's being produced and made available somewhere. Thanks! -Rich -- 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: Recommendations on prepping a library for 1.2 release?
On Wed, Jun 16, 2010 at 10:17 PM, Richard Lyman richard.ly...@gmail.comwrote: Everything's on github - right? The simplest commands to grab the core (and contrib?) from github as well as the commands to keep updating every week or so until release would be fantastic. git clone url, to get it git pull, to update it git fetch, to grab the other branches git checkout branch, to switch to a branch ant, to build the branch you are on. All of this is assuming, hopefully incorrectly, that there's no automated nightly JAR that's being produced and made available somewhere. The clojure master branch is being built continuously here, http://build.clojure.org/ David -- 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: Complex type in clojure
Thanks. It's always interesting to see different notations. On Jun 15, 4:49 pm, Travis Hoffman travis.a.hoff...@gmail.com wrote: We Electrical Engineers are quite annoying in this regard, but historically, there is much variation out there: Python uses j, MATLAB accepts i or j. Apache Commons allows the user to specify the specific character to use, but defaults to i I believe. Eventually, I would suggest this be a localizable field. Please see: http://en.wikipedia.org/wiki/Imaginary_unit#Alternative_notations -Travis On Jun 15, 4:22 pm, James Reeves jree...@weavejester.com wrote: On 15 June 2010 23:26, Carson c.sci.b...@gmail.com wrote: Sorry I may have missed the reason for this earlier: What's the reason for allowing both 'i' and 'j' to indicate the imaginary part? Is the intention to also later have 'k' to support quaternions? Just curious. Thanks. j is used by electrical engineers to represent the imaginary part of a complex number, because I has already been taken to mean electrical current. Presumably this is the reason. - James -- 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: Recommendations on prepping a library for 1.2 release?
On Wed, Jun 16, 2010 at 8:36 PM, David Nolen dnolen.li...@gmail.com wrote: On Wed, Jun 16, 2010 at 10:17 PM, Richard Lyman richard.ly...@gmail.com wrote: Everything's on github - right? The simplest commands to grab the core (and contrib?) from github as well as the commands to keep updating every week or so until release would be fantastic. git clone url, to get it git pull, to update it git fetch, to grab the other branches git checkout branch, to switch to a branch ant, to build the branch you are on. Do I need any branches? What are the branches? I thought that when a branch was stable it would be merged back into master (if I'm using the right terms). All of this is assuming, hopefully incorrectly, that there's no automated nightly JAR that's being produced and made available somewhere. The clojure master branch is being built continuously here, http://build.clojure.org/ When you say master branch, do you mean just core, or does that include contrib? Speaking of which: Should I still care about contrib? I remember hearing that several items had been merged into core... David Thanks for the quick and succinct response. -Rich -- 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: Recommendations on prepping a library for 1.2 release?
On Wed, Jun 16, 2010 at 11:34 PM, Richard Lyman richard.ly...@gmail.comwrote: On Wed, Jun 16, 2010 at 8:36 PM, David Nolen dnolen.li...@gmail.com wrote: On Wed, Jun 16, 2010 at 10:17 PM, Richard Lyman richard.ly...@gmail.com wrote: Everything's on github - right? The simplest commands to grab the core (and contrib?) from github as well as the commands to keep updating every week or so until release would be fantastic. git clone url, to get it git pull, to update it git fetch, to grab the other branches git checkout branch, to switch to a branch ant, to build the branch you are on. Do I need any branches? What are the branches? I thought that when a branch was stable it would be merged back into master (if I'm using the right terms). Yes master is the stable branch. Branches besides master are often where new work is being done - some of which might get merged back into master. You don't need them, but Rich Hickey is pretty good at putting really interesting and very serious work into a branch. For example the prim and num branches have some stunning performance improvements for code that relies on fast arithmetic. All of this is assuming, hopefully incorrectly, that there's no automated nightly JAR that's being produced and made available somewhere. The clojure master branch is being built continuously here, http://build.clojure.org/ When you say master branch, do you mean just core, or does that include contrib? Speaking of which: Should I still care about contrib? I remember hearing that several items had been merged into core... Hudson has builds of clojure as well as clojure-contrib. There's plenty of interesting stuff going on in clojure-contrib. David -- 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: Recommendations on prepping a library for 1.2 release?
Do I need any branches? What are the branches? I thought that when a branch was stable it would be merged back into master (if I'm using the right terms). The master branch for clojure is the main development branch for 1.2 (someone correct me if I'm wrong). It's the one I'm using, and I'm also using 1.2. There are other branches, like num, if you want efficient numerical computations. In all likelihood, master is what you want. When you say master branch, do you mean just core, or does that include contrib? Core has its master branch, and contrib has its own master branch. Speaking of which: Should I still care about contrib? I remember hearing that several items had been merged into core... Probably you should, contrib has tons of other goodness. See http://richhickey.github.com/clojure-contrib/ for details. Rob -- 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
Leiningen documentation review?
I'm pushing for a Leiningen 1.2.0 release really soon now, and part of that effort is sprucing up the documentation. I've revamped the readme and added a tutorial for folks just getting started. Of course, self-editing is never as good as having outside help, so I'd love it if I could get some feedback on it. I'm particularly interested in opinions from people who are just starting out with Clojure--it's easy for me to take things for granted that not everyone understands. Mostly I'd like feedback on the tutorial: http://github.com/technomancy/leiningen/blob/master/TUTORIAL.md But if you've got some time to look over the readme, that would be great too: http://github.com/technomancy/leiningen/blob/master/README.md Thanks! -Phil -- 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: Recommendations on prepping a library for 1.2 release?
On Wed, Jun 16, 2010 at 8:34 PM, Richard Lyman richard.ly...@gmail.com wrote: All of this is assuming, hopefully incorrectly, that there's no automated nightly JAR that's being produced and made available somewhere. The clojure master branch is being built continuously here, http://build.clojure.org/ When you say master branch, do you mean just core, or does that include contrib? Speaking of which: Should I still care about contrib? I remember hearing that several items had been merged into core... You can't build contrib without Maven these days. But unless you're directly hacking on Clojure or Contrib itself, there's very little reason to build it yourself; you should get along fine with downloading the jar files straight from http://build.clojure.org/snapshots You can get a lot further without contrib than you used to be able to--several seq functions have been moved to clojure.core, and clojure.contrib.duck-streams has been moved to clojure.java.io. -Phil -- 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: basic help with netbeans/enclojure installation
You can easily download old releases of NetBeans. From the netbeans.orgfront page click on Download FREE. On that page click on Archive in the upper right corner. Finally look for the version select box on the right side of the page. IANAL, but I believe the license of each project allows you to distribute the compatible versions together via your class's website or CDs that you hand out in class, etc. On Wed, Jun 16, 2010 at 6:05 PM, Lee Spector lspec...@hampshire.edu wrote: I'm using NetBeans 6.9, which is just what happened to be there when I went to try this today. Maybe I should be trying a different environment if this is going to depend on the netbeans version or require more manual installation. I'm hoping to find something that doesn't require manual git pulls or jumping through other hoops, in part because I'll be using it with students who'll have to set up on their own machines and I want that to be painless. Minimum functionality is a REPL and an editor with Clojure indentation and parentheses matching. Other stuff like debugging/profiling/builtin-documentation would be great but if I can get the minimum with a no-hassle installation then I'll be happy, and the no-hassle installation part is really the most important thing. I'm personally using an emacs setup but that installation was not hassle free and I don't want to make my students learn emacs anyway. Last time I tried the Eclipse route it wasn't too bad but I found the environment confusingly complex and there wasn't Clojure indentation, which I think is really necessary. Ideally I'll use something cross platform, but I might use MCLIDE if it's the best thing going -- last I tried it it still required jumping through some hoops and didn't seem quite ready for prime time yet. Any advice would be appreciated. Thanks, -Lee On Jun 16, 2010, at 6:46 PM, Stefan Kamphausen wrote: Hi, On Jun 17, 12:29 am, Lee Spector lspec...@hampshire.edu wrote: - Go to the 'Avalilable Plugins' tab and select the Enclojure Clojure Plugin and click Install When I do it fails with the following messages: - Some plugins require plugin Common Scripting Language API (new) to be installed. I had some very similar problems some weeks ago, when I tried this, too. At that time I used Netbeans 6.7 and 6.9 wasn't yet released. After I installed Netbeans 6.8 things went almost smooth. I had to do a manual git pull in the created labrepl project. After that it's justing waiting for Maven to finish which took *quite* a while with my slow connection at home. I could even use the debugger to step clojure programs (after using that funny/ugly trick with a dummy java class). Cheers, Stefan -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Lee Spector, Professor of Computer Science School of Cognitive Science, Hampshire College 893 West Street, Amherst, MA 01002-3359 lspec...@hampshire.edu, http://hampshire.edu/lspector/ Phone: 413-559-5352, Fax: 413-559-5438 Check out Genetic Programming and Evolvable Machines: http://www.springer.com/10710 - http://gpemjournal.blogspot.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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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