Adding Classpaths On The Fly
Hi, I'm trying to add a classpath to the current Clojure REPL session on the fly. (Particularly, I extracted shcloj-code.tgz of Programming Clojure to /tmp/code directory, and trying to load /tmp/code/examples/snake.clj file.) For this purpose, I tried below two steps with no luck. - (System/setProperty "java.class.path" (str (System/getProperty "java.class.path") ":/tmp/code")) - (add-classpath "file:///tmp/code") But after both tries Clojure complains that "Could not locate examples/snake__init.class or examples/snake.clj on classpath". Am I missing something obvious, or it's not possible to introduce new classpaths on the fly? BTW, after (add-classpath "file:///tmp/code") call, (System/getProperty "java.class.path") appears to be unchanged. Is that something expected? Regards. --~--~-~--~~~---~--~~ 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: Adding Classpaths On The Fly
For the record, I'm forwarding below reply from Stuart Sierra. On Fri, 25 Sep 2009, Stuart Sierra writes: > On Sep 25, 3:02 am, Volkan YAZICI wrote: >> - (System/setProperty >>"java.class.path" >>(str (System/getProperty "java.class.path") >> ":/tmp/code")) > > The "java.class.path" system property is read-only. And in the > context of dynamic ClassLoaders (like Clojure's) it's largely > meaningless. > >> - (add-classpath "file:///tmp/code") > > add-classpath does not work in some environments and may be removed in > future versions of Clojure. > > Bottom line: you can't dynamically change the Java classpath. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
"ensure" Usage
Hi, Can anybody give an example to the usage of "ensure". I couldn't figure out what exactly it does from its documentation string. Regards. --~--~-~--~~~---~--~~ 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: Memory Characteristics of Persistent Datastructures
On Sun, 4 Oct 2009, Elliott Slaughter writes: > You're right, it was a memory leak, although it took me hours to find. > Clojure's lazy lists were responsible for the leak; I wasn't honestly > expecting this innocent looking code to be so insidious > > (defn leak [] > (loop [v [0 0]] > (recur (map + v [1 1] > > Adding a doall call fixed the leak. Could you please provide a more concrete (if possible working) example? I'm trying to figure out the actual reason of the problem, and there are still some missing parts in the maze. Regards. --~--~-~--~~~---~--~~ 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: Printing to *out* in another thread
On Sat, 17 Oct 2009, mbrodersen writes: > If you want to print to stdout from multiple threads without getting > the printing garbeled you can do something like the following (it also > logs all printed values): > > (def wa-debug-agent) > > (defn wa-debug-make [] > (def wa-debug-agent (agent []))) > > (defn wa-debug-print > "This makes it possible to print from multiple threads without > overlapping each other" > [& args] > (send wa-debug-agent > (fn [list v] > (apply println v) > (conj list v)) args)) Here is another variant using atoms instead. (defn serial-println [_ _ _ args] (apply println args) (flush)) ; #'user/serial-println (def serial-stream (atom nil)) ; #'user/serial-stream (add-watch serial-stream :default serial-println) ; # (defn serial-enqueue [& args] (swap! serial-stream (fn [_] args))) ; #'user/serial-enqueue (def sprintln serial-enqueue) ; #'user/sprintln (dotimes [i 10] (.run (Thread. #(let [d (rand-int 2000)] (Thread/sleep d) (sprintln "Id:" i "Duration:" d) ; Id: 0 Duration: 1228 ; Id: 1 Duration: 1067 ; Id: 2 Duration: 893 ; Id: 2 Duration: 893 ; Id: 3 Duration: 1482 ; Id: 4 Duration: 1514 ; Id: 5 Duration: 79 ; Id: 6 Duration: 1966 ; Id: 7 Duration: 730 ; Id: 8 Duration: 1489 ; Id: 9 Duration: 1919 Regards. --~--~-~--~~~---~--~~ 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: data structures for efficient range queries
On Mon, 19 Oct 2009, nchubrich writes: > I need to make a data structure for a query such as "find everything > that is priced $3.27 - $6.12" (and perhaps sum up the total revenue > for all items in that price range). The naive way would be to make an > array with one slot for each increment in the entire range, and have > each slot pointing to a bucket with all items at that increment (here, > price). But this would not be terribly efficient or feasible over > very large ranges (imagine you wanted to query both large and small > ranges: think of distances on a galactic, planetary, continental, > city, human, etc. scale. Do you make multiple indices for coarse- > grained and small-grained queries? Do you have coarse-grained slots > pointing to smaller ranges, and so on ad infinitum? But that would > seem to make evaluating large ranges very inefficient). Is there a > cleverer/Clojurisher way to do it? The price example is what I'm > doing, so I don't really need a galactiscalable data structure I think what you are after is an interval tree[1] data structure. You might find a suitable Java library or implement yours easily. Regards. [1] http://en.wikipedia.org/wiki/Interval_tree --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
BILFP User Group
Hi, Would anybody mind adding BILFP[1] (Bilkent University Comp. Eng. Dept. Functional Programming Society) to the "Clojure User Groups" page[2], please? Regards. [1] http://bilfp.wikidot.com/ [2] http://clojure.org/community -- 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
Floyd-Warshall's APSP (All-Pairs-Shortest-Path) Algorithm
Hi, In case of need, here[1] is an optimized version of Floyd-Warshall's APSP (All-Pairs-Shortest-Path) algorithm in Clojure. Regards. [1] http://paste.lisp.org/display/95370 -- 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
Reflection Warning Output in SLIME
Hi, When I compile an expression via C-c C-c in SLIME -- assuming *warn-on- reflection* is turned on -- reflection related warnings don't appear neither in the REPL, nor in the inferior lisp buffer. Everytime, I have to paste the code the REPL manually. Any solutions? Regards. -- 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: apply-ing Java methods
See memfn in Clojure API docs. -- 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: Clojure for financial applications
On Mar 7, 6:35 pm, jshore wrote: > Wondering whether anyone has done something very complex in the algo > space or comparable so can get an idea of how this sort of stuff is > structured idiomatically. I will also be concerned with performance > and memory use, as one of my strategies creates a few thousand sub- > strategies and/or also uses massive matrices that get updates from > tick to tick. Recently, I have been using Clojure to implement a model we introduced related with hypergraphs. For this purpose, most of the heavy work is done in C libraries (JNA is quite easy to use) and pure Java libraries (thanks to Java interop.), hence no problems so far. And Clojure supplies a cool interface to pure Java arrays (int-array, float-array, etc.) in a relatively reasonable way. But AFAIK, there is no way to use multi-dimensional arrays (i.e. int[][]) asis in Clojure. (I might be missing something about this, folks told that there are no real multi-dimensional arrays in Java either.) And it is a PITA to write imperative code in Clojure, and most algorithms are written in an imperative style. (You know, "for (i = k; i < c; i++) ..." loops everywhere.) But it is not hard to implement a few utility macros for yourself. (Hrm... A contrib library would be really awesome.) Moreover, Clojure data structures and their J2SE suplements really eases your work -- think all industrial quality set, list, priority queue, etc. implementations. To sum up, I must admit that Clojure (or more generally speaking, Lisp) stands as a quite effective tool to bridge between algorithms. Regards. -- 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: Clojure for financial applications
On Mar 8, 8:22 pm, Jonathan Shore wrote: > It is a shame to have to dive down to Java or native (perhaps with the > exception of some of the massive numerical libraries one does not want to > rewrite). I'm hoping to use Clojure or something like clojure as a complete > replacement. Shame? Isn't most of us here for Clojure's access to a vast amount of industrial strength Java libraries in the wild? In your case writing pure Clojure code can be an option, but in my case it really is easier (and effective) to make code reuse. OTOH, so mentioned native binaries don't have open source equivalents, hence I'm stucked to them. > Well, I imagine one could at least write matrix-style access in terms of a > single dim array (as is done in many languages). One could write a set of > functions that work on a binding of an array with dimension. That's what I do at the moment, but support for multi-dimensional arrays would be more appropriate, IMHO. > For the sake of understanding, I'm not yet clear on how one *efficiently* > binds multiple "pieces" of state together in clojure. How would one create a > simple matrix for example where I want to bind dimension and a float-array > into a tightly bound structure. I can see that a assoc / map could be used > (but has undesireable overhead) or perhaps a closure with the array, > dimensions, and a returning function for access? For instance, consider a matrix decomposition scheme where you need to keep the track of index mappings between transformations. In C/Java, I'd have lots of dummy objects/functions around, messy for loops, allocation/release stuff, etc. But in Lisp, map/reduce/filter family, lambdas, and some glue code via macros, etc. makes your code damn easy to read/maintain and introduce new features. Moreover, mutable data structures (I have thin gateway between Clojure vectors and native Java vectors) helps me to exploit code in a functional way, no need to worry for matrix index mangling problems. > Hmm, if it is to be a bridge, then could just as well consider jruby. jruby > has many of the lisp constructs and conveniences. In fact there is now a > ruby subset called Duby which provides java-level performance by doing type > inference (or by using type annotations). Just use the language you are most comfortable at. In my situation, access to foreign Java libraries, immutable data structures, Lisp inheritance (macros, lambdas, closures, etc.) dominates here. YMMV. Regards. -- 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: problems with slime and emacs
On Oct 31, 5:59 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I'm struggling to get slime and emacs to work together. I copied the > code from the readme included with swank-clojure, but am running into > an error. Just for the records, there are some problems with both swank-clojure code and README instructions. I've sent a mail to its author with appropriate bug reports and fixes, but no replies yet. Anyway, here are my foundings. - One must specify SWANK-CLOJURE-JAR-PATH and SWANK-CLOJURE-JAR-PATH variables before calling (require 'swank-clojure-autoload). (It'd also be good to mention about SWANK-CLOJURE-JAVA-PATH in the README.) - SWANK-CLOJURE-CMD fails for relative paths. See http://paste.lisp.org/display/69530 for a fixed version. (I tweaked error message too. See documentation of ERROR.) I hope above points would help to others as well. Regards. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure documentation via mind map diagram
On Oct 31, 9:06 am, bc <[EMAIL PROTECTED]> wrote: > On my blog, I've posted an alternative way to navigate the Clojure > documentation:http://bc.tech.coop/blog/081031.html While this is being said, does Rich Hickey consider switching the pages on the Clojure website to a more consistent documentation format? (Let's not start a war between LaTeX vs. DocBook vs. Texi. I'm ok with any such scheme, as long as there is a scheme.) In this way, people will be able to download the documentation and convert it to any appropriate format (e.g PDF for printing) they desire. OTOH, it'll open the way for people to contribute to the documentation by patches, etc. Regards. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: problems with slime and emacs
On Nov 1, 4:47 am, Chanwoo Yoo <[EMAIL PROTECTED]> wrote: > Hi. With a latest version of slime, I can not make slime working > properly with clojure on Mac(Leopard). I tried it as instructions of > clojure wiki, a readme file in swank-clojure, and emacs/slime/clojure > tutorial on ubuntu, but in the every case, slime shows some error > messages. > > When I type m+x run-clojure, a user prompte appears with errors: > > (clojure/add-classpath "file:Users/chanwoo/Documents/lisp/clojure/ > swank-clojure/") > > (clojure/require (quote > swank)) > > (swank/ignore-protocol-version "2008-10-31") > > (swank/start-server "/var/folders/Zc/ZcIgibUaGyWC8sCN4S4Y9TI/-Tmp-/ > slime.33346" :encoding "iso-latin-1-unix") > > Clojure > user=> > nil > user=> java.lang.Exception: Unable to resolve symbol: *1 in this > context > clojure.lang.Compiler$CompilerException: core.clj:124: Unable to > resolve symbol: *1 in this context AFAIK, you should be using Clojure compiled from the most recent SVN sources, not release tarballs. Regards. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---