Re: How to override .toString for a struct?
On Sep 22, 2:23 am, Jung Ko wrote: > Hi, > > Can someone teach me how I can override the "toString" method for a struct ? > > Here's a code snippet that shows what I'm trying to do: > > user> (defstruct bookinfo :book :filename) > user> (struct bookinfo "hello" "world") => {:book "hello", :filename "world"} > > I would like to override the "toString" method on a struct so that the > following behavior is true: > > user> (struct bookinfo "hello" "world") => "hello" > > In Common Lisp, I would simply define a method on (print-object). What > would be the equivalent thing in Clojure? As Mike said, it's done by adding a method to print-method, but you will need metadata... "structs" in clojure are nothing but an optimisation of maps... That is, in all situations structmaps are (at least, should be) interchangeable with a regular persistent map. They do not create their own type or anything, so you can't override their toString method directly. However, since print-method uses :type metadata, you can do the following: ;; using ::foo to get namespace-qualified keywords is good for type tags, because it avoids collisions ;; typed-book could be a struct-map, or in fact any implementation of Map that also supports metadata (def typed-book (with-meta {:book "somebook"} {:type ::my-book})) ; the latter map is the metadata (defmethod print-method ::my-book [thebook writer] (print-method (:book thebook) writer)) ; falls back to the string writer (print typed-book) ; prints 'somebook' --~--~-~--~~~---~--~~ 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: Applying Java methods.
On Sep 21, 11:35 pm, pmf wrote: > On Sep 21, 11:22 pm, sross wrote: > > > I'm looking for a bit of advice for calling a java method which has a > > few different signatures (such as Connection.prepareStatement). > > Is there a cleaner way of passing a variable number of arguments to > > the method, such as > > > (apply (memfn prepareStatement) (sql/connection) args) > > Java's vararg-methods accept an array of Objects; try if this works: > (.prepareStatement (sql/connection) sql (into-array Object [arg1 arg2 > arg3]) Yes. Unfortunately prepareStatement isn't a varargs method but 3 methods with differing signatures so this approach cannot be used here. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
-> with anonymous functions
Hi there! Lets assume I have this map: user=> (def person {:name "Father" :childs [{:name "Son" :age 10}]}) Testing: user=> (-> person :childs first) {:name "Son", :age 10} Now lets filter the child map: user=> (def only-name (fn [m] (select-keys m [:name]))) user=> (-> person :childs first only-name) {:name "Son"} So why does this not work?: user=> (-> person :childs first (fn [m] (select-keys m [:name]))) java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol (NO_SOURCE_FILE:59) Or this?: user=> (-> person :childs first #(select-keys % [:name])) java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector (NO_SOURCE_FILE:60) --~--~-~--~~~---~--~~ 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: -> with anonymous functions
Hi Roman! On Tue, Sep 22, 2009 at 2:58 PM, Roman Roelofsen < roman.roelof...@googlemail.com> wrote: > > Hi there! > > Lets assume I have this map: > > user=> (def person {:name "Father" :childs [{:name "Son" :age 10}]}) > > Testing: > > user=> (-> person :childs first) > {:name "Son", :age 10} > > Now lets filter the child map: > > user=> (def only-name (fn [m] (select-keys m [:name]))) > user=> (-> person :childs first only-name) > {:name "Son"} > > So why does this not work?: > > user=> (-> person :childs first (fn [m] (select-keys m [:name]))) > java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't > know how to create ISeq from: Symbol (NO_SOURCE_FILE:59) > because -> put its firs t argument in second position into its second argument: (-> foo (fn [x] x)) becomes (fn foo [x] x) user=> (macroexpand-1 '(-> foo (fn [x] x))) (fn foo [x] x) Or this?: > > user=> (-> person :childs first #(select-keys % [:name])) > java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to > clojure.lang.IPersistentVector (NO_SOURCE_FILE:60) > Ditto. At read time, #(...) expand to seomething like (fn [x] (...)). One usual albeit somewhat ugly workaround is to put another pair of parens around the fn user=> (macroexpand-1 '(-> foo ((fn [x] x ((fn [x] x) foo) HTH, Christophe --~--~-~--~~~---~--~~ 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: -> with anonymous functions
On Sep 22, 3:58 pm, Roman Roelofsen wrote: > Hi there! > > Lets assume I have this map: > > user=> (def person {:name "Father" :childs [{:name "Son" :age 10}]}) > > Testing: > > user=> (-> person :childs first) > {:name "Son", :age 10} > > Now lets filter the child map: > > user=> (def only-name (fn [m] (select-keys m [:name]))) > user=> (-> person :childs first only-name) > {:name "Son"} > > So why does this not work?: > > user=> (-> person :childs first (fn [m] (select-keys m [:name]))) > java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't > know how to create ISeq from: Symbol (NO_SOURCE_FILE:59) > > Or this?: > > user=> (-> person :childs first #(select-keys % [:name])) > java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to > clojure.lang.IPersistentVector (NO_SOURCE_FILE:60) You assume more of -> than you should :) -> does not take functions as parameters. It only sees a bunch of symbols, as it is a macro, which means it does a code transformation. It puts the first form (the symbol person) in the second position of the following form (the keyword :childs), which must be a sequence, or if it is not, is wrapped in a list first. This repeats recursively until there are no more forms left. Now, the anonymous function example fails because (-> person :childs first (fn [] whatever)) transforms into (fn (first (:childs person)) x [] y). which is not what you intended, but nonetheless a correct result. If you look at the examples that work and macroexpand them, you would see that (-> person :childs first) transforms first into (-> (:childs person) first) and from there to (first (:childs person)) which happens to be a valid Clojure expression --~--~-~--~~~---~--~~ 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: Applying Java methods.
On Mon, Sep 21, 2009 at 5:22 PM, sross wrote: > > Hi All, > > I'm looking for a bit of advice for calling a java method which has a > few different signatures (such as Connection.prepareStatement). > Is there a cleaner way of passing a variable number of arguments to > the method, such as > > (apply (memfn prepareStatement) (sql/connection) args) > > or is doing something like the following the only approach. > > (defn prepare-statement > ([sql] (.prepareStatement (sql/connection) sql)) > ([sql arg] (.prepareStatement (sql/connection) sql arg)) > ([sql arg arg2] (.prepareStatement (sql/connection) sql arg arg2)) > ([sql arg arg2 arg3] (.prepareStatement (sql/connection) sql arg > arg2 arg3))) Your solution will provide the best performance (you may need to type-hint the args). If performance doesn't matter, you can use Rich's jcall fn: (defn jcall [obj name & args] (clojure.lang.Reflector.invokeInstanceMethod obj (str name) (if args (to-array args) (clojure.lang.RT.EMPTY_ARRAY Then you could: (defn prepare-statement [& args] (apply jcall (sql/connection) "prepareStatement" args)) Note that uses runtime reflection, array creation, etc. each time it's called. You can expect it to be at least an order of magnitude slower than if it were directly compiled like your original solution could be. --Chouser --~--~-~--~~~---~--~~ 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: -> with anonymous functions
Thanks for the explanation! So the solution is much simpler: user=> (-> person :childs first (select-keys [:name])) {:name "Son"} Cool :-) On Sep 22, 3:26 pm, Jarkko Oranen wrote: > On Sep 22, 3:58 pm, Roman Roelofsen > wrote: > > > > > Hi there! > > > Lets assume I have this map: > > > user=> (def person {:name "Father" :childs [{:name "Son" :age 10}]}) > > > Testing: > > > user=> (-> person :childs first) > > {:name "Son", :age 10} > > > Now lets filter the child map: > > > user=> (def only-name (fn [m] (select-keys m [:name]))) > > user=> (-> person :childs first only-name) > > {:name "Son"} > > > So why does this not work?: > > > user=> (-> person :childs first (fn [m] (select-keys m [:name]))) > > java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't > > know how to create ISeq from: Symbol (NO_SOURCE_FILE:59) > > > Or this?: > > > user=> (-> person :childs first #(select-keys % [:name])) > > java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to > > clojure.lang.IPersistentVector (NO_SOURCE_FILE:60) > > You assume more of -> than you should :) > -> does not take functions as parameters. It only sees a bunch of > symbols, as it is a macro, which means it does a code transformation. > It puts the first form (the symbol person) in the second position of > the following form (the keyword :childs), which must be a sequence, or > if it is not, is wrapped in a list first. This repeats recursively > until there are no more forms left. > Now, the anonymous function example fails because (-> person :childs > first (fn [] whatever)) transforms into (fn (first (:childs person)) x > [] y). which is not what you intended, but nonetheless a correct > result. > > If you look at the examples that work and macroexpand them, you would > see that (-> person :childs first) transforms first into (-> (:childs > person) first) and from there to (first (:childs person)) which > happens to be a valid Clojure expression --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
Hi, thanks a lot. Your code looks much better than mine. But there is one part that I don't understand: (defn producer [] (if (dosync (if (not @consuming) (alter data conj 1))) (recur))) How can I be sure that no more data is added to data after @consuming was set to true ? Regards Roger --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Managing Clojure project files
Hello All, Please make out time and check the below link. And if you consider the code there useful, I encourage you to use it. I would appreciate your comments and reviews. http://emekamicro.blogspot.com/2009/09/managing-clojure-project-files.html Regards, Emeka --~--~-~--~~~---~--~~ 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: Q: How to convert a struct-map to xml and back (ignoring functions)?
Thanks for the link. It's a good start and it has prodded me to start analyzing clojure core and contrib code - which I'm finding are incredibly good examples of how to do 'stuff'. --~--~-~--~~~---~--~~ 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: Q: How to convert a struct-map to xml and back (ignoring functions)?
Clojure data structures can be printed to a string, and the string can be read back in as a data structure. user> (def a {:key1 "string" :key2 #{"set" "of" "strings"}}) #'user/a user> a {:key1 "string", :key2 #{"set" "strings" "of"}} user> (def b (str a)) #'user/b user> b "{:key1 \"string\", :key2 #{\"set\" \"strings\" \"of\"}}" user> (def c (read-string b)) #'user/c user> c {:key1 "string", :key2 #{"set" "strings" "of"}} user> (= a c) true --~--~-~--~~~---~--~~ 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: Managing Clojure project files
Sweet! I'd like to try it out. Wondering, though, might blogspot have a feature of some sort to render the code in something more palatable? I'd like to review it but it's a pain. Thanks, On 9/22/09, Emeka wrote: > Hello All, > > Please make out time and check the below link. And if you consider the code > there useful, I encourage you to use it. > I would appreciate your comments and reviews. > > http://emekamicro.blogspot.com/2009/09/managing-clojure-project-files.html > > Regards, > Emeka > > > > -- John --~--~-~--~~~---~--~~ 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: How to override .toString for a struct?
On Tue, Sep 22, 2009 at 1:31 AM, Jarkko Oranen wrote: > As Mike said, it's done by adding a method to print-method, but you > will need metadata... "structs" in clojure are nothing but an > optimisation of maps... That is, in all situations structmaps are (at > least, should be) interchangeable with a regular persistent map. They > do not create their own type or anything, so you can't override their > toString method directly. > > However, since print-method uses :type metadata, you can do the > following: > > ;; using ::foo to get namespace-qualified keywords is good for type > tags, because it avoids collisions > ;; typed-book could be a struct-map, or in fact any implementation of > Map that also supports metadata > (def typed-book (with-meta {:book "somebook"} {:type ::my-book})) ; > the latter map is the metadata > (defmethod print-method ::my-book [thebook writer] > (print-method (:book thebook) writer)) ; falls back to the string > writer > > (print typed-book) ; prints 'somebook' Thank you Mike and Jarkko for the detailed answer. It works as you described. :) Sincerely, Jung Ko --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
Hi, I gave it a try to find a solution to your problem. I ended up using a single atom to hold the produced data and as means to detect that consuming started (by swapping in a fn wrapping the produced value). Don't know wether this fits your problem better than the one already posted. (def data (atom [])) (defn produce [data-atom] (Thread/sleep 100) (when (vector? (swap! data #(if (vector? %) (conj % :foo) %))) (recur data-atom))) (defn consume [data-atom] ((swap! data-atom #(if (vector? %) (fn [] %) % (defn produce-consume-test [] (dotimes [n 100] (future-call #(produce data))) (Thread/sleep 1000) (consume data)) (do (swap! data (constantly [])) (count (produce-consume-test))) --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
> thanks a lot. Your code looks much better than mine. But there is one > part that I don't understand: > > (defn producer [] > (if (dosync (if (not @consuming) >(alter data conj 1))) >(recur))) > > After rereading the docs several times It seems that I begin to understand how this works. The values of the vars inside a dosync block are determined when the dosync block starts. This makes it impossible that @consuming changes after the dosync block is entered. True ? The remaining question is: Is it possible that data is added to data after the consumer is started ? Regards Roger --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
On Tue, Sep 22, 2009 at 3:18 PM, Roger Gilliar wrote: > >> thanks a lot. Your code looks much better than mine. But there is one >> part that I don't understand: >> >> (defn producer [] >> (if (dosync (if (not @consuming) >> (alter data conj 1))) >> (recur))) >> > After rereading the docs several times It seems that I begin to > understand how this works. The values of the vars inside a dosync > block are determined when the dosync block starts. This makes it > impossible that @consuming changes after the dosync block is entered. > > True ? No, that's not true. consuming is a Ref. Refs maintain a chain of their historical values. Inside a transaction when the value of a Ref is needed, the Ref finds its newest value in the chain that was set before the transaction started. So it doesn't have to do this when the transaction starts. It waits until the value is actually needed. For more details on this, see http://ociweb.com/mark/stm/article.html. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
> How can I be sure that no more data is added to data after @consuming > was set to true ? You need to prevent the modification of consuming by using ensure rather than deref (@). --~--~-~--~~~---~--~~ 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: Q: How to convert a struct-map to xml and back (ignoring functions)?
Thanks for the note about read-string and the example. If I only had to consider Clojure I'd probably use that. The Clojure structures are going to be persisted to/from a DB, and then also read back (and maybe updated) later using other languages. The tools I prefer to use for this are based on XML, but I can also use JSON. I have since found clojure.contrib.json.[read,write] and that works fine. Cheers. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
an article about Clojure on IBM DeveloperWoks
An article about Clojure on IBM DeveloperWoks http://www.ibm.com/developerworks/opensource/library/os-eclipse-clojure/index.html --~--~-~--~~~---~--~~ 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: an article about Clojure on IBM DeveloperWoks
Thanks for the links, we - Counterclockwise / clojure-dev devs - were not aware that some publicity was made for Counterclockwise on IBM DeveloperWorks ! That's cool ! Regards, -- Laurent 2009/9/23 Alpinweis > > An article about Clojure on IBM DeveloperWoks > > http://www.ibm.com/developerworks/opensource/library/os-eclipse-clojure/index.html > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Namespace/class visibility in eval
I'm trying to create an HTTP server that is essentially a clojure REPL with some integration into some classes on the server's classpath. I've got something working, but I noticed some things that made me realize I don't quite understand the scope of namespaces/imports in clojure when eval'ing. If anyone can shed some light on what's happening and why, it would be great. I'm using compojure to do my HTTP and the server right now looks like: (ns my.namespace.hello-world (:use compojure) (:use clojure.contrib.duck-streams) (:use clojure.contrib.json.write) (:import java.io.InputStreamReader) (:import java.io.PushbackReader) (:import (org.joda.time Interval DateTime))) (defroutes evallerificator (POST "/1.0/cloj" (eval (read (PushbackReader. (InputStreamReader. (request :body)) (GET "/" (html [:h1 "Hello World"])) (ANY "*" (page-not-found))) (run-server {:port 43034} "/*" (servlet evallerificator)) This works if I curl something like: curl -v 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d '(str (+ 1 2))' But, if I want to, say, output something in JSON format I have to write curl 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d '(clojure.contrib.json.write/json-str {:howdy ["hi" 1 2 3]})' {"howdy":["hi",1,2,3]} If I do just curl 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d '(json-str {:howdy ["hi" 1 2 3]})' I get this exception java.lang.Exception: Unable to resolve symbol: json-str in this context (NO_SOURCE_FILE:0) Something like this curl -v 'http://localhost:43034/1.0/cloj' -H 'content-type: application/clojure' -d "(require 'clojure.contrib.json.write) (json-str {:howdy [\"hi\" 1 2 3]})" Doesn't work because I'm only read/eval'ing one thing. My goal is to be able to use things on the classpath from the clojure code that I pass in. It would be nice if I had control of what someone could require/use, but at this point I'm willing to settle for access to anything and everything on the classpath. Any help is appreciated. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
New Release for Enclojure plugin - 2009-09-22
New release of the Enclojure plugin for Netbeans has been released! I have moved Enclojure to github and greatly simplified the build process. See readme in the root directory of the repo for more details. http://github.com/EricThorsen/enclojure You can download the release at: http://github.com/EricThorsen/enclojure/downloads This release was primarily focused on bug fixes particularly on Ubuntu and Windows with a few enhancements to completion. Thanks again to everyone who has provided guidance and feedback! Eric git log 3 hours ago, Added a testing file for completion-task 4 hours ago, Fixed a completion bug where the context was getting confused in some cases causing no symbols to be suggested at all. 5 hours ago, Fixed a completion bug when there was no context. 28 hours ago, Added an interface for REPL history to de-couple the repl-history from the specific IDE. Moved the generic prefs utilities into the ide project out of the Netbeans specific stuff. 31 hours ago, Moved enclojure preferences under the .netbeans dir 31 hours ago, Moved enclojure preferences under the .netbeans dir 32 hours ago, Fixed bugs on project creation and new source file support on Windows 33 hours ago, Fixed a let bug... 2 days ago, Changed the default home dir to use the netbeans dir. 4 days ago, Fixed a nasty bug in the form parser when there was an unreadble form in a source file. 5 days ago, Added docs to the completion 5 days ago, nothing changed? 5 days ago, Took out a temporary log statement in the launcher. 6 days ago, Added support for inter-project dependancies for the REPL. 6 days ago, Fixed several timing issues with the configuration settings and starting/stopping various REPLs. 6 days ago, Fixed the problem related to the *1,*,2*3,*e vars not being bound when pretty printing was enabled. 7 days ago, Working towards fixing the *1,*2,*3 binding issue when pretty printing is enabled. 7 days ago, Merge branch 'bugfix' 7 days ago, Merge branch 'master' of g...@github.com:EricThorsen/ enclojure 7 days ago, Added a readme for building enclojure. 7 days ago, Added the new clojure platform to the layer.xml file. 8 days ago, Added the later clojure and clojure-contrib libs to the deps.zip and modified the build to use deps.zip 11 days ago, Continuing to work on added the embedded platform to automatically show up in the platform definitions. 11 days ago, Upgraded to the latest version of clojure (9/11/2009) Changed the logging strings to use the more efficient slf4j argument passing. 2 weeks ago, Cleaned up the new logging file. 2 weeks ago, Added log statement to troubleshoot intermitent platform config problems on Ubuntu. 2 weeks ago, Made some changes to fix build on Ubuntu. I still have to get rid of the jdi explicit code if I can to make this build work on the mac as well. Working on a bug for goto-definition on Ubuntu was causing an exception. 2 weeks ago, Updated build to look at new deps.zip. 2 weeks ago, Added netbeans project to make development easier. Note: these are not required for the non-netbeans specific lib. Everything can be build with ant using free-form projects with another IDE or from the commaon line. 2 weeks ago, added the ivy-cache dir to gitignore. Updated some docs in the c_slf4j 2 weeks ago, Finished moving all log statements to c-slfj4. The default jar maps to the java.util.logging. Fixed a bug related to the new project repl support for free form java projects. 2 weeks ago, First pass at cleaning up the used code on the commons project and more importantly, moving to the slf4j for logging. 3 weeks ago, Merge branch 'separate-repl' 3 weeks ago, See previous comment 3 weeks ago, Enabled project REPLs on free form java projects (Closes #6) Added classpath support functions into the repl-client module. Added the clojure facade on slf4j lib in commons (Refs #2) 3 weeks ago, updated project zip 3 weeks ago, Fixed a boundary bug in the insert text on completion for Ubuntu. 3 weeks ago, Fixed a bug in the Connect External repl dialog. Added a test script for the repl-server. 3 weeks ago, Fixed a bug that was causing an exception in some files during the code folding. Fixed a bug where an exception was thrown if you attempted to load a file with no REPL running. 3 weeks ago, Changed the toString method for project classpaths to allow the ClassPath API to build the string. 3 weeks ago, Took out reference to the enclojure.commons jar for running repls. 3 weeks ago, Fixed another issue when the IDE passes a full file path to the go-to-definition and also corrected the line offset problem where is was always taking you 1 line below where you wanted to be. 3 weeks ago, Fixed a bug in the goto-declaration where the search was not including the namespace of the current file. Removed all other clojure source files except the repl.main file in the repl-server project and got
Re: New Release for Enclojure plugin - 2009-09-22
any chance the enclojure plugin can be made available to download from the NetBeans repo? It would mean much easier for netbeans users to find and install it by simply bringing up the plugin menu from within NetBeans. Just a thought. On Tue, Sep 22, 2009 at 8:53 PM, Eric Thorsen wrote: > > New release of the Enclojure plugin for Netbeans has been released! > I have moved Enclojure to github and greatly simplified the build > process. See readme in the root directory of the repo for more > details. > http://github.com/EricThorsen/enclojure > > You can download the release at: > http://github.com/EricThorsen/enclojure/downloads > > This release was primarily focused on bug fixes particularly on Ubuntu > and Windows with a few enhancements to completion. > > Thanks again to everyone who has provided guidance and feedback! > Eric > > git log > > 3 hours ago, Added a testing file for completion-task > 4 hours ago, Fixed a completion bug where the context was getting > confused in some cases causing no symbols to be suggested at all. > 5 hours ago, Fixed a completion bug when there was no context. > 28 hours ago, Added an interface for REPL history to de-couple the > repl-history from the specific IDE. Moved the generic prefs utilities > into the ide project out of the Netbeans specific stuff. > 31 hours ago, Moved enclojure preferences under the .netbeans dir > 31 hours ago, Moved enclojure preferences under the .netbeans dir > 32 hours ago, Fixed bugs on project creation and new source file > support on Windows > 33 hours ago, Fixed a let bug... > 2 days ago, Changed the default home dir to use the netbeans dir. > 4 days ago, Fixed a nasty bug in the form parser when there was an > unreadble form in a source file. > 5 days ago, Added docs to the completion > 5 days ago, nothing changed? > 5 days ago, Took out a temporary log statement in the launcher. > 6 days ago, Added support for inter-project dependancies for the > REPL. > 6 days ago, Fixed several timing issues with the configuration > settings and starting/stopping various REPLs. > 6 days ago, Fixed the problem related to the *1,*,2*3,*e vars not > being bound when pretty printing was enabled. > 7 days ago, Working towards fixing the *1,*2,*3 binding issue when > pretty printing is enabled. > 7 days ago, Merge branch 'bugfix' > 7 days ago, Merge branch 'master' of g...@github.com:EricThorsen/ > enclojure > 7 days ago, Added a readme for building enclojure. > 7 days ago, Added the new clojure platform to the layer.xml file. > 8 days ago, Added the later clojure and clojure-contrib libs to the > deps.zip and modified the build to use deps.zip > 11 days ago, Continuing to work on added the embedded platform to > automatically show up in the platform definitions. > 11 days ago, Upgraded to the latest version of clojure (9/11/2009) > Changed the logging strings to use the more efficient slf4j argument > passing. > 2 weeks ago, Cleaned up the new logging file. > 2 weeks ago, Added log statement to troubleshoot intermitent platform > config problems on Ubuntu. > 2 weeks ago, Made some changes to fix build on Ubuntu. I still have > to get rid of the jdi explicit code if I can to make this build work > on the mac as well. Working on a bug for goto-definition on Ubuntu was > causing an exception. > 2 weeks ago, Updated build to look at new deps.zip. > 2 weeks ago, Added netbeans project to make development easier. > Note: these are not required for the non-netbeans specific lib. > Everything can be build with ant using free-form projects with another > IDE or from the commaon line. > 2 weeks ago, added the ivy-cache dir to gitignore. Updated some docs > in the c_slf4j > 2 weeks ago, Finished moving all log statements to c-slfj4. The > default jar maps to the java.util.logging. Fixed a bug related to the > new project repl support for free form java projects. > 2 weeks ago, First pass at cleaning up the used code on the commons > project and more importantly, moving to the slf4j for logging. > 3 weeks ago, Merge branch 'separate-repl' > 3 weeks ago, See previous comment > 3 weeks ago, Enabled project REPLs on free form java projects (Closes > #6) Added classpath support functions into the repl-client module. > Added the clojure facade on slf4j lib in commons (Refs #2) > 3 weeks ago, updated project zip > 3 weeks ago, Fixed a boundary bug in the insert text on completion > for Ubuntu. > 3 weeks ago, Fixed a bug in the Connect External repl dialog. Added a > test script for the repl-server. > 3 weeks ago, Fixed a bug that was causing an exception in some files > during the code folding. Fixed a bug where an exception was thrown if > you attempted to load a file with no REPL running. > 3 weeks ago, Changed the toString method for project classpaths to > allow the ClassPath API to build the string. > 3 weeks ago, Took out reference to the
Re: "If you wish to have a version for off-line use...
Did you mean this? http://clojure.googlegroups.com/web/manual.pdf On Sep 20, 4:59 am, cej38 wrote: > I was just looking through the main web page of clojure-contrib and > came across this: > > "If you wish to have a version for off-line use you can use the > download button on the page at GitHub .gh-pages branch." > > Is there a similar repository for the clojure.org? --~--~-~--~~~---~--~~ 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: Namespace/class visibility in eval
On Tue, Sep 22, 2009 at 6:46 PM, Eric Tschetter wrote: > If I do just > > curl 'http://localhost:43034/1.0/cloj' -H 'content-type: > application/clojure' -d '(json-str {:howdy ["hi" 1 2 3]})' > > I get this exception > > java.lang.Exception: Unable to resolve symbol: json-str in this > context (NO_SOURCE_FILE:0) > Looks like only clojure.core is imported as far as read/eval is concerned. Something like this > > curl -v 'http://localhost:43034/1.0/cloj' -H 'content-type: > application/clojure' -d "(require 'clojure.contrib.json.write) > (json-str {:howdy [\"hi\" 1 2 3]})" > > Doesn't work because I'm only read/eval'ing one thing. > Wrap the require and json-str in a do. Or, modify your original code so that what read operates on includes this require. Something like: (defroutes evallerificator (POST "/1.0/cloj" (eval (list `do `(require (quote clojure.contrib.json.write)) (read (PushbackReader. (InputStreamReader. (request :body))) (GET "/" (html [:h1 "Hello World"])) (ANY "*" (page-not-found))) or, if that doesn't work (it proves to be "read" that does symbol resolution), (defroutes evallerificator (POST "/1.0/cloj" (eval (read-str (str "(do (require 'clojure.contrib.json.write) " (slurp (PushbackReader. (InputStreamReader. (request :body ")" (GET "/" (html [:h1 "Hello World"])) (ANY "*" (page-not-found))) (untested!) But, this looks like a gaping security hole. You're taking an HTTP POST request body and eval'ing it. Someone will, sooner or later, try typing "(delete all the secret files)" into the web form and clicking Send. Or worse, something that will actually delete something or grant privilege. Sending "(doall (iterate inc 1))" will crash the server with OOME after a lengthy 100%-cpu-use hang while it fills memory with consecutive Integer objects, for a cheap and easy DoS attack. And so forth. The last example shows that even vetting the incoming string for I/O is not enough protection. (And the incoming string could sneak I/O in in numerous ways; a lengthy computation could assemble a dynamic string equal to "with-open" or "InputStream" and another equal to a file path ("/etc/passwd" anyone?) and combine them. It might use "symbol" or "read", then "eval". Blocking eval just makes them resort to cobbling together classnames and method names from obfuscated fragments and then invoking Java reflection, e.g. Class/forName. Maybe if you blocked every Java reflection-related class name as well as read, eval, and the Clojure I/O forms -- but even then someone can request an infinite seq be doall'd or similarly to cause some amount of trouble, even if deleting files or creating a privileged account on the server machine is placed out of their reach.) --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
>> .. It waits until the value is actually needed. For > more details on this, see http://ociweb.com/mark/stm/article.html. . Great article.Thanks ! Roger > --~--~-~--~~~---~--~~ 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: Q: is there a better way to do this
> You need to prevent the modification of consuming by using ensure > rather than deref (@). Oh - excellent point! I didn't think of that. When it useful to be able to deref inside a dosync without ensuring? Ensure seems like a more safe default of what I'd expect from a transaction. So why not make deref automatically ensure within a dosync? It takes a bit of care to remember to use ensure instead of deref in a dosync. Regards, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
NO_SOURCE_FILE
hi, is there perchance some way Clojure's REPL might be able to print out more information in such situations? i don't know what precisely the situations are. it is frustrating to not get more information to help debug something. seems like it might be about anonymous fns or some such? thanks for any brainstorms! --~--~-~--~~~---~--~~ 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: NO_SOURCE_FILE
There could be a verbose flag which would print the form in which the error occurs. This shouldn't be default though as the forms can be quite large. On Sep 23, 3:37 pm, Raoul Duke wrote: > hi, > > is there perchance some way Clojure's REPL might be able to print out > more information in such situations? i don't know what precisely the > situations are. it is frustrating to not get more information to help > debug something. seems like it might be about anonymous fns or some > such? > > thanks for any brainstorms! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Streaming Data?
Dear Clojurians, Are lazy-seqs good for streaming data that arrives at indeterminate intervals? if not any pointers about which approach to take? I'm working on a simple serial port library for Clojure and I'm trying to understand how to best model a solution. Basically serial events will happen periodically on the port and I'd rather design my program in a functional way then just trying to translate Java serial port code that I've seen. Thanks, 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 -~--~~~~--~~--~--~---
trouble running clojure.test
Hello, I'm having trouble unit testing clojure code. To be sure I'm just testing clojure.test, I'm trying to test clojure.contrib.json.read. test.clj states: ;; RUNNING TESTS ;; ;; Run tests with the function "(run-tests namespaces...)": (run-tests 'your.namespace 'some.other.namespace) However, this doesn't work: > (run-tests 'clojure.contrib.json.read) nil What does seem to work is this: > (test-ns 'clojure.contrib.json.read) {:test 17, :pass 27, :fail 0, :error 0} However, I need MUCH more verbose output: which functions passed? which ones failed (expected/actual)??? test.clj states this should work perfectly: ;; You can type an "is" expression directly at the REPL, which will ;; print a message if it fails. ;; ;; user> (is (= 5 (+ 2 2))) ;; ;; FAIL in (:1) ;; expected: (= 5 (+ 2 2)) ;; actual: (not (= 5 4)) ;; false but it doesn't work this way at all: > (is (= 5 (+ 2 2))) false Just false? How do I enable the nice report? NOTE: the code above doesn't have any failed functions, but a simple test function I created only did this: (test-ns 'test) {:test 2, :pass 1, :fail 1, :error 0} *missing == FAIL in ... I've also tried test_is.clj but I only ever get 'nil' as a result. I also tried with I'm sure I've missed it. test.clj contains defmethod report ... that has the FAIL println in it. I do not know why it is not getting called. All suggestions are warmly welcomed. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---