Idiomatic Way to Keep a Variable Private to a Namespace
I want to define and use a map that is private to a namespace and used by several functions in that namespace. Is the idiomatic way simply to def it within the namespace? Is there another way to hide it? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Javascript generator
jim writes: > Due to popular demand*, I resuscitated my code to generate javascript > from s-expressions. This was what I coded to learn about logic > programming in Clojure. > > Github: http://github.com/jduey/js-gen > Clojars: http://clojars.org/net.intensivesystems/js-gen > > *actually it was just one person, but I'm easily swayed. Neat! You've seen Scriptjure, I expect, so it'd be interesting to hear how your library differs: http://github.com/arohner/scriptjure -Steve -- 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: Idiomatic Way to Keep a Variable Private to a Namespace
;; some_ns/internal.clj (ns some-ns.internal) (def private-map {:k1 10 :k2 20}) ;;end-of-file ;; some_ns.clj (ns some-ns (:use some-ns.internal)) ;; ..functions.. (defn foo [] ;; do something with private-map ..) ;;end-of-file This is how I have been doing it. But I would love to hear other ideas. Regards, Shantanu On Oct 11, 12:22 pm, HiHeelHottie wrote: > I want to define and use a map that is private to a namespace and used > by several functions in that namespace. Is the idiomatic way simply > to def it within the namespace? Is there another way to hide it? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Idiomatic Way to Keep a Variable Private to a Namespace
Hi, On 11 Okt., 09:22, HiHeelHottie wrote: > I want to define and use a map that is private to a namespace and used > by several functions in that namespace. Is the idiomatic way simply > to def it within the namespace? Is there another way to hide it? (def ^{:private true} my-map {:a :b :c :d}) Don't spend to much time on finding ways to build walls. Just use the above approach and/or document, that the variable is private and should be left alone. "Hiding" things is also not really necessary: a pure :use is strongly discouraged. :use should only be used with :only. 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
var vs. symbols
Hi, I'm sure this has been asked before (although I couldn't find anything other than this StackOverflow thread http://stackoverflow.com/questions/2320348/symbols-in-clojure) and, in addition to that thread, I have a clarifying question: Am I right if I say that when I do (def foo "1") I'm creating a var whose root binding is "1" and then binding the symbol foo to this var? Cheers, U -- 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: var vs. symbols
you are right (at least as far as I know) -- 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: var vs. symbols
2010/10/11 Ulises > Hi, > > I'm sure this has been asked before (although I couldn't find anything > other than this StackOverflow thread > http://stackoverflow.com/questions/2320348/symbols-in-clojure) and, in > addition to that thread, I have a clarifying question: > > Am I right if I say that when I do (def foo "1") I'm creating a var > whose root binding is "1" and then binding the symbol foo to this var? > I guess one should use "mapping" instead of "binding". The var is mapped to the symbol "foo" in the namespace *ns*. I'm saying that because functions for inspecting namespaces are (ns-map), etc. HTH, -- Laurent -- 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: var vs. symbols
> I guess one should use "mapping" instead of "binding". The var is mapped to > the symbol "foo" in the namespace *ns*. > I'm saying that because functions for inspecting namespaces are (ns-map), Ah! Excellent, thanks. U -- 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: var vs. symbols
Hi, On 11 Okt., 11:44, Laurent PETIT wrote: > I guess one should use "mapping" instead of "binding". The var is mapped to > the symbol "foo" in the namespace *ns*. > > I'm saying that because functions for inspecting namespaces are (ns-map), > etc. In a determined attempt to increase confusion, I would like to throw another interpretation into the ring. Vars are not connected to symbols at all. They happen to get a name. When a unqualified symbol is read by the reader, it is resolved in the current namespace to the Var with the same name. So a symbol itself has no connection to any Var. I would consider the actual map just an implementation detail. The same could be achieved by a list of Vars which is walked to find the required one. (with a different performance, of course) So I would say: "Unqualified symbols in the namespace the def happened in will resolve to the def'd Var." (of course only after the def happened!) 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: var vs. symbols
> So I would say: "Unqualified symbols in the namespace the def happened > in will resolve to the def'd Var." (of course only after the def > happened!) so in theory one could have a symbol foo bound to a var bar? U -- 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: var vs. symbols
Hi, On 11 Okt., 12:26, Ulises wrote: > so in theory one could have a symbol foo bound to a var bar? Eh. No. I don't think so. The Var has a name and the symbol has a name. And an unqualified symbol is resolved to the "closest" Var with the same name (conveniently derefing the var to get its contents). This might be in the same namespace or in a different namespace which was :use'd. I'm still not convinced that symbols are "bound" to a Var. 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: var vs. symbols
> Eh. No. I don't think so. The Var has a name and the symbol has a > name. And an unqualified symbol is resolved to the "closest" Var with > the same name (conveniently derefing the var to get its contents). > This might be in the same namespace or in a different namespace which > was :use'd. I'm still not convinced that symbols are "bound" to a Var. And there I was thinking I was starting to "get it". user> (def foo) #'user/foo user> foo ;Var user/foo is unbound. ; [Thrown class java.lang.IllegalStateException] user> I guess this means there's no var named user/foo and hence the symbol cannot get its closest match in name? U -- 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: var vs. symbols
Hi, On 11 Okt., 12:45, Ulises wrote: > user> (def foo) > #'user/foo > user> foo > ;Var user/foo is unbound. > ; [Thrown class java.lang.IllegalStateException] > user> > > I guess this means there's no var named user/foo and hence the symbol > cannot get its closest match in name? You are confusing things. The error means that there is no *value* bound to the Var. user=> (def foo) #'user/foo user=> (var foo) #'user/foo user=> (var non-existant) java.lang.Exception: Unable to resolve var: non-existant in this context (NO_SOURCE_FILE:3) 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: var vs. symbols
Hi, or a maybe clearer example, which shows the different states: ; No Var, yet. user=> (var foo) java.lang.Exception: Unable to resolve var: foo in this context (NO_SOURCE_FILE:1) ; Var is now defined. Hence it can be resolved. But it has to root value, ie. it is "unbound", yet. user=> (def foo) #'user/foo user=> (var foo) #'user/foo user=> foo java.lang.IllegalStateException: Var user/foo is unbound. (NO_SOURCE_FILE:0) ; Finally provide a value (either via def or as in this case temporarily with binding) user=> (binding [foo 5] foo) 5 Hope, that 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
NPE in lazy-xml/emit
Hi, I'm afraid I'm new to Clojure, so I'm not even going to attempt a patch, but I get a NullPointerException when I pass an empty map (e.g., {} or {:something {}}) to lazy-xml/emit. The stacktrace is below, if anyone's interested. Regards, Ed O'Loughlin - 2010-10-10 19:08:16.111::WARN: EXCEPTION javax.xml.transform.TransformerException: java.lang.NullPointerException at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java: 716) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java: 313) at clojure.contrib.lazy_xml$emit.doInvoke(lazy_xml.clj:157) at clojure.lang.RestFn.invoke(RestFn.java:411) at neataudio.web$xml_response.doInvoke(web.clj:19) at clojure.lang.RestFn.invoke(RestFn.java:411) at neataudio.web$fn__1893$fn__1894.invoke(web.clj:39) at compojure.core$routes$fn__748$fn__749.invoke(core.clj:71) at clojure.core$some.invoke(core.clj:2053) at compojure.core$routes$fn__748.invoke(core.clj:71) at ring.middleware.params$wrap_params$fn__389.invoke(params.clj:76) at ring.middleware.cookies$wrap_cookies$fn__589.invoke(cookies.clj: 124) at ring.middleware.json_params$wrap_json_params $fn__1184.invoke(json_params.clj:19) at neataudio.web$wrap_error_handling$fn__1888.invoke(web.clj:28) at clojure.lang.Var.invoke(Var.java:365) at ring.adapter.jetty$proxy_handler$fn__304.invoke(jetty.clj:17) at ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler $0.handle(Unknown Source) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: 152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: 534) at org.mortbay.jetty.HttpConnection $RequestHandler.headerComplete(HttpConnection.java:864) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:533) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:207) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403) at org.mortbay.jetty.bio.SocketConnector $Connection.run(SocketConnector.java:228) at org.mortbay.thread.QueuedThreadPool $PoolThread.run(QueuedThreadPool.java:522) Caused by: java.lang.NullPointerException at clojure.core$namespace.invoke(core.clj:1252) at clojure.contrib.lazy_xml$emit_element.invoke(lazy_xml.clj:131) at clojure.contrib.lazy_xml$emit$reify__1348.parse(lazy_xml.clj:169) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java: 636) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java: 707) ... 25 more -- 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: var vs. symbols
> Hope, that helps. It does indeed. So, def either creates or looks up a var of the name of the symbol given and then every time eval comes across a symbol it tries to lookup a var of the same name? (just read http://clojure.org/special_forms#def which I should've read before posting) Cheers and sorry for the confusion and the silly questions, U -- 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: var vs. symbols
Hi, On 11 Okt., 13:29, Ulises wrote: > sorry for the confusion and the silly questions, Ehm. Nope. To cite the (german) sesame street: Wer? Wie? Was? Wieso? Weshalb? Warum? Wer nicht fragt bleibt dumm! Just keep asking. :) 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: Javascript generator
I've heard of scriptjure but never used it or looked at it. My interests took me in another direction and I've never circled back. I would be interested to know how the differ. Thanks, Jim On Oct 11, 3:21 am, Steve Purcell wrote: > jim writes: > > Due to popular demand*, I resuscitated my code to generate javascript > > from s-expressions. This was what I coded to learn about logic > > programming in Clojure. > > > Github:http://github.com/jduey/js-gen > > Clojars:http://clojars.org/net.intensivesystems/js-gen > > > *actually it was just one person, but I'm easily swayed. > > Neat! You've seen Scriptjure, I expect, so it'd be interesting to hear > how your library differs: > > http://github.com/arohner/scriptjure > > -Steve -- 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: lein compile changes not getting picked up by lein swank
On Oct 10, 2010, at 3:05 PM, HiHeelHottie wrote: > I'm running lein swank and using slime-connect from emacs. When I use > lein compile after making changes to a method, they don't appear to > get picked up unless I bring down lein swank, bring it up again, slime- > connect, etc. > > Is there a way to get lein compile changes to be picked up by an > already running lein swank? Also, would be interested to hear about > the workflow others are using with lein to develop a java class. I believe you're seeing the effects of the Java behavior that (at least by default) a class loader will only load a given ".class" file once in the lifetime of a given JVM. Its contents are cached and the cache is used for all further reference to the classes defined in it. To be more dynamic than that you can arrange for your generated class to call out to Clojure functions to do some or all of its actual work. New versions of the Clojure functions you're working on can be loaded into a running lein swank as many times as you'd like from ".clj" files. --Steve -- 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: Javascript generator
Well, taking a brief look over your code, it seems like the main difference is that scriptjure is macro-based, so all the code generation gets done at compile-time. That makes scriptjure faster, but at the expense of needing an unquote form - "(clj ...)" - to splice clojure expressions into the javascript source sexps. -Steve jim writes: > I've heard of scriptjure but never used it or looked at it. My > interests took me in another direction and I've never circled back. I > would be interested to know how the differ. > > Thanks, > Jim > > On Oct 11, 3:21 am, Steve Purcell wrote: >> jim writes: >> > Due to popular demand*, I resuscitated my code to generate javascript >> > from s-expressions. This was what I coded to learn about logic >> > programming in Clojure. >> >> > Github:http://github.com/jduey/js-gen >> > Clojars:http://clojars.org/net.intensivesystems/js-gen >> >> > *actually it was just one person, but I'm easily swayed. >> >> Neat! You've seen Scriptjure, I expect, so it'd be interesting to hear >> how your library differs: >> >> http://github.com/arohner/scriptjure >> >> -Steve -- 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: Servlet question
Thanks this does seem to solve the problem of the servlet being reinitialized on every run. On Oct 10, 11:10 pm, Adrian Cuthbertson wrote: > Hi Dmitri, > > The problem is probably related to calling init with args. It requires > that super() gets called - I can't remember where I saw the > documentation, but here's an example of what works for me. > > The following is a generic servlet which gets passed a clojure > namespace name as an init parameter at init time which is saved in an > atom. Then on each service call, it parses the servlet path and uses > the "ipath" (first component of the url after the context), along with > the ns name from the atom to load a clj namespace (once) and call a > function called passing it the req and rsp. The clj fn cn then > handle the method type, GET, POST, etc and has access to all the > servlet stuff. > > This way you have a servlet as a gateway to a clj ns and the function > called determined by the req url... > > (ns svlt.Svlt > (import (javax.servlet.http HttpServlet HttpServletRequest > HttpServletResponse HttpSession) > (javax.servlet ServletConfig) > ) > (:gen-class :extends javax.servlet.http.HttpServlet > :state state :init clinit)) > > (defn -clinit > [] > [[] (atom (hash-map))]) > > (defn -init-void > [this] ; NB - careful, must rather call init() (void) than with the cfg > args. > ; If with args, must call .super() which is problematic > (let [;cfg (.getServletConfig this) > ns-nm (.getInitParameter this "app-ns")] > (println :Svlt :init :ns-nm ns-nm) > (swap! (.state this) assoc :ns-nm ns-nm))) > > (defn -service > [this #^HttpServletRequest req #^HttpServletRequest rsp] > (let [cpath (.getContextPath req) > spath (.getServletPath req) > ipath (.getPathInfo req) > _ (println :Svlt :cpath cpath :spath spath :ipath ipath) > ns-nm (get @(.state this) :ns-nm) > _ (println :Svlt :ns-nm ns-nm) > _ (when (nil? ns-nm) (throw (java.io.IOException. > (str "No app-ns param found in Svlt config: " spath > ipath (if (or (nil? ipath) (= ipath "")) "root" ipath) > ipath (if (.startsWith ipath "/") (.substring ipath 1) ipath) > ns-sym (symbol ns-nm) > _ (println :ns-sym ns-sym :ipath-now ipath) > found-ns (find-ns ns-sym) > found-ns (if (nil? found-ns) > (let [n (create-ns ns-sym)] (require ns-sym) n) > found-ns) > _ (when (nil? found-ns) (throw (java.io.IOException. > (str "Namespace not found for: " ns-sym > req-fn (get (ns-publics ns-sym) (symbol ipath)) > ] > (req-fn req rsp))) > > -Hth, Adrian -- 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: Idiomatic Way to Keep a Variable Private to a Namespace
(:use [clojure.contrib.def]) (defvar- x ...) A bit shorter than writing the meta-data by hand. Def provides a number of other interesting shortcuts. Have a look at def.clj in contrib. I prefer to keep things private and avoid cluttering the use clause with a long :only list. I use :only only when I end up with a name conflict. Luc P. HiHeelHottie wrote .. > > I want to define and use a map that is private to a namespace and used > by several functions in that namespace. Is the idiomatic way simply > to def it within the namespace? Is there another way to hide it? > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first > post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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: Javascript generator
On Mon, Oct 11, 2010 at 10:02 AM, Steve Purcell wrote: > Well, taking a brief look over your code, it seems like the main > difference is that scriptjure is macro-based, so all the code generation > gets done at compile-time. > js-gen generates js at compile time. > > That makes scriptjure faster, but at the expense of needing an unquote > form - "(clj ...)" - to splice clojure expressions into the javascript > source > sexps. > > -Steve I haven't found this to be true at all. Scriptjure in my tests is quite a bit slower because it doesn't emit the final generated code at compile time, but an intermediate form that permits splicing. I look forward to the cross-pollinations of ideas between these two endeavors :) 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: New Release of the Clojure Debugging Toolkit
>> You going to do some speech recognition in Clojure? Unfortunately, no. I just have some hand RSI problems, and I use Dragon NaturallySpeaking for writing e-mails and documenting Clojure code. You can see an example of the notes I've taken while going through the labrepl exercises at http://www.gettingclojure.com/notes:clojure-notes-labrepl-1 and ...labrepl-2. --Gregg -- 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: Idiomatic Way to Keep a Variable Private to a Namespace
It's fairly common to let over a function, e.g.: (let [a (atom 0)] (defn next-id [] (swap! a inc))) In the above, the atom can only be referenced from within the lexical scope of the let, hence essentially private to the next-id function. On Oct 11, 8:03 am, lprefonta...@softaddicts.ca wrote: > (:use [clojure.contrib.def]) > > (defvar- x ...) > > A bit shorter than writing the meta-data by hand. > > Def provides a number of other interesting shortcuts. Have a look at > def.clj in contrib. > I prefer to keep things private and avoid cluttering the use > clause with a long :only list. I use :only only when I end up with a name > conflict. > > Luc P. > > HiHeelHottie wrote .. > > > > > > > I want to define and use a map that is private to a namespace and used > > by several functions in that namespace. Is the idiomatic way simply > > to def it within the namespace? Is there another way to hide it? > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first > > post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/clojure?hl=en -- 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: Javascript generator
David Nolen writes: > On Mon, Oct 11, 2010 at 10:02 AM, Steve Purcell > wrote: > > Well, taking a brief look over your code, it seems like the main > difference is that scriptjure is macro-based, so all the code > generation > gets done at compile-time. > > > js-gen generates js at compile time. Indeed - my embarrassing mistake, for which I apologise! A more thorough reading of the code would have shown up the one key macro that ties it all together. > That makes scriptjure faster, but at the expense of needing an > unquote > form - "(clj ...)" - to splice clojure expressions into the > javascript source > sexps. > > > I haven't found this to be true at all. Scriptjure in my tests is > quite a bit slower because it doesn't emit the final generated code at > compile time, but an intermediate form that permits splicing. > I look forward to the cross-pollinations of ideas between these two > endeavors :) Indeed. Thanks for taking the time to correct me! Now time for me to actually play with js-gen in earnest... -Steve -- 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
Find reference type on classpath
Hi list, I often run into this issue where I am follow a Java documentation where they developers fail to explain where they import packages from. In most Java IDE's you can search your classpath for reference types. It would be great is if was possible to do the same in slime. I looked around the docs but was unable to find and insights on how do to this. Does anyone have a way of searching for reference types from within slime/emacs? Ivan Willig -- 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
strange bug in range or lazy-seq?
Hi, I tried experimenting with lazy sequences and wrote this program (def nums (cons 2 (lazy-seq (map inc nums (def primes (cons (first nums) (lazy-seq (->> (rest nums) (remove (fn [x] (let [dividors (take-while #(<= (* % %) x) primes)] (some #(= 0 (rem x %)) dividors It works fine. However if I redefine nums like this (def nums (drop 2 (range))) It gives me a wrong result e.g. (take 5 primes) is (2 3 5 7 9) I don't see how that can be. I put in a println to see where the problem is I inserted this line before the "some" function call. (println (str "x = " x ", dividors = " (seq dividors))) If I then define nums as (drop 2 (range)) and write (take 5 primes) I get this output (x = 3, dividors = x = 4, dividors = (2) x = 5, dividors = (2) x = 6, dividors = (2) x = 7, dividors = (2) x = 8, dividors = (2) x = 9, dividors = (2) x = 10, dividors = (2) x = 11, dividors = (2) x = 12, dividors = (2) x = 13, dividors = (2) x = 14, dividors = (2) x = 15, dividors = (2) x = 16, dividors = (2) x = 17, dividors = (2) x = 18, dividors = (2) x = 19, dividors = (2) x = 20, dividors = (2) x = 21, dividors = (2) x = 22, dividors = (2) x = 23, dividors = (2) x = 24, dividors = (2) x = 25, dividors = (2) x = 26, dividors = (2) x = 27, dividors = (2) x = 28, dividors = (2) x = 29, dividors = (2) x = 30, dividors = (2) x = 31, dividors = (2) 2 3 5 7 9) That just doesn't make any sense. Can anyone explain this? btw, I use clojure 1.2.0 -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Find reference type on classpath
On Mon, Oct 11, 2010 at 12:21 PM, Ivan Willig wrote: > I often run into this issue where I am follow a Java documentation where > they developers fail to explain where they import packages from. In most > Java IDE's you can search your classpath for reference types. It would be > great is if was possible to do the same in slime. I looked around the docs > but was unable to find and insights on how do to this. > > Does anyone have a way of searching for reference types from within > slime/emacs? You can use M-. over an identifier to jump to its definition. This is totally unrelated to reference types, but sort of sounds like what you want. Your question is a bit muddled, though. -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: strange bug in range or lazy-seq?
I confess I'm a bit baffled by this too, but I have a couple suggestions that don't address your problem :) (drop 2 (range)) is the same as (iterate inc 2), and the same as your convoluted lazy-seq, except that the iterate works here, while for some reason the range doesn't. You might consider zero? instead of = 0. On Oct 11, 1:21 pm, SpiderPig wrote: > Hi, > I tried experimenting with lazy sequences and wrote this program > > (def nums (cons 2 (lazy-seq (map inc nums > (def primes (cons (first nums) > (lazy-seq (->> > (rest nums) > (remove > (fn [x] > (let [dividors (take-while #(<= (* % %) x) > primes)] > (some #(= 0 (rem x %)) dividors > > It works fine. However if I redefine nums like this > (def nums (drop 2 (range))) > > It gives me a wrong result > e.g. (take 5 primes) is (2 3 5 7 9) > > I don't see how that can be. > I put in a println to see where the problem is > I inserted this line before the "some" function call. > (println (str "x = " x ", dividors = " (seq dividors))) > If I then define nums as (drop 2 (range)) > and write (take 5 primes) I get this output > > (x = 3, dividors = > x = 4, dividors = (2) > x = 5, dividors = (2) > x = 6, dividors = (2) > x = 7, dividors = (2) > x = 8, dividors = (2) > x = 9, dividors = (2) > x = 10, dividors = (2) > x = 11, dividors = (2) > x = 12, dividors = (2) > x = 13, dividors = (2) > x = 14, dividors = (2) > x = 15, dividors = (2) > x = 16, dividors = (2) > x = 17, dividors = (2) > x = 18, dividors = (2) > x = 19, dividors = (2) > x = 20, dividors = (2) > x = 21, dividors = (2) > x = 22, dividors = (2) > x = 23, dividors = (2) > x = 24, dividors = (2) > x = 25, dividors = (2) > x = 26, dividors = (2) > x = 27, dividors = (2) > x = 28, dividors = (2) > x = 29, dividors = (2) > x = 30, dividors = (2) > x = 31, dividors = (2) > 2 3 5 7 9) > > That just doesn't make any sense. Can anyone explain this? > > btw, I use clojure 1.2.0 -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Is ClojureCLR converging toward a release?
Check out the downloads area on http://github.com/richhickey/clojure-clr. Grab clojure-clr-1.2.0.zip. Unzip, start up Clojure.Main.exe and you should be running. The zip also contains Clojure.Compile.exe, which you can invoke with command line arguments indicating files to compile. The support DLLs for the DLR are included. These are debug builds for .Net 3.5 only. Within the next day or so, the master branch will updated with a new build process that will create debug and release builds for 3.5 and 4.0. Future binary distributions will be available in all four flavors. The new build process and extension to .Net 4.0 requires the ClojureCLR project to move to Visual Studio 2010. It will simplify getting started for developers, too. It's ready to go. I just have to get the wiki pages updated. -David On Oct 4, 11:13 pm, Mike K wrote: > David, Rich: any further updates on this? > > Mike > > On Sep 24, 8:24 am, dmiller wrote: > > > Just waiting for that person's CA to be processed by 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: New Release of the Clojure Debugging Toolkit
Hi folks and congrats to George Jahad for this great work. Hoewer the cdt dont work on my windows vista. After some changes on my own i get the same error of Greg Willams: java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap (cdt.clj:28) i've tried add-classpath of tool.jar (where is the class in my jdk) with various formats, after testing the urls in browser with success but i get the ClassNotFound all the time Current directory is c:/Users/atreyu/AppData/Roaming/.emacs.d/ Clojure 1.2.0 user=> java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap (cdt.clj:28) user=> java.lang.Exception: Unable to resolve symbol: set-source-path in this context (NO_SOURCE_FILE:2) user=> java.lang.Exception: Unable to resolve symbol: cdt-attach in this context (NO_SOURCE_FILE:3) user=> (def file-url (format "file://%s/../lib/tools.jar" (System/getProperty "java.home"))) #'user/file-url user=> file-url "file://c:\\Program Files\\Java\\jdk1.6.0_21\\jre/../lib/tools.jar" user=> (def file-path "c:\\Program Files\\Java\\jdk1.6.0_21\\jre/../ lib/tools.jar") #'user/file-url user=> (.exists (java.io.File. file-path)) true user=> (add-classpath file-url) WARNING: add-classpath is deprecated nil user=> (import com.sun.jdi.Bootstrap) java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap (NO_SOURCE_FILE:15) i hope somebody'll can help this poor win users ;-) -- 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 Release of the Clojure Debugging Toolkit
On Oct 12, 12:48 am, atreyu wrote: > Hi folks and congrats to George Jahad for this great work. > Hoewer the cdt dont work on my windows vista. After some changes on my > own i get the same error of Greg Willams: > > java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap (cdt.clj:28) > > i've tried add-classpath of tool.jar (where is the class in my jdk) > with various formats, > after testing the urls in browser with success but i get the > ClassNotFound all the time > > Current directory is c:/Users/atreyu/AppData/Roaming/.emacs.d/ > Clojure 1.2.0 > user=> java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap > (cdt.clj:28) > user=> java.lang.Exception: Unable to resolve symbol: set-source-path > in this context (NO_SOURCE_FILE:2) > user=> java.lang.Exception: Unable to resolve symbol: cdt-attach in > this context (NO_SOURCE_FILE:3) > user=> (def file-url (format "file://%s/../lib/tools.jar" > (System/getProperty > "java.home"))) > #'user/file-url > user=> file-url > "file://c:\\Program Files\\Java\\jdk1.6.0_21\\jre/../lib/tools.jar" > user=> (def file-path "c:\\Program Files\\Java\\jdk1.6.0_21\\jre/../ > lib/tools.jar") > #'user/file-url > user=> (.exists (java.io.File. file-path)) > true > user=> (add-classpath file-url) > WARNING: add-classpath is deprecated > nil > user=> (import com.sun.jdi.Bootstrap) > java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap > (NO_SOURCE_FILE:15) > > i hope somebody'll can help this poor win users ;-) ok i have made a (ugly) trick to make it work, copying tools.jar in cdt/lib and changing cdt.el: (defun cdt-query-cmdline () (let ((path (strip-trail cdt-dir))) (format "java -classpath%s/lib/clojure-1.2.0.jar;%s/lib/clojure- contrib-1.2.0.jar;%s/lib/debug-repl-0.3.0-20091229.021828-3.jar;%s/lib/ tools.jar;%s/src clojure.main --repl" path path path path path))) I guess there is a nicer solution :-/ -- 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 Release of the Clojure Debugging Toolkit
ok i have made a (ugly) trick to make it work, copying tools.jar in cdt/lib and changing cdt.el: (defun cdt-query-cmdline () (let ((path (strip-trail cdt-dir))) (format "java -classpath%s/lib/clojure-1.2.0.jar;%s/lib/clojure- contrib-1.2.0.jar;%s/lib/debug-repl-0.3.0-20091229.021828-3.jar;%s/ lib/ tools.jar;%s/src clojure.main --repl" path path path path path))) I guess there is a nicer solution :-/ -- 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 Release of the Clojure Debugging Toolkit
ok i have made a (ugly) trick to make it work, copying tools.jar in cdt/lib and changing cdt.el: (defun cdt-query-cmdline () (let ((path (strip-trail cdt-dir))) (format "java -classpath%s/lib/clojure-1.2.0.jar;%s/lib/clojure- contrib-1.2.0.jar;%s/lib/debug-repl-0.3.0-20091229.021828-3.jar;%s/ lib/ tools.jar;%s/src clojure.main --repl" path path path path path))) I guess there is a nicer solution :-/ After this step i've tried to test debugger commands and im afraid reval and gud-this throws: Unexpected exception generated: # com.sun.jdi.InvocationException: Exception occurred in target VM (NO_SOURCE_FILE:0) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Test-driven development in Clojure
Hi, I'm new to Clojure, using it for a reasonably sized project for the first time, and I'm trying to do test-driven development. While it does work well technically - clojure.test is very nice to use and feels a lot like JUnit 4's assertThat() - I'm wondering if I'm trying to program Java in Clojure. Here's an example: I'm writing a class (Um. I mean, a ... namespace? Well, a horde of functions.) that accesses web pages from a backend, which can e.g. take these from the filesystem or from a database. In Java or C++, I'd use an interface for that and create one implementation for the filesystem and one for the database: interface Provider { String loadPage(String name); } This is possible in Clojure: (defprotocol Provider (load-page [this name]) It can be implemented using deftype: (deftype DatabaseProvider [] Provider (load-page [this name] (have-fun-with-the-database))) And I can call it like this: (load-page (DatabaseProvider.) "foo") Feels a little weird (especially since all examples of defprotocol and deftype use camel case for type names), but works. Back to my question: Am I trying to do Java in Clojure? Is there a more Lisp-y way to do this? As you may have suspected, this design wasn't my initial intention, it was driven by TDD: This allows me to create a mock implementation against which I can write my test cases without having having to depend on external resources. Typical TDD design. In fact, there will only be one backend for now. This made me wonder if test-driven development was desirable in Clojure at all, or even in functional programming in general. There's a few articles on the issue. Many seem to be from Clojure newcomers, asking questions themselves, and none handles design issues like mock objects [1]. One guy basically said that he stopped doing TDD because the REPL makes it possible to test specific functions directly [2]. I can see how he says that the *driven* aspect of TDD can be performed by the REPL, but I find it too inconvenient for extensive use. Bob Martin says that, because functional programming differs from object-oriented programming (In my opinion, these paradigms are compatible - did he mean imperative programming?), test-driven development has to start by testing the details, and work up to testing the big picture. TDD in e.g. Java starts with the big picture and moves down. I don't understand his points completely, but if he's right, this might be a fundamental problem for TDD in functional languages. One guy partly disagrees with him on some matters, but doesn't really mention the bottom-up thing [4]. What are your thoughts on these issues? Is anybody here doing TDD in Clojure? Is anybody against it? [1]: http://www.magpiebrain.com/2010/02/16/struggling-with-test-driven-clojure/ [2]: http://s-expressions.com/2009/07/28/clojure-the-repl-and-test-driven-development/ [3]: http://blog.objectmentor.com/articles/2010/06/03/tdd-in-clojure [4]: http://ericlefevre.net/wordpress/2010/06/04/bob-martin-on-tdd-in-clojure/ signature.asc Description: OpenPGP digital signature
Re: strange bug in range or lazy-seq?
> (def nums (cons 2 (lazy-seq (map inc nums > (def primes (cons (first nums) > (lazy-seq (->> > (rest nums) > (remove > (fn [x] > (let [dividors (take-while #(<= (* % %) x) > primes)] > (some #(= 0 (rem x %)) dividors > > It works fine. However if I redefine nums like this > (def nums (drop 2 (range))) > > It gives me a wrong result > e.g. (take 5 primes) is (2 3 5 7 9) I don't have a complete answer, but... Using your first version (cons and lazy-seq): user> (take 25 primes) (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97) Using your second version (range): user> (take 25 primes) (2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 37 41 43 47 53 59 61 67 71) Notice that the range version has every odd number right up until 31, then it switches to starting to get the primes correct from there on. So now I'm suspicious. A quick look at the source for (range) and note it's doing chunking, with 32-item chunks: (defn range ... ([start end step] (lazy-seq (let [b (chunk-buffer 32) comp (if (pos? step) < >)] (loop [i start] (if (and (< (count b) 32) (comp i end)) (do (chunk-append b i) (recur (+ i step))) (chunk-cons (chunk b) (when (comp i end) (range i end step) Quite a numerical coincidence... So is it possible that the difference is in how the lazy sequences are being called on to produce their next item? Perhaps range, since it has a next one available and pre-calculated already, offers its up more willingly than your hand-rolled lazy-seq? Figuring the details of that out is beyond my limited capabilities at the moment, but it seems worth investigating. Finally, for interest in figuring out exactly what the two different behaviours are: (def right-nums (cons 2 (lazy-seq (map inc right-nums (def right-primes (cons (first right-nums) (lazy-seq (->> (rest right-nums) (remove (fn [x] (let [dividors (take-while #(<= (* % %) x) right-primes)] (some #(= 0 (rem x %)) dividors (def wrong-nums (drop 2 (range))) (def wrong-primes (cons (first wrong-nums) (lazy-seq (->> (rest wrong-nums) (remove (fn [x] (let [dividors (take-while #(<= (* % %) x) wrong-primes)] (some #(= 0 (rem x %)) dividors (def wrong-answers (filter (fn [x] (not (some #(= x %) (take-while #(<= % x) right-primes wrong-primes)) user> (take 2 wrong-answers) (9 15) user> (take 3 wrong-answers) (9 15 21) user> (take 5 wrong-answers) (9 15 21 25 27) user> (take 6 wrong-answers) <... much time passes, I get bored, Ctrl-C ...> ; Evaluation aborted. Hope this helps?! -- 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: strange bug in range or lazy-seq?
When a var's definition has a "lazy reference" to itself, as primes does below, then your results will be dependent on the lazy/chunky/strict-ness of the calls leading to the lazy reference. The functions range, rest, and remove are chunk-aware, so the range-based version of primes consumes a bunch of numbers before its changes become self-visible. Other functions, such as iterate, are not chunked, so the results are visible to primes sooner. In most domains it is rare to have definitions with *this* kind of self-reference. When you do have it, your best bet is to take explicit control over the laziness by using recur and/or lazy-seq directly. The example below (simplified from contrib) demonstrates this approach to primes: (def primes (concat [2] (let [primes-from (fn primes-from [n] (if (some #(zero? (rem n %)) (take-while #(<= (* % %) n) primes)) (recur (+ n 2)) (lazy-seq (cons n (primes-from (+ n 2))] (primes-from 2 This approach also saves memory over having a separate nums collection--nums is fully (and unnecessarily) realized in memory in the implementations below. Hope this helps, Stu > Hi, > I tried experimenting with lazy sequences and wrote this program > > (def nums (cons 2 (lazy-seq (map inc nums > (def primes (cons (first nums) > (lazy-seq (->> >(rest nums) >(remove > (fn [x] >(let [dividors (take-while #(<= (* % %) x) > primes)] > (some #(= 0 (rem x %)) dividors > > It works fine. However if I redefine nums like this > (def nums (drop 2 (range))) > > It gives me a wrong result > e.g. (take 5 primes) is (2 3 5 7 9) > > I don't see how that can be. > I put in a println to see where the problem is > I inserted this line before the "some" function call. > (println (str "x = " x ", dividors = " (seq dividors))) > If I then define nums as (drop 2 (range)) > and write (take 5 primes) I get this output > > (x = 3, dividors = > x = 4, dividors = (2) > x = 5, dividors = (2) > x = 6, dividors = (2) > x = 7, dividors = (2) > x = 8, dividors = (2) > x = 9, dividors = (2) > x = 10, dividors = (2) > x = 11, dividors = (2) > x = 12, dividors = (2) > x = 13, dividors = (2) > x = 14, dividors = (2) > x = 15, dividors = (2) > x = 16, dividors = (2) > x = 17, dividors = (2) > x = 18, dividors = (2) > x = 19, dividors = (2) > x = 20, dividors = (2) > x = 21, dividors = (2) > x = 22, dividors = (2) > x = 23, dividors = (2) > x = 24, dividors = (2) > x = 25, dividors = (2) > x = 26, dividors = (2) > x = 27, dividors = (2) > x = 28, dividors = (2) > x = 29, dividors = (2) > x = 30, dividors = (2) > x = 31, dividors = (2) > 2 3 5 7 9) > > That just doesn't make any sense. Can anyone explain this? > > btw, I use clojure 1.2.0 > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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: Test-driven development in Clojure
On Mon, Oct 11, 2010 at 6:06 PM, Felix H. Dahlke wrote: > This made me wonder if test-driven development was desirable in Clojure > at all, or even in functional programming in general. For another point of view: take a look at what Brian Marick's been doing with a framework called Midje to do outside-in TDD. It helps you mock out function dependencies and might get you where you want to go. It's just maturing now but I found his blog posts illuminating. http://www.exampler.com/blog/2010/06/10/tdd-in-clojure-a-sketch-part-1/ http://www.exampler.com/blog/2010/06/16/tdd-in-clojure-part-2-in-which-i-recover-fairly-gracefully-from-a-stupid-decision/ http://www.exampler.com/blog/2010/06/17/tdd-in-clojure-part-3-one-wafer-thin-function-conclusions/ and then http://github.com/marick/Midje -- John Stoneham ly...@lyrically.net -- 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
error on a project using clj-processing
hello, i've started a new lein project. it's my project.clj: (defproject test-processing "0.1.0-SNAPSHOT" :description "Test Processing" :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"] [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"] [org.clojars.fyuryu/rosado.processing "1.0.7"]] :dev-dependencies [[swank-clojure "1.2.1"]]) I did lein deps, all the jars are on lib but I'm getting this error from lein repl: vil...@automata:~/meu-src/test-processing$ lein repl "REPL started; server listening on localhost:23102." user=> (ns test-processing (:use rosado.processing)) java.lang.NoSuchMethodError: clojure.lang.RestFn.(I)V (NO_SOURCE_FILE:1) test-processing=> any help? thanks. -- Vilson Vieira vil...@void.cc ((( http://automata.cc ))) ((( http://musa.cc ))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Is ClojureCLR converging toward a release?
Fantastic! Great job David and everyone else who contributed. Mike -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Is ClojureCLR converging toward a release?
Fantastic! Great job David and everyone else who contributed. Mike -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Is ClojureCLR converging toward a release?
Fantastic! Great job David and everyone else who contributed. Mike -- 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: Test-driven development in Clojure
On Oct 11, 2010, at 8:53 PM, John Stoneham wrote: > For another point of view: take a look at what Brian Marick's been > doing with a framework called Midje to do outside-in TDD. It helps you > mock out function dependencies and might get you where you want to go. > It's just maturing now but I found his blog posts illuminating. I'll be doing a talk on this at Strange Loop, and would also be happy to show people at clojure-conj. - Brian Marick, independent consultant Mostly on agile methods with a testing slant Author of /Programming Cocoa with Ruby/ www.exampler.com, www.exampler.com/blog, www.twitter.com/marick -- 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: error on a project using clj-processing
On Oct 11, 2010, at 10:28 PM, Vilson Vieira wrote: > i've started a new lein project. it's my project.clj: > > (defproject test-processing "0.1.0-SNAPSHOT" > :description "Test Processing" > :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"] > [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"] > [org.clojars.fyuryu/rosado.processing "1.0.7"]] > :dev-dependencies [[swank-clojure "1.2.1"]]) > > I did lein deps, all the jars are on lib but I'm getting this error from lein > repl: > > vil...@automata:~/meu-src/test-processing$ lein repl > "REPL started; server listening on localhost:23102." > user=> (ns test-processing (:use rosado.processing)) > java.lang.NoSuchMethodError: clojure.lang.RestFn.(I)V (NO_SOURCE_FILE:1) That may be related to having compiled code from different versions of Clojure trying to mix. Do you know what the deps of rosado.processing are? It may help to use clojure and contrib 1.2.0 rather than snapshots. --Steve -- 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 clojure couchdb
I'm playing around with couchdb. I'm using the version that lein gets with the following command: [clojure-couchdb "0.4.4"] which as far as I can tell is the most recently maintained version. When I do a bunch of rapid calls to document-create in a tight loop, after about 3000 or so documents have been created, I get the error listed below. Any idea how to resolve this? Is there a different version of the clojure-couchdb library that doesn't exhibit this problem? Thanks, Mark Address already in use: connect [Thrown class java.net.BindException] Backtrace: 0: java.net.PlainSocketImpl.socketConnect(Native Method) 1: java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 2: java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 3: java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 4: java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 5: java.net.Socket.connect(Socket.java:529) 6: org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123) 7: org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123) 8: org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147) 9: org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108) 10: org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415) 11: org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) 12: org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) 13: org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554) 14: clj_http.core$request.invoke(core.clj:50) 15: clojure.lang.Var.invoke(Var.java:365) 16: clj_http.client$wrap_redirects$fn__3851.invoke(client.clj:41) 17: clj_http.client$wrap_decompression$fn__3856.invoke(client.clj:56) 18: clj_http.client$wrap_input_coercion$fn__3866.invoke(client.clj:78) 19: clj_http.client$wrap_output_coercion$fn__3861.invoke(client.clj:67) 20: clj_http.client$wrap_query_params$fn__3889.invoke(client.clj:129) 21: clj_http.client$wrap_basic_auth$fn__3893.invoke(client.clj:142) 22: clj_http.client$wrap_accept$fn__3875.invoke(client.clj:102) 23: clj_http.client$wrap_accept_encoding$fn__3880.invoke(client.clj:114) 24: clj_http.client$wrap_content_type$fn__3871.invoke(client.clj:92) 25: clj_http.client$wrap_method$fn__3898.invoke(client.clj:148) 26: clj_http.client$wrap_url$fn__3902.invoke(client.clj:156) 27: couchdb.client$couch_request.invoke(client.clj:101) 28: couchdb.client$do_document_touch.invoke(client.clj:254) 29: couchdb.client$document_create.invoke(client.clj:274) -- 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
Question on binding & macros
I'm working on the chapter on continuations in On Lisp (Chapter 20) and am trying to translate the code to clojure However, I am running into some issues. With the following definitions: (def *cont* identity) (defmacro =values [& retvals] `(*cont* ~...@retvals)) why would the following two expressions throw errors??? (binding [*cont* (fn [m n] (=values (list m n)))] (*cont* 'a 'b)) (binding [*cont* (fn [m n] (=values (list m n)))] (=values 'hello 'there)) However, these two expression work without a problem! ((binding [*cont* (fn [m n] (=values (list m n)))] *cont*) 'a 'b) (binding [*cont* (fn [m n] (list m n))] (*cont* 'a 'b)) -- 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 clojure couchdb
On Tue, Oct 12, 2010 at 12:45 AM, Mark Engelberg wrote: > I'm playing around with couchdb. I'm using the version that lein gets > with the following command: > [clojure-couchdb "0.4.4"] > which as far as I can tell is the most recently maintained version. > > When I do a bunch of rapid calls to document-create in a tight loop, > after about 3000 or so documents have been created, I get the error > listed below. Any idea how to resolve this? Is there a different > version of the clojure-couchdb library that doesn't exhibit this > problem? > > Thanks, > > Mark > > Address already in use: connect > [Thrown class java.net.BindException] > You might want to look at the end of this thread: http://groups.google.com/group/aleph-lib/browse_thread/thread/d0feb5d784f05682/b81fd22a35bed316 Also in my experiencing batching writes with CouchDB is a big performance gain. 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: Question on binding & macros
Hi, On 12 Okt., 07:05, Aravindh Johendran wrote: > (def *cont* identity) > (defmacro =values [& retvals] > `(*cont* ~...@retvals)) > > why would the following two expressions throw errors??? > (binding [*cont* (fn [m n] (=values (list m n)))] (*cont* 'a 'b)) So what happens here: The macro =values in the anonymous fn expands into a call to *cont*. So it is equivalent to: (binding [*cont* (fn [m n] (*cont* (list m n)))] (*cont* :a :b)). So when you call *cont* in the binding you actually call the anonymous function which calls again *cont*, ie. itself. But this time you only pass one argument (the list) while the function expects two. Hence the error. > However, these two expression work without a problem! > ((binding [*cont* (fn [m n] (=values (list m n)))] *cont*) 'a 'b) Here your basically return the anonymous function and call it passing :a and :b. Since the we already left the binding body the original root value (identity) of *cont* is restored. So calling it with one argument does not cause the error. > (binding [*cont* (fn [m n] (list m n))] (*cont* 'a 'b)) I think it should be clear by now, why this one works: you have no recursive call to *cont*. Hence problem here. Hope that 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: Question on binding & macros
> Hope that helps. > > Sincerely > Meikel Thanks! That helped. -- 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