suitability of Clojure for implementing new languages?
I'm currently working on a research project which involves the implementation of several new programming languages in a variety of paradigms. Our current work in being done in PLT Scheme. However, we have several other requirements which suggest that Clojure might be a better choice: support for multimedia and i/o (from the underlying Java in Clojure), cross-platform and web-based deployment, and a language that is in the Lisp/Scheme (preferably Scheme) tradition. It seems that possible choices include Clojure, or a Java-based Scheme implementation, such as kawa or sisc. Does anyone have any comments about how appropriate Clojure would be for implementing new programming languages? thanks, Alex Mitchell --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Reminder: Bay Area Clojure User Group meeting in SF during JavaOne (6/3) with Rich Hickey
Just wanted to say I had a great time at the meetup. Really fun to see people using Clojure in earnest and hear Rich talk about stuff. I blogged it a bit here: http://tech.puredanger.com/2009/06/10/clojure-rich-hickey/ On Jun 4, 11:44 am, Paul Mooser wrote: > I wanted to say thank you to everyone involved in setting this up - > Tom and Amit for organizing, and everyone who presented. It was fun to > get a chance to see what other people are doing in clojure, and to get > a preview of what Rich has been working on and to hear his thoughts on > near-to-mid term directions for the language. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Clojure contrib http-agent hangs when making a POST request
Hi, I'm getting some strange errors when trying to make a POST request using the Clojure contrib http-agent library (http:// richhickey.github.com/clojure-contrib/http.agent-api.html). When I run: (use 'clojure.contrib.http.agent) (println (string (http-agent "http://www.google.com"; :method "POST" :body "param=true"))) The REPL simply hangs forever. However, when I run the following: (def agt (http-agent "http://www.google.com"; :method "POST" :body "param=true")) ;...wait a bit or add a (Thread/sleep 1000) (println (string agt)) I get a correct response (Google saying it doesn't like POST requests) Also, the (result ... ) function appears to work fine also: (println (result (http-agent "http://www.google.com"; :method "POST" :body "param=true"))) So it looks like something in the (string ... ) function is causing it to hang if the response has not yet completed. Anyone have any idea what might be causing this? Thanks, Alex Does anyone have any ideas why --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure contrib http-agent hangs when making a POST request
Rob, that's perfect. Thanks very much for looking into that and supplying the patch. Hopefully we can get that applied to the source in git. On Oct 30, 9:58 pm, Rob Wolfe wrote: > Alex writes: > > Hi, > > > I'm getting some strange errors when trying to make a POST request > > using the Clojure contrib http-agent library (http:// > > richhickey.github.com/clojure-contrib/http.agent-api.html). > > > When I run: > > > (use 'clojure.contrib.http.agent) > > > (println (string (http-agent "http://www.google.com"; :method > > "POST" :body "param=true"))) > > > The REPL simply hangs forever. > > > However, when I run the following: > > > (def agt (http-agent "http://www.google.com"; :method "POST" :body > > "param=true")) > > ;...wait a bit or add a (Thread/sleep 1000) > > (println (string agt)) > > > I get a correct response (Google saying it doesn't like POST requests) > > > Also, the (result ... ) function appears to work fine also: > > > (println (result (http-agent "http://www.google.com"; :method > > "POST" :body "param=true"))) > > > So it looks like something in the (string ... ) function is causing it > > to hang if the response has not yet completed. Anyone have any idea > > what might be causing this? > > I guess the problem is in "string" function, because it tries > to get "content encoding" of stream which is not available. > In this case output stream was presumably closed by server. > So I can see two solutions: > > 1) always waiting until request is completed using "result" function > > > (ns test2 > (:require [clojure.contrib.http.agent :as http] > [clojure.contrib.duck-streams :as ds])) > > (let [agnt > (http/http-agent "http://www.google.com"; > :method "POST" > :body "param=true")] > (http/result agnt) > (println "string: " (http/string agnt))) > (shutdown-agents) > > > 2) applying this patch on original clojure.contrib.http.agent, > which imho solves this problem > > > --- a/src/clojure/contrib/http/agent.clj > +++ b/src/clojure/contrib/http/agent.clj > @@ -263,9 +263,12 @@ > headers, or clojure.contrib.duck-streams/*default-encoding* if it is > not specified." > ([http-agnt] > - (string http-agnt (or (.getContentEncoding > - #^HttpURLConnection (::connection @http-agnt)) > - duck/*default-encoding*))) > + (let [a @http-agnt] > + (if (= (::state a) ::receiving) > + (string http-agnt (or (.getContentEncoding > + #^HttpURLConnection (::connection > @http-agnt)) > + duck/*default-encoding*)) > + (string http-agnt duck/*default-encoding* > ([http-agnt #^String encoding] > (.toString (get-byte-buffer http-agnt) encoding))) > > > HTH, > Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
scope of binding
Hi, I have a question about the scope of "binding" of a var. Let's say I have the following var: (def *v* 1) And I define a function that uses it: (defn f [n] (+ *v* n)) "binding" behaves as expected, establishing a thread-local binding to a new value in its scope: user=> (binding [*v* 2] (f 1)) 3 But if I pass it to "map", I expected it to pick up the new value, but it does not. user=> (binding [*v* 2] (map f [1 1 1])) (2 2 2) The output should be "(3 3 3)" if I understand it correctly. Where am I wrong? -- 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: scope of binding
D'oh! Thanks. I fall for that trap yet again. Sounds so simple when explained. 2010/2/9 Sean Devlin : > The problem is that map returns a lazy seq, and the lazy seq is > evaluated outside of the binding by the REPL. If you add a doall > inside the binding, it behaves as you expect. > > user=> (binding [*v* 2] (doall (map f [1 1 1]))) > (3 3 3) > > Sean I know I've omitted this detail, but the actual code in question is actually *db* binding from clojure.contrib.sql, so I can't change it either way. doall works fine though. 2010/2/9 Richard Newman : > You can also capture the binding. This looks a little ugly, but it works: it > grabs the binding eagerly, and returns a closure that dynamically binds it > when the function is invoked. > > (binding [*v* 2] > (map (let [v *v*] > (fn [n] > (binding [*v* v] > (f n > [1 1 1])) > > Obviously you wouldn't use it in this instance -- use doall, or better yet > rewrite your function to not use dynamic bindings -- but for larger jobs it > works fine. -- 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: Negation in core.logic
Hi, Norman Richards, In the example, "arg" and "goal" were not literal but were meant to be replaced with something appropriate to whatever you are trying to do. Yes, unless you use a projected value, it is equivalent to precomputing it outside the run*. The point was that, although very hacky, there is a way to create a goal which succeeds if, and only if, another goal fails. Having said that, David Nolen's "nafc" constraint sounds much better and I am going to check it out right now. On Sat, Aug 10, 2013 at 12:05 AM, Norman Richards wrote: > Sorry - gmail spasm > > What I was trying to say is that what I think your code is doing is > running a Clojure expression once and unifying with 0. It's equivalent to > precomputing that outside of the run*: > > (let [result (count (run* [arg] (goal arg))] > (run* [q] > ;; whatever-else-you-were doing > (== 0 result))) > > Now, of course that expression could use some projected value or be > embedded in a goal that gets tested multiple times, but chances are that > the naive uses of that are probably not doing what you really want to do. > > -- > -- > 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 a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/clojure/hz63yeQfiQE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Sum up second elemsts of pairs in a sequence by grouping by the first item in pair
Hello everybody, How to transform sequence *[[1 0.5] [1 0.7] [2 1.0] [3 0.1] [3 0.1]]* to *[[1 1.2] [2 1.0] [3 0.2]]* ? Best regards, Alex -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Functional Programming Jobs across the globe! www.functionalworks.com
Check out our new platform (built in Clojure/Clojurescript), the one stop shop for Functional Programming roles across the globe. Check it out .. www.functionalworks.com -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Functional Programming Job Board - Clojure
Morning Everyone, For those of you that are looking for your next FP gig then check out the worlds leading Functional Programming job board! Functional Works <https://functional.works-hub.com/?utm_source=Clojure-google-group&utm_medium=Google-group&utm_campaign=alex> thanks, Alex -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Best Book for Clojure
That's very subjective, but I'd vote for "Joy of Clojure" for understanding ideas behind language design and some idiomatic use cases. I'd not recommend "Clojure Programming" for start, as it's very comprehensive and dives deep into detailes(which was a minus when I was starting with Clojure and wanted some quick wins), so I mostly use it as a language reference in my everyday job. But again, that's all subjective and depends on your experience and learning approach. "Brave and true" also seems to be quick and lightweight starting(and only starting) point, if you're comfortable with all that zombies and vampires in examples which are far from real life. среда, 14 марта 2018 г., 2:44:55 UTC+2 пользователь pbi...@gmail.com написал: > > I want to buy a book. > Which is the best book for clojure? > > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ANN] A complete draft of "Elements of Clojure" is available
Thanks for your work Zach пятница, 16 марта 2018 г., 18:21:19 UTC+2 пользователь Zach Tellman написал: > > Almost exactly two years ago, I announced on this mailing list that I was > working on an intermediate-level book on Clojure [1], and released the > first chapter. I've confined updates since then to a book-specific list, > but I feel like it's fair to post here again to say that the fourth and > final chapter has been released. Details can be found on the book's > mailing list: > https://groups.google.com/forum/#!topic/elements-of-clojure/t_Uqc8F0Ch0. > > If you haven't heard about the book before, please check out its website: > http://elementsofclojure.com/ > > Zach > > > [1] https://groups.google.com/forum/#!msg/clojure/Nh_Z0XaxhTA/P-lPdf2NDQAJ > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ANN] zakon 0.1.0
Zakon is declarative authorization library which unleashes all the power of multimethods. Github: https://github.com/dawcs/zakon -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (type ...) vs (class ...)
Looks like pre defrecord stuff used in early days to add "type" to map. Can still be used if you need "type" on a map without using defrecord. среда, 24 октября 2018 г., 10:30:14 UTC+3 пользователь Didier написал: > > Reviving this thread, as I'd like to kmow if someone can explain the > purpose of the type metadata and what is responsible for adding 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ANN] flow 0.3.1
flow is a tiny library for declarative errors handling without monads https://github.com/dawcs/flow -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: An Error spec?
How about using exception instances as errors? That plays pretty nicely with ex-info and (try ... (catch Exception e e)). I've built https://github.com/dawcs/flow on top of that approach and that seems like pretty good abstraction. Despite I'm not sure about CLJS. Anomalies are also great and you may check out https://github.com/dawcs/anomalies-tools for some tooling around it. But you may still need a bridge to convert exceptions caught from 3rd-party java libs into anomalies structure. And despite Cognitect roots, it doesn't feel like "official standard". пятница, 26 октября 2018 г., 4:46:54 UTC+3 пользователь Didier написал: > > I've started to see a pattern in my spec like this: > > (s/or :success string? > :error ::error) > > And I've been tempted to create my own spec macro for this. But I also > thought, maybe Spec itself should have such a spec. > > (s/error ) > > What do people think? > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ANN] 1.10.0-beta5
No, that will not work exactly like Ruby eigenclass, cause eigenclass has a priority when method lookup is performed. In Clojure case if instance's class has implementation of method, it will be preferred instead of meta version. If I understand everything correctly. четверг, 8 ноября 2018 г., 12:33:10 UTC+2 пользователь Rick Moynihan написал: > > Cool, so I guess it's the clojure of equivalent of Ruby's eigenclasses: > > f = "some object" > class << f > def foo > "new foo method on f" > end > end > > f.foo # => "new foo method on f" > > It's a shame this mechanism only works for values implementing IMeta, but > I understand the JVM is a little prohibitive in this regard. > > Even so I suppose the main use of this is that it lets a caller give you a > value, and you can return a plussed up version with new capabilities, > without having to return a wrapped value. Wrapped values are sometimes > problematic because they introduce new representations of existing types, > and this allows an API to return values to the caller that behave the same > as what went in. Neat! > > R. > > On Tue, 6 Nov 2018 at 15:51, Alex Miller > wrote: > >> >> On Tuesday, November 6, 2018 at 9:25:31 AM UTC-6, John Schmidt wrote: >>> >>> Nice to see continued progress on Clojure 1.10! >>> >>> It is not clear to me what metadata extension provides that is not >>> already possible with direct definitions or external extensions. Some >>> additional background or a small motivating example would be much >>> appreciated in clearing up the confusion! >>> >> >> Metadata extension allows you to implement protocols on a per-value basis >> (the others are type/class-oriented). This opens up a whole new range of >> potential uses for protocols. Rich was already using this approach for the >> new datafy/nav functionality - this made it generic for all protocols. >> >> Any collection instance can carry metadata, so you can take any >> collection instance and dynamically extend a protocol to it by adding >> metadata. So if you think about something like Component, which has a >> Lifecycle protocol for start/stop, you can now make lightweight components >> without needing to make a type or reify: >> >> $ clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-beta5"}, >> com.stuartsierra/component {:mvn/version "0.3.2"}}}' >> Clojure 1.10.0-beta5 >> user=> (require '[com.stuartsierra.component :as component]) >> nil >> user=> (def c (with-meta {:state :init} >> {`component/start (fn [c] (assoc c :state :started)) >> `component/stop (fn [c] (assoc c :state :stopped))})) >> #'user/c >> user=> (component/start c) >> {:state :started} >> user=> (component/stop c) >> {:state :stopped} >> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: An Error spec?
Thanks Sean, simple api is really main goal in Flow design. Initially we had much more sugar, but resulting version is pretty concise. We use it in production at Eventum, mostly in graphql resolvers/mutations and we're quite happy with it. четверг, 8 ноября 2018 г., 21:18:18 UTC+2 пользователь Sean Corfield написал: > > Flow reminds me a bit of a project I started in early 2015 and decided to > sunset in late 2016: https://github.com/seancorfield/engine > > > > We actually used Engine at work for a while but decided the resulting code > was both harder to read and not really very idiomatic. I’ll be interested > to hear how people find Flow in production – it’s a lot more focused and > simpler than Engine (which is definitely a good thing! 😊 ). > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > -- > *From:* clo...@googlegroups.com > on behalf of alex > > *Sent:* Wednesday, November 7, 2018 2:05:28 PM > *To:* Clojure > *Subject:* Re: An Error spec? > > How about using exception instances as errors? That plays pretty nicely > with ex-info and (try ... (catch Exception e e)). I've built > https://github.com/dawcs/flow on top of that approach and that seems > like pretty good abstraction. Despite I'm not sure about CLJS. > Anomalies are also great and you may check out > https://github.com/dawcs/anomalies-tools for some tooling around it. But > you may still need a bridge to convert exceptions caught from 3rd-party > java libs into anomalies structure. And despite Cognitect roots, it doesn't > feel like "official standard". > > пятница, 26 октября 2018 г., 4:46:54 UTC+3 пользователь Didier написал: >> >> I've started to see a pattern in my spec like this: >> >> (s/or :success string? >> :error ::error) >> >> And I've been tempted to create my own spec macro for this. But I also >> thought, maybe Spec itself should have such a spec. >> >> (s/error ) >> >> What do people think? >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+u...@googlegroups.com . > For more options, visit https://groups.google.com/d/optout. > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: An Error spec?
Sean, thanks for your feedback! Instance of Throwable is fail anyway and I can't imagine a situation when it's not. **exception-base-class** only sets behavior of *call* - what we should catch and what will be thrown. Probably naming is kinda ambiguous here and **exception-base-class** should be called **catch-from* *to make its purpose more clear without reading docstring. пятница, 9 ноября 2018 г., 8:05:18 UTC+2 пользователь Sean Corfield написал: > > Alex, I’m curious, should this > https://github.com/dawcs/flow/blob/master/src/dawcs/flow.clj#L53 use * > *exception-base-class** rather than Throwable directly? > > > > It looks very interesting and elegant – I’ll probably give this a test > drive next week! > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > -- > *From:* clo...@googlegroups.com > on behalf of alex > > *Sent:* Wednesday, November 7, 2018 2:05:28 PM > *To:* Clojure > *Subject:* Re: An Error spec? > > How about using exception instances as errors? That plays pretty nicely > with ex-info and (try ... (catch Exception e e)). I've built > https://github.com/dawcs/flow on top of that approach and that seems > like pretty good abstraction. Despite I'm not sure about CLJS. > Anomalies are also great and you may check out > https://github.com/dawcs/anomalies-tools for some tooling around it. But > you may still need a bridge to convert exceptions caught from 3rd-party > java libs into anomalies structure. And despite Cognitect roots, it doesn't > feel like "official standard". > > пятница, 26 октября 2018 г., 4:46:54 UTC+3 пользователь Didier написал: >> >> I've started to see a pattern in my spec like this: >> >> (s/or :success string? >> :error ::error) >> >> And I've been tempted to create my own spec macro for this. But I also >> thought, maybe Spec itself should have such a spec. >> >> (s/error ) >> >> What do people think? >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+u...@googlegroups.com . > For more options, visit https://groups.google.com/d/optout. > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Clojure 1.10 issue: thrown? no longer works on macros
I'm not sure, but probably it behaves so because of throwing at macroexpand stage. вторник, 18 декабря 2018 г., 11:29:09 UTC+2 пользователь puzzler написал: > > Consider the following macro: > > (defmacro f [x] {:pre [(number? x)]} `(+ ~x 5)) > => (f 3) > 8 > => (f true) > Unexpected error (AssertionError) macroexpanding f at > (test:localhost:62048(clj)*:265:28). > Assert failed: (number? x) > > So, as expected it throws an AssertionError if passed a non-number. > However, the following test (using is from clojure.test) used to work > prior to 1.10, but now fails: > > => (is (thrown? AssertionError (f true))) > Unexpected error (AssertionError) macroexpanding f at > (test:localhost:62048(clj)*:268:56). > Assert failed: (number? x) > > What's odd is that the macro still throws an AssertionError, but the > `thrown?` inside the `is` is no longer intercepting the AssertionError, so > the test doesn't pass -- instead the error causes a failure in the test > suite. > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Scala/Clojure/F# - Functional Programming Advocates - New York/Chicago/San Fran
Hey All, I am currently working with some of the worlds most talented FP teams in the US to help them build out there Clojure, F# and Scala teams. If you are looking for a new gig within the Functional Space and want to work alongside some of the best engineers then drop me a line! a...@functionalworks.com Paying up to $180,000 + Benefits + Bonus + Stock! Look forward to hearing from you. thanks, Alex Mesropians -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Clojure Engineer - Top Tech House - Chicago - $180,000 +
Hey All, I am currently working alongside a top tech house over in Chicago that is building a distributed system using Clojure. They are now on the search for talented and experienced Clojure engineers to join their team. Paying up to $180,000 + Benefits + Bonus ! If you are interested in finding out all the details drop me a line a...@functionalworks.com thanks, Alex -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Contract - 3 Months - Clojure/Clojurescript/Reagent - London
Morning, I have just had a 3 month contract come up for a Clojure/Clojurescript/Reagent engineer here in London. Working for a top Clojure house! Drop me a line for more info or if you are interested! a...@functionalworks.com thanks, Alex -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Possible bug in clojure.java.jdbc
Hey all, I've been using clojure.java.jdbc to write a simple database app. When I use the `update-or-insert-values` function, I get an SQLException thrown whenever my column names have special characters in them (like a space or an ampersand). I think the solution is in line 908: the column-strs should be quoted before calling `interpose`. If you do `(map #(str "\"" %1 "\"") column-strs)` that should do it? I can get around this by just writing my own version, but I wanted to patch it for everybody. I was told in #clojure that I can't? Anyways, I'm going to try to get in contact with the maintainer, but if anyone here has contributing rights, and would like to patch it, you have my thanks. --semisight -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Possible bug in clojure.java.jdbc
@Andy: Sorry, I didn't know the proper channel, I'll post it there. I don't control the column names. They're imported from an excel spreadsheet or assigned by the client I'm writing the app for. From experience, it is certainly *possible*, at least to add these columns. Currently I just have a function that "escapes" the user input, replacing special characters with lookalikes (i.e. space with an underscore). On Tuesday, February 5, 2013 10:42:50 PM UTC-8, Sean Corfield wrote: > > Andy's right on process... but as maintainer of clojure.java.jdbc, I > have to ask: why on earth do you have column names containing spaces > or & or other weird characters? That's a serious question: how do you > get into that situation? > > I'm not saying clojure.java.jdbc can't be updated to support it, I'm > just questioning whether it should... > > On Tue, Feb 5, 2013 at 7:32 PM, Andy Fingerhut > > > wrote: > > You can create a ticket for java.jdbc here if you wish that describes > the problem and what you think will fix it. Then any of the 500+ Clojure > contributors can take a shot at fixing it: > > > > http://dev.clojure.org/jira/browse/JDBC > > > > Andy > > > > On Feb 5, 2013, at 7:07 PM, al...@bitlimn.com wrote: > > > >> Hey all, > >> > >> I've been using clojure.java.jdbc to write a simple database app. When > I use the `update-or-insert-values` function, I get an SQLException thrown > whenever my column names have special characters in them (like a space or > an ampersand). I think the solution is in line 908: the column-strs should > be quoted before calling `interpose`. If you do `(map #(str "\"" %1 "\"") > column-strs)` that should do it? > >> > >> I can get around this by just writing my own version, but I wanted to > patch it for everybody. I was told in #clojure that I can't? Anyways, I'm > going to try to get in contact with the maintainer, but if anyone here has > contributing rights, and would like to patch it, you have my thanks. > >> > >> --semisight > > > > -- > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send > an email to clojure+u...@googlegroups.com . > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > > -- > Sean A Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > World Singles, LLC. -- http://worldsingles.com/ > > "Perfection is the enemy of the good." > -- Gustave Flaubert, French realist novelist (1821-1880) > -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
lein > swank > Aquamacs > slime-connect test failed. Help!
I'm new at clojure+emacs+slime+swank+leiningen and I wanted to run a (simple?) test that goes like this: $ lein new test-project; cd test-project $ cat > ./src/core.clj (ns test-project.core) (def *argh* 1) ; loop, printing *argh* every sec, for 100 secs (loop [i 0] (if (= i 100) (println "OK.") (do (println *argh*) (. Thread (sleep 1000)) (recur (+ i 1) Then, to test core.clj, I ran it from the command line: $ clj ./src/core.clj 1 1 1 etc. OK. Then, I did: $ lein swank user=> Connection opened on local port 4005 # First question: why no visible output? Still hoping, I launched emacs (actually Aquamacs, cuz I'm not that comfortable with yanking) and: 1. opened test-project/src/test_project/core.clj 2. M-x slime-connect Versions differ: 2010-09-22 (slime) vs. 20100404 (swank). Continue? (y or no) Hem. Why that? Plus, no output in the slime buffer. Just an REPL prompt. And a non-responsive one at that (I can type but nothing that I type is interpreted). So, just a prompt, really. 3. in the core.clj buffer, changed value of *arhg* to 2, placed cursor at the end of this, and evaluated the expression (^X ^E). No change on the slime-repl clojure side. I realize how little I understand about all this but would love to get started. Any advice much appreciated. Thanks Alex -- 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 > swank > Aquamacs > slime-connect test failed. Help!
I wrote this immediately after writing the code and running the test. I should have waited a bit because in retrospect the test is bound to fail. Guessing I should have used a transaction. On Sep 28, 7:17 pm, Alex wrote: > I'm new at clojure+emacs+slime+swank+leiningen and I wanted to run a > (simple?) test that goes like this: > > $ lein new test-project; cd test-project > $ cat > ./src/core.clj > (ns test-project.core) > > (def *argh* 1) > > ; loop, printing *argh* every sec, for 100 secs > (loop [i 0] > (if (= i 100) > (println "OK.") > (do > (println *argh*) > (. Thread (sleep 1000)) > (recur (+ i 1) > > Then, to test core.clj, I ran it from the command line: > $ clj ./src/core.clj > 1 > 1 > 1 > etc. > OK. > > Then, I did: > $ lein swank > user=> Connection opened on local port 4005 > # 127.0.0.1,port=0,localport=4005]> > > First question: why no visible output? > > Still hoping, I launched emacs (actually Aquamacs, cuz I'm not that > comfortable with yanking) and: > 1. opened test-project/src/test_project/core.clj > > 2. M-x slime-connect > Versions differ: 2010-09-22 (slime) vs. 20100404 (swank). Continue? (y > or no) > > Hem. Why that? Plus, no output in the slime buffer. Just an REPL > prompt. And a non-responsive one at that (I can type but nothing that > I type is interpreted). So, just a prompt, really. > > 3. in the core.clj buffer, changed value of *arhg* to 2, placed cursor > at the end of this, and evaluated the expression (^X ^E). No change on > the slime-repl clojure side. > > I realize how little I understand about all this but would love to get > started. Any advice much appreciated. > > Thanks > Alex -- 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 > swank > Aquamacs > slime-connect test failed. Help!
On Sep 29, 1:08 pm, Phil Hagelberg wrote: > On Tue, Sep 28, 2010 at 4:17 AM, Alex wrote: > > $ lein swank > > user=> Connection opened on local port 4005 > > # > 127.0.0.1,port=0,localport=4005]> > > > First question: why no visible output? > > Running "lein swank" just launches a swank server. It doesn't run any > of your project's code. Once you connect via slime, you can use C-c > C-k to compile a given namespace. But generally it's poor form to have > side-effects in the top-level; you should wrap your code in a defn and > run that function at the repl. > Understood. I need to read more on this because I'm not clear then on how to launch a simple "print X to stdout, sleep, then loop" app, while being able to communicate with it from emacs, and seeing consequent changes in the app's output. Aquamacs: I hear you. I came to the same conclusions last night and am now running emacs 23. Thanks again Alex -- 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
Clojure Community Values
If you have trouble viewing or submitting this form, you can fill it out online: https://docs.google.com/spreadsheet/viewform?formkey=dFpleU1QbVRyLWVXVElRMmJpQlpoYWc6MQ Clojure Community Values For no particular reason I got to thinking about things the Clojure community values in the style of the Agile manifesto, that is "we value ___ over ___" with the caveat that we may find both valuable, but one more than the other. This survey is not serious, or important, or binding. Maybe the results will be useless but perhaps they will be interesting. Blatant commercial: if you want to discuss, why not check out Clojure/West in San Jose, Mar 16-17 (http://clojurewest.org), early bird registration ends hmmm today! In the Clojure community, we value... * Emphatic yes Yes No Actually, the opposite Code over ideas Thinking over tests Data over interfaces Values over variables Public over private Accessibility over encapsulation Simple over easy Eggs over easy Man, you totally screwed up. These are better: Add one per line. If they're good I'll add them to the list above. Powered by Google Docs Report Abuse - Terms of Service - Additional Terms -- 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: Learning Clojure
To the debate on whether there should be examples early in the text, here are my two cents: When I click on something called "Learning [programming language]" I like to see a representative example of the syntax early on. If there's just text as far as the eye can see (that is, the first screen) it is off-putting for some reason. After all, it is a programming language. Alex On Dec 11, 2008, at 12:55 AM, Timothy Pratley wrote: > > Hi Brian, > > >> Rich talks about destructuring in the part about "let" on the >> "special >> forms" page. > > Ah indeed, thanks for pointing that out :) > > >> If you have any examples to add, please add them yourself (it is a >> wiki >> page). > > You've given some really good reasons why I shouldn't mess with it > *chuckle* so I'm getting mixed messages. If you do want me to add > example link, I'm happy to do that but for now I'm assuming you'd > prefer it left as is :) > > >> Thanks for your feedback. > > You are most welcome. > > > 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Gorilla: key combinations
Thanks for Gorilla. I am using it with MacVim. One (or :bug :pebkac) report... I put plugin/gorilla.vim in /Applications/MacVim.app/Contents/ Resources/vim/runtime/plugin/ and it seems to be loaded when MacVim starts. But the keybindings are not set up. \sr doesn't do anything (well, the 's' puts Vim in insert mode). I can do :ruby Gorilla::Repl.start() (which \sr is supposed to be bound to), and that works. I can also do :ruby Gorilla.setup_maps() and after that \sr starts the REPL as expected. I fixed this by adding the line "Gorilla.setup_maps()" before the "EOF" line in gorilla.vim, but I imagine that shouldn't be necesssary. Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Method overloading & proxy method
On Mar 23, 9:55 am, ronen wrote: > [... what] I actually need is a way of overriding specific methods (like the > visit > (MethodDeclaration n, A arg) and not all of them. I keep running into this problem again and again myself, so I thought I might post some notes. The short of it: doing anything fancy with proxy gets hard fast but there is a way to do it with gen-class. In my case I'd like to subclass java.io.InputStream and implement the abstract read() method but NOT override the non-abstract read(byte[] b) and read(byte[] b, int off, int len). So what I really want to do is something like this: (def is (proxy [java.io.InputStream] [] (read [] (int \a Which works okay for this: (.read is) => 97 But if anything calls the other overloaded methods like this: (.read is (make-array (. Byte TYPE) 10)) We get a: java.lang.IllegalArgumentException: Wrong number of args passed to: user$fn--1844$fn So it seems as Stuart explained, proxy overrdes all the "read" methods, not just the zero-arity one. So my next attempt was to use proxy-super. This was also the suggestion from my friendly neighbourhood Clojure guru, Mark Triggs: (def is (proxy [java.io.InputStream] [] (read [& args] (println args) (cond (= (count args) 0) (int \a) (= (count args) 1) (proxy-super read (first args)) (= (count args) 3) (proxy-super read (first args) (second args) (nth args 3)) (.read is) => 97 (.read is (make-array (. Byte TYPE) 10)) => java.lang.AbstractMethodError: java.io.InputStream.read()I 0: clojure.proxy.java.io.InputStream.read(Unknown Source) 1: java.io.InputStream.read(InputStream.java:154) 2: clojure.proxy.java.io.InputStream.read(Unknown Source) 3: java.io.InputStream.read(InputStream.java:85) 4: clojure.proxy.java.io.InputStream.read(Unknown Source) So what's going on here? Well, my (.read is bytes) is doing (proxy- super read bytes) okay. The java code then does a this.read(bytes, 0, bytes.size). So my code passes this through to the super-class again which finally does a this.read(). Unfortunately, as Mark explains "[proxy-super] works by temporarily hiding your overriding implementation of a method. For abstract classes that freaks out the JVM because it looks like you haven't implemented everything." So since read has been hidden, the java code attempting to call it just sees it's own abstract method which it obviously can't execute. In this case I can obviously resort to just reimplementing the other two methods, but it's a bit frustrating. This is a fairly common pattern in Java code, needing to subclass something and define one method foo() where there's a bunch of other overloaded convenience versions of it in the superclass which call the one you've overriden. Thankfully, Mark managed to figure out a way of doing it with with gen- class by using an undocumented (?) feature where you can put types into the method names so as to pick the exact one you want to override: (ns org.example.FancyInputStream (:gen-class :extends java.io.InputStream)) (defn -read-void [this] (int \a)) This now works as expected. Mark's notes on this are here: http://dishevelled.net/Tricky-uses-of-Clojure-gen-class-and-AOT-compilation.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 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: Poll for a new name for clojure eclipse plugin 'clojure-dev'
How about the name: jecl "jecl" breaks down: (j)ecl = (j)ava j(ec)l = (ec)lipse je(cl) = (cl)ojure jecl.net is not registered (yet) "develop clojure on eclipse with jecl" has a ring to it, I think ..and of course there is the story of Jekyll(clojure) and Hyde(java) where Jekyll is a good doctor and Hyde is the terrible monster that he turns into when he doesn't take his medicine. ;) But just an idea anyway :) --~--~-~--~~~---~--~~ 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: [OT] Convincing others about Clojure
I'm no expert but I love to argue, so this is what I would say: On Wed, Jun 24, 2009 at 10:59 PM, Baishampayan Ghose wrote: > > > Their concerns are thus: > > 1. How do you get Clojure programmers? Lisp is not for the faint hearted. There has been a lot of re-newed interest in lisp over the past couple years. > > > 2. What about the performance of Clojure? Is it fast? >From what I've heard and seen it is as fast as java itself in some cases because it sits natively on-top of the jvm 3. People who want to use this are more academically inclined and are > not practical. This will make the whole project fail. Rich Hicky, is a self described "practitioner" not an academic, and I think it is because of this that clojure is at its heart a very pragmatic language (for example: clojure is functional but doesn't enforce strict purity) and not just another intelectual exercise. I'm not trying to knock Simon Peyton Jones (the academic behind Haskel, the man is undoubtedly a genious), I'm simply saying clojure comes from a different angle. The reasons to chose clojure: 1. functional languages are the future, in a few years absolutely everything (even cellphones) will be multicore 2. sits on the jvm, a robust and open platform with access to thousands of librarys 3. a lisp --~--~-~--~~~---~--~~ 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: [OT] github (?) question
Yes Rich Hickey's git repository for clojure and clojure-contrib are the main development repositorys. http://github.com/richhickey/clojure/tree/master http://github.com/richhickey/clojure-contrib/tree/master The reason why git has no big flashing sign pointing to his repositorys is because git is a *distributed* version control system. In git's eyes every repository of clojure is just as good as every other repository, git would be perfectly happy to pull push and branch and merge from anyone's repository, so If you want to know which is the main development branch then you need to either find the link on the clojure.org website or else make an educated guess. Best regards, Alex On Fri, Jun 26, 2009 at 12:48 AM, Laurent PETIT wrote: > Hi, this is an OT question, but since Rich encouraged git gurus here on the > ml to on help non gurus, then I ask :-) > > By just surfing on github website, I find a cloned repository of > clojure-contrib, e.g. clone done by user XXX. > > From the main page of this repo, I can see who else cloned XXX's repo, who > else watches XXX's repo. > > But what I would like to do is see whether XXX's repo is a clone of another > repo, and go up the chain to the real "master" repo. > > Is this possible from the UI of github, or do I have to clone XXX's repo, > invoke some git command on my clone, ... and repeat the operation at each > node of the cloning graph ? > > > Thanks in advance, > > (Of course, for clojure-contrib I guess that Rich's repo is the master, but > still it's rather a guess than an evidence provided by the tools to me). > > -- > 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: [OT] Convincing others about Clojure
Thats great to hear, hope everything goes well, let us know how it turns out! Best regards, agc On Fri, Jun 26, 2009 at 1:55 AM, Baishampayan Ghose wrote: > Laurent, > > > Out of curiosity, which (combination of) advice do you think 'closed the > > deal' ? > > Well, the guy is a real startup veteran. I explained to him with some > help from a bunch of Paul Graham essays that we want to use Clojure just > because it is "practically" more suitable for the problem at hand and > not because we are academically inclined Lisp purists. > > I just needed to convince him that I am not religious about using _some_ > Lisp but I am choosing Clojure because as an Engineer I think that would > give us a distinct edge against the competitors. > > And the fact that Clojure runs on the JVM and has direct access to Java > libs helped the case. > > He, being a fairly intelligent and pragmatic man, accepted my logic. > > Thanks a bunch guys. > > Regards, > BG > > -- > Baishampayan Ghose > oCricket.com > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: java.ext.dirs problem
Hello, Undoubtedly it is not the best solution, but all I do is export a variable called CLASSPATH pointing to whichever directories I want to require or load. # append to your .bashrc script # Start CLASSPATH=/home/user/aaa:/home/user/bbb:$CLASSPATH export CLASSPATH # End The only gotcha so far that I've discovered is that you must not include the namespace in the path. For example with a file located here: /home/user/project/foo/bar.clj If the namespace of that file is (ns foo/bar) then do this: # correct CLASSPATH=/home/user/project:$CLASSPATH export CLASSPATH # wrong CLASSPATH=/home/user/project/foo:$CLASSPATH export CLASSPATH As for distributing your project all you would need is to put something like this into the script that you already use to launch your program. This is pretty simple but it works for me, just update my CLASSPATH variable and I'm good to go and I don't have to specify anything on the command line when I launch a repl. Best regards, agc --~--~-~--~~~---~--~~ 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: Troll in our midst - please ignore them
Hi Rich, Does this mean you're going to be moderating every post, or just posts from new accounts? Either way, perhaps you could start looking around for a couple of people who would do this job of moderating for you because I'm sure I'm not alone in thinking that your time would be best used elsewhere. :) However I do completely agree that more moderation is needed. Best regards, agc On Sun, Jun 28, 2009 at 11:51 AM, Rich Hickey wrote: > > It has become obvious to me we now have a troll in our midst, known > first as Wrexsoul, then Four of Seventeen, and now Handkea fumosa. > > In spite of their desire for anonymity, their posts identify them for > us: > > Posting too often > At too great a length, often histrionically and provocatively > With great consternation whenever Clojure doesn't align with their > expectations > Becoming argumentative when the facts are pointed out, or they are > disagreed with > Quick to make the discussion about the discussion itself, or > themselves > Degrading eventually to "is so!"/"is not!" drivel > > I have moderated all of these nicks, but it is likely that this person > will just show up with another. > > It is quite essential, if this group is not to degrade into > comp.lang.lisp, that people like this be completely ignored. > > So, as soon as someone says: > > Are you calling me a liar? > what the hell is causing this? > I'm shocked... > OMG!! Clojure is broken The sky will fall if Clojure isn't changed > to meet my needs! > > or anything else inflammatory, argumentative, impatient etc, just > ignore them. > > A great litmus test is this - does their post annoy you? Then don't > waste your time and energy with a reply. It is designed to annoy and > provoke you, so stifle it with inattention. > > We have had a lot of newbie questions answered here in a great spirit > of cooperation. Most are asked in a general indicator of desire to > learn, some even with some frustration, but also usually a dose of > 'this doesn't seem right, am I doing this correctly?', and the best > answers are informative, factual and supportive. Let's keep that up, > but when it becomes obvious someone isn't looking to participate in a > positive community, it is vital that we ignore them rather than argue > with them. > > It is doubly important not to reply in kind, in anger etc. > > On my end, I will be using moderation aggressively to shut this down. > So, if you are a new member you might find your posts get delayed, and > more than the first one. Please be patient and resist the urge to > double post, as I can only check the moderation queue a few times a > day. > > This community is great, positive, intelligent and helpful, and I'm > sure we can rise above this. > > Thanks, > > Rich > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Troll in our midst - please ignore them
On Sun, Jun 28, 2009 at 10:21 PM, CuppoJava wrote: > > Thank you Denfer, > That's a very interesting trick. I'm sure it'll be handy to me in the > future. I really never considered trolls a possibility on this forum. > It seems if that sort of thing interests you, there's much easier and > satisfying prey elsewhere. > heh, well if trolls had brains they wouldn't be trolls now would they? Best regards, agc --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Clojure Workshop in London next Monday
Next Monday evening we're hosting a Clojure Workshop at the ThoughtWorks offices in central London. This will be an introductory workshop where I hope that we'll all start to learn Clojure together. I'll present a quick introduction to what's interesting and different about Clojure, then we'll run a coding dojo to explore the language by implementing a simple program together. I'm aiming this event primarily at those who've started dabbling with Clojure or are interested in getting started. You won't need any previous experience with Clojure or any Lisp to get involved, but more experienced hands will be very welcome to guide us through the learning experience. All the info, including sign up link, here http://londongeeknights.wetpaint.com/page/Clojure+Workshop Hope to see some of you there, Alex --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
FYI Bug in "Programming Clojure" clojure download, wrt clojure.contrib.repl-utils/source
I just discovered that clojure.contrib.repl-utils/source (described on page 40 of the book "Programming Clojure") does not work with the version of the clojure.jar provided with the current code downloads for "Programming Clojure". Core functions do not properly report their source with that version of clojure.jar (apparently an old Clojure 1.1.0-alpha-SNAPSHOT). Used with either clojure.1.0.0.jar or an up to date clojure 1.1.0- alpha built from GitHub, the clojure.contrib.repl-utils/source function works fine. Kind regards, Alex Stoddard --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
London Clojurians
After the successful coding dojo held on Monday night [1], I've created a group for London Clojurians who want to get together to organise events, share learnings etc. It's at http://groups.google.com/group/london-clojurians Currently google thinks that the group is spam and won't let me post a welcome message - does anyone know what I can do about this? Alex [1] http://londongeeknights.wetpaint.com/page/Clojure+Workshop --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure Workshop in London next Monday
@Andrew, glad you enjoyed it :-) @Jim, sorry you missed it :-( There was quite a lot of interest in organising something to follow on from last Monday's event, so I've created a mailing list for London Clojure activity [1]. The next TW geek night is a pairing workshop [2] on September 8. [1] http://groups.google.com/group/london-clojurians/ [2] http://londongeeknights.wetpaint.com/page/Pairing+101 --~--~-~--~~~---~--~~ 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: Unable to use contrib
vishy wrote: > user=> (require 'clojure.contrib.math) > nil > user=> (lcm 4 5) > java.lang.Exception: Unable to resolve symbol: lcm in this context > (NO_SOURCE_FILE:2) The problem is that "require" only loads the math library, it doesn't "refer" to it. This means that you have to qualify lcm with the full namespace, like this: user=> (clojure.contrib.math/lcm 4 5) 20 You probably want "use" instead of "require", like this: user=> (use 'clojure.contrib.math) nil user=> (lcm 4 5) 20 Hope that helps. Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Basic questions
vishy wrote: > How can I find out all the namespaces in a library like > clojure.contrib. I assume you mean doing this at the REPL or OS shell. I don't know how to do it for non-loaded libs, aside from manually walking the classpath, but (all-ns) might be what you want for loaded namespaces. Usually I just look at the documentation or the source code of the library (eg. unzip -l clojure-contrib.jar | grep 'clj$'). > Also, how to find all the functions defined in a > namespace? There's some useful functions in clojure.contrib.ns-utils for printing documentation, for example: (use 'clojure.contrib.ns-utils) (docs clojure.xml) If you literally just wanted a list of all the functions in a namespace. then (ns-publics 'some.namespace) will give you a map of all the vars in the namespace. You could then just filter the ones that are functions. So something like: (defn ns-functions [ns] (for [[n, v] (ns-publics ns) :when (and (.isBound v) (instance? clojure.lang.Fn @v))] n)) (ns-functions 'clojure.xml) => (startparse-sax parse emit-element emit) Cheers, Alex --~--~-~--~~~---~--~~ 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: Duplicated keys in maps
On Oct 12, 11:55 am, Angel Java Lopez wrote: > I just discovered that maps support duplicated keys: > What is the rationale behind this behaviour? No, maps don't support duplicate keys. What you're seeing is due to an implementation detail in how array-maps are created from literals. You'll notice that if you create a map with more than 8 keys there won't be any duplicate keys. Here's Rich's reply from last time this was mentioned: http://groups.google.com/group/clojure/msg/7e330411cd04ca71 --~--~-~--~~~---~--~~ 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: Unable to resolve var
gL wrote: > The solution only works with a var name that equals to a Clojure name > (here "max"). That's because (binding) only works with a var that already exists, it doesn't create a new one. To create your own var (instead of abusing a clojure core one) just use "with-local-vars" instead of "binding" and "var-set" instead of "set!". But generally it's much easier to do it in a functional way making using of lazy sequence functions. > How do you access an element at a given place in a lazy sequence in a > more idiomatic way? (nth (lex-permutations [0 1 2 3 4 5 6 7 8 9]) 99) [Indexing starts at 0 so we use 99 instead of 100.] Cheers, Alex --~--~-~--~~~---~--~~ 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: JVM Language Summit talk on state, identity, time
Garth Sheldon-Coulson wrote: > In his blog post Rich mentioned his JVM Language Summit talk > on state, identity, value, time, etc. > > Does anyone know if audio or video was recorded, or (if Rich is reading > this) if there are more comprehensive notes to be gotten? The conclusion of it is here: http://www.youtube.com/watch?v=zRTx1oGG_1Y --~--~-~--~~~---~--~~ 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: difference between into & concat
DemAS wrote: > I'm just wondering if there is any difference between 'into' and > 'concat' ? There are actually more differences than similarities in my opinion. For starters, 'concat' can take more than 2 arguments: (concat [1 2] [3 4] [5 6]) => (1 2 3 4 5 6) 'into' returns whatever collection type is passed in, so for a vector: (into [1 2] [3 4]) => [1 2 3 4] or a map: (into {:a 1} [[:b 2] [:c 3]]) => {;a 1, :b 2, :c 3} while 'concat' (being lazy) will always return a lazy seq: (concat [1 2] [3 4]) => (1 2 3 4) (concat {:a 1} [[:b 2] [:c 3]]) => ([:a 1] [:b 2] [:c 3]) > I have found only one difference - the 'concat'-functon sorts resulted > list. Neither of them do any sorting, even in your example with ranges the output is not sorted. The difference in the ordering is because concat keeps the seqs (in your example ranges) ordered: (concat (range 1 5) (range 11 15)) => (1 2 3 4 11 12 13 14) While 'into' just repeatedly applies the 'conj' function, which for a seq will add each element to the front of the seq, instead of the end, so the second range appears in reverse in front the first: (into (range 1 5) (range 11 15)) => (14 13 12 11 1 2 3 4) When used on a vector however, 'conj' adds to the end, so we get: (into (vec (range 1 5)) (range 11 15)) => [1 2 3 4 11 12 13 14] --~--~-~--~~~---~--~~ 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: Best way to run multiple filters on the same [lazy] collection?
Meikel Brandmeyer wrote: > Maybe you can do: > > (reduce (fn [[sales upgrades demo :as v] data] >(cond > (is-sales? data) [(conj sales data) upgrades demo] > (is-upgrade? data) [sales (conj upgrades data) demo] > (is-demo? data)[sales upgrades (conj demo data)] > :else v)) > [[] [] []] (get-idata)) Another variation: (use 'clojure.contrib.seq-utils) (defn record-type [data] (cond (is-sale? data) :sales (is-upgrade? data) :upgrades (is-demo? data) :demos)) (group-by record-type (filter record-type (get-idata))) If the three output lists themselves are too large, I'd just explicitly sum your units with reduce: (reduce (fn [counts data] (let [type (record-type data)] (assoc counts type (+ (units data) (get counts type 0) {} (get-idata)) => {:sales 1233, :upgrades 17, :demos 42, nil 30} --~--~-~--~~~---~--~~ 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: Best way to run multiple filters on the same [lazy] collection?
Alex Osborne wrote: > If the three output lists themselves are too large, I'd just explicitly > sum your units with reduce: > > (reduce > (fn [counts data] > (let [type (record-type data)] > (assoc counts type (+ (units data) > (get counts type 0) > {} (get-idata)) > > => {:sales 1233, :upgrades 17, :demos 42, nil 30} Actually come to think of it, this sort of thing is common enough that you could pull out a 'reduce-by' function like this: (defn reduce-by [grouper f val coll] (reduce (fn [m x] (let [group (grouper x)] (assoc m group (f (get m group val) x (sorted-map) coll)) Then group-by could be easily defined in terms of it: (defn group-by [f coll] (reduce-by f conj [] coll)) And it makes your unit summing example: (reduce-by record-type (fn [count data] (+ count (units data))) 0 (get-idata)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: Clojure live-repl
David Powell wrote: > It uses the Java Attach API to let you connect a Clojure REPL to any running > Java or Clojure process, without them requiring any special startup. Exceedingly cool! > It probably requires a Sun 1.6 JDK. And currently the startup script is a > batch file, so if anyone can knock a Bourne shell script together that would > be cool. This worked for me: http://gist.github.com/212785 --~--~-~--~~~---~--~~ 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: Best way to run multiple filters on the same [lazy] collection?
Dmitry Kakurin wrote: > I actually like your "tag them then group them" approach. > But what if the same record can have multiple tags? > E.g. :sales and :upgrades? > Hmmm. the first way that occurred to me is just make your tagging function return a set: (defn record-types [x] (disj #{(when (is-sale? x) :sales) (when (is-upgrade? x) :upgrades) (when (is-demo? x) :demos)} nil)) So you'd then get groups like: {#{:sales :upgrades} [...] #{:sales} [...] #{:upgrades}[...]} But unfortunately it seems that because the group-by in clojure.contrib.seq-utils uses a sorted-map it can't have keys that are sets (as there's no ordering defined for sets). You could either use vectors instead of sets, or better yet lets just define reduce-by and group-by to use a hash-map instead: (defn reduce-by [grouper f val coll] (reduce (fn [m x] (let [group (grouper x)] (assoc m group (f (get m group val) x {} coll)) (defn group-by [grouper coll] (reduce-by grouper conj [] coll)) This has the advantage that you can do things like intersections ("number of sales sales that were also upgrades"). If you don't care about intersections and just want the three :sales, :upgrades, and :demos lists, then I guess we start with 'for' to generate [tag record] pairs: (for [record (get-idata) type (record-types record)] [type record]) So if "data1" is both sales and upgrades then you'd get: ([:sales data1] [:upgrades data1] [:sales data2] [:demos data3] ...) We can then reduce-by grouped on the first value in the pair (the tag) and then transform the resulting maps to select just the second item in the pair (the record): (reduce-by first #(conj %1 (second %2)) [] (for [record (get-idata) type (record-types record)] [type record])) => {:sales [data1 data2 ... ], :upgrades [data1 data3 ...], :demos [data4 ...]} --~--~-~--~~~---~--~~ 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: Using synchronized keyword
Gorsal wrote: > I was wondering how to used the java keyword synchronized in clojure? http://clojure.org/api#locking Java: synchronized(foo) { ... } Clojure: (locking foo ...) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Printing to *out* in another thread
mbrodersen wrote: >> Using atoms is not a good idea. Unless you don't mind if the same >> message is sometimes printed more than once. Atoms are implemented >> using spin locks with automatic retry. > > Hmmm...unless add-watch => observer is called only once. Looking in clojure/lang/Atom.java: public Object swap(IFn f) throws Exception{ for(; ;) { Object v = deref(); Object newv = f.invoke(v); validate(newv); if(state.compareAndSet(v, newv)) { notifyWatches(v, newv); return newv; } } } So I guess that'd be a yes, it's only called once. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: agents swallowing exceptions?
Raoul Duke wrote: > apparently one has to manually write ones agents to log the exceptions > out to stderr or stdout? i guess my personal principle of least > surprise implementation would have been to at least spit out the first > exception once. The problem is where do you throw the exceptions? Due to the asynchronous nature of agents the thread that called send/senf-off is potentially long gone and is doing something else now. So the agent can't safely immediately throw it. Perhaps you're suggesting the agents should automatically catch all their own exceptions and then throw them to stderr. What if you want to handle them? For debugging I guess you can define your own version of send/send-off that wraps methods in a try/catch. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: data structures for efficient range queries
nchubrich wrote: > I need to make a data structure for a query such as "find everything > that is priced $3.27 - $6.12" (and perhaps sum up the total revenue > for all items in that price range). That's one of the things sorted maps are for: (let [objects-by-price (sorted-map 0.50 :cookie, 5.0 :lunch, 6.10 :movie, 200.0 :tv)] (take-while #(<= (key %) 6.12) (subseq objects-by-price >= 3.27))) => ([5.0 :lunch] [6.1 :movie]) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: data structures for efficient range queries
Alex Osborne wrote: > nchubrich wrote: >> I need to make a data structure for a query such as "find everything >> that is priced $3.27 - $6.12" (and perhaps sum up the total revenue >> for all items in that price range). > > > That's one of the things sorted maps are for: > > (let [objects-by-price (sorted-map 0.50 :cookie, 5.0 :lunch, >6.10 :movie, 200.0 :tv)] > (take-while #(<= (key %) 6.12) (subseq objects-by-price >= 3.27))) > > > => ([5.0 :lunch] [6.1 :movie]) > > >> The naive way would be to make an >> array with one slot for each increment in the entire range, and have >> each slot pointing to a bucket with all items at that increment (here, >> price). But this would not be terribly efficient or feasible over >> very large ranges Also, if you're wondering how sorted-map makes that fast, see: http://en.wikipedia.org/wiki/Binary_search_tree It just does a search and then traverses the tree from that point, so it takes O((log n) + m) time where n is the size of the tree and m is the number of items your query returns. Richard's suggestion of binary search in a sorted array is also a good option but is a bit of a pain if you need to add new items to the array. http://en.wikipedia.org/wiki/Binary_search --~--~-~--~~~---~--~~ 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: Redirecting Output
Gorsal wrote: > I'm trying to redirect the input i receive from a BufferedInputStream > to the repl. I'm trying something like this: > > (defmacro with-thread [nm & body] > `(let [thread# (Thread. (fn [] (do ~...@body)))] > (if ~nm (.setName thread# ~nm)) > (.start thread#) > thread#)) > > (defn redirect-stream [nm stream function] > (with-thread nm > (loop [the-char nil] > (if (and the-char (not (= the-char -1))) (jprint (char the- > char))) > (let [value (function stream the-char)] > (if (not value) > (recur (.read stream) > (and (> (.available stream) 0) > (.read stream)) > )) > However, this raises the CPU to about 50 percent. This is due to the > infinite recursion, I'm assuming? Yes, it's because you're tight looping, checking to see if data is available as fast as possible. A quick and dirty hack would be to put in a sleep to slow it down a bit. (if (> (.available stream) 0) (.read stream) (Thread/sleep 100)) A better option would be to use NIO and a selectable channel to block waiting for data availability: http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/Selector.html Then you can use wakeup() on the Selector to interrupt 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: sequence manipulation question
Dmitri wrote: > I notice that certain sequence operations such as concat and cons will > not retain the original type of sequence, for example if you combine > two vectors together a list will be returned: > > user=> (concat [1 2] [3 4]) > (1 2 3 4) > > is this intentional behavior, and would it not be more consistent for > concat to retain the original type of the data structures, when both > data structures that were passed in are of the same type. It's because concat returns a lazy sequence, the concatenation only happens when you ask for relevant elements (which has the benefit that it doesn't need to do any copying, saving both time and memory). If you want to concatenate two vectors eagerly (so returning another vector) you could use 'into' instead: user=> (into [1 2] [3 4]) [1 2 3 4] > Also, why > does cons behave differently from conj: > > user=> (conj [1 2] 3) > [1 2 3] > > user=> (cons 2 [1 2]) > (2 1 2) Because cons always creates a list (which construct at the front), while conj "adds" it in the natural (ie fastest) way for that collection type, vectors "add" at the end. user> (conj '(1 2) 3) (3 1 2) user> (conj [1 2] 3) [1 2 3] user> (conj #{1 2} 3) #{1 2 3} user> (cons 3 '(1 2)) (3 1 2) --~--~-~--~~~---~--~~ 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: sequence manipulation question
Oops, looks like the end of my message got cut off. Appended below. Alex Osborne wrote: > Dmitri wrote: > > I notice that certain sequence operations such as concat and cons will > > not retain the original type of sequence, for example if you combine > > two vectors together a list will be returned: > > > > user=> (concat [1 2] [3 4]) > > (1 2 3 4) > > > > is this intentional behavior, and would it not be more consistent for > > concat to retain the original type of the data structures, when both > > data structures that were passed in are of the same type. > > It's because concat returns a lazy sequence, the concatenation only > happens when you ask for relevant elements (which has the benefit that > it doesn't need to do any copying, saving both time and memory). If you > want to concatenate two vectors eagerly (so returning another vector) > you could use 'into' instead: > > user=> (into [1 2] [3 4]) > [1 2 3 4] > > > Also, why > > does cons behave differently from conj: > > > > user=> (conj [1 2] 3) > > [1 2 3] > > > > user=> (cons 2 [1 2]) > > (2 1 2) > > Because cons always creates a list (which construct at the front), while > conj "adds" it in the natural (ie fastest) way for that collection type, > vectors "add" at the end. > > user> (conj '(1 2) 3) > (3 1 2) > user> (conj [1 2] 3) > [1 2 3] > user> (conj #{1 2} 3) > #{1 2 3} user> (cons 3 '(1 2)) (3 1 2) user> (cons 3 [1 2]) (3 1 2) user> (cons 3 #{1 2}) (3 1 2) Usually you'll want to use conj, not cons. Note that when we do (cons 3 [1 2]) cons is making a cons cell that looks like this: +---+---+ | 3 | @-> (seq [1 2]) +---+---+ It's not converting the whole vector to a list, it just adds the element you cons'd on and points at the existing list. You can see that here: user> (type (cons 3 [1 2])) clojure.lang.Cons user> (type (rest (cons 3 [1 2]))) clojure.lang.APersistentVector$Seq --~--~-~--~~~---~--~~ 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: b:vimclojure_namespace does not exist
I'm not really a vim user, but I just tried this out as I was curious to see what vimclojure was like. It sounds like the nailgun server can't find clojure.jar, try checking the classpath you're using to launch the server. I get the exact same error if I set a bad classpath on purpose. eyeris wrote: > After further investigation, I've determined that it is silently > catching an exception in autoload/vimclojure., vim in > vimclojure#InitBuffer() around line 668. > Commenting out the try/catch/endtry lines gives me the error: > > "~/devel/xlsmerge/src/xlsmerge/gui.clj" 186L, 6430C > Error detected while processing function > vimclojure#InitBuffer..vimclojure#ExecuteNailWithInput: > line 19: > Couldn't execute Nail! java.lang.NoClassDefFoundError: clojure/lang/ > IFn at java.lang.Class.forName0(Native Method) at > java.lang.Class.forName(Class.java:186) at > com.martiansoftware.nailgun.NGSession.run(Unknown Source) > Error detected while processing function vimclojure#InitBuffer: > line9: > E171: Missing :endif > Error detected while processing /home/dvogel/.vim/syntax/clojure.vim: > line 19: > E171: Missing :endif > Error detected while processing function 5_SynSet: > line 22: > E170: Missing :endfor > > Running the command manually gives a more readable error: > > ~/devel/xlsmerge$ ~/devel/clj/vimclojure/ng > de.kotka.vimclojure.nails.NamespaceOfFile ~/devel/xlsmerge/src/ > xlsmerge/gui.clj > java.lang.NoClassDefFoundError: clojure/lang/IFn > at java.lang.Class.forName0(Native Method) > at java.lang.Class.forName(Class.java:186) > at com.martiansoftware.nailgun.NGSession.run(Unknown Source) > Caused by: java.lang.ClassNotFoundException: clojure.lang.IFn > at java.net.URLClassLoader$1.run(URLClassLoader.java:217) > at java.security.AccessController.doPrivileged(Native Method) > at java.net.URLClassLoader.findClass(URLClassLoader.java:205) > at java.lang.ClassLoader.loadClass(ClassLoader.java:323) > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) > at java.lang.ClassLoader.loadClass(ClassLoader.java:268) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336) > ... 3 more > > > > > > On Oct 19, 10:42 pm, eyeris wrote: >> I've installed the latest VimClojure. I've added to my .vimrc: >> >> let g:clj_want_gorilla = 1 >> let vimclojure#NailgunClient = ".../path/to/ng" >> au BufRead,Bufnewfile *.clj setfiletype clojure >> au BufRead,Bufnewfile *.clj setl lisp >> >> The ng client is executable. Yet when I open a .clj file, echo >> b:vimclojure_namespace I get two errors: >> >> E121: Undefined variable: b:vimclojure_namespace >> E15: Invalid expression: b:vimclojure_namespace >> >> VimClojure shouldn't be so hard to get working. This is my third time >> setting it up (once on Windows, once on two versions of Debian) and it >> never works according to the directions. > > --~--~-~--~~~---~--~~ 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: Redirecting Output
John Harrop wrote: > On Tue, Oct 20, 2009 at 12:07 AM, Alex Osborne <mailto:a...@meshy.org>> wrote: > > Gorsal wrote: > > However, this raises the CPU to about 50 percent. This is due to the > > infinite recursion, I'm assuming? > > Yes, it's because you're tight looping, checking to see if data is > available as fast as possible. A quick and dirty hack would be to put > in a sleep to slow it down a bit. > > > A blocking operation and Java's Thread.interrupt() method would be cleaner. Yes, that's why I suggested NIO. Apparently you can't interrupt an (old IO) read though: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4514257 --~--~-~--~~~---~--~~ 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: Best way to run multiple filters on the same [lazy] collection?
Dmitry Kakurin wrote: > Thanks Alex, this is a VERY elegant solution. Hehe. I think I got a bit carried away generalising mine, but I found it interesting. :-) I think your way or Meikal's juxt (which is really neat, I didn't know about juxt) is much better for this specific problem. I guess mine is more suited for when the 'groups' are derived from the data (like the 'SQLalike' examples Timothy came up with) rather than predefined by the code. > But there is still ex-C++ programmer sitting inside my head, screaming > "Ah, so many temporaries and lookups, this is so inefficient" :-). > I'll try to make "him" shut up by comparing perf with my multi-filter > approach. > On my PC your multi-filter is 3-4 times faster than my last reduce-by version, which I guess is not too bad considering my version has all those lookups and temporary objects (I tested by filtering a large range of integers into groups divisible by 2, 3 and 6). The JVM seems to be actually pretty fast at creating objects and Clojure does lots of little tricks to speed up lookups, like caching hash codes and using vectors instead of hash tables for small maps. To quiet my inner premature optimisation fanatic I usually rationalise with "the disk is going to be the bottleneck anyway" and "lets try the first way that occurs to me and only if it turns out to be too slow in practice only then tweak 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: Best way to run multiple filters on the same [lazy] collection?
Dmitry Kakurin wrote: >> Stylistic: you should not put the closing parens on dedicated lines. >> They are normally collected on the last line. While this is only a >> style issue, you should get used to it, since 99.9% of all code at in >> the wild will use that style... > > I've read it many times, and I've tried to do it. > But how do you solve this practical problem: > When you need to insert something in the middle, how do you find the > right closing paren > where to split it? I use TextMate if it matters. Most people writing in a lisp use an editor that does paren highlighting. So for example in Emacs, when I have something like this: (foo (bar (baz (quox '(a b c) It's hard to show this in an email but if I move the cursors (_) to the right of one of closing parens, then emacs will highlight the one it matches with, by changing the background colour: (foo (bar *(*baz (quox '(a b c)))_)) Some people also use something called "rainbow parens" which is where each pair of matching parens are colour coded. Others use s-expression highlighting, which colour codes the whole expression. You can see various versions of this here: http://lemonodor.com/archives/001207.html It's worth trying out an editor with Clojure support (Emacs with SLIME, Vim with VimClojure, Enclojure, the IDEA plugin etc), they have useful shortcuts like hotkeys for moving between s-expressions and you can quickly evaluate things from in your editor without having to switch to the REPL. For example if I write (apply + [1 2 3 4]) in a file in Emacs and hit Ctrl-X Ctrl-E then "10" appears in the status line. --~--~-~--~~~---~--~~ 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: Private multimethods possible?
samppi wrote: > Are private multis possible? I notice that clojure.contrib.def does > not have a defmulti-, which doesn't bode well, but it's still worth a > question at the mailing list. Yes, you can make any symbol private. If you look at the definition of defn- you'll see all it does is set the :private metadata entry on the function's name to true: (defmacro defn- "same as defn, yielding non-public def" [name & decls] (list* `defn (with-meta name (assoc (meta name) :private true)) decls)) This bears repeating as it may not be obious: symbols *themselves* are set private, not the functions (or other values) they are bound to. So you could do the same when defining a multimethod, just give the name (symbol) of the method the metadata ":private" with the value "true": (defmulti #{:private true} my-multi my-dispatch) --~--~-~--~~~---~--~~ 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: Private multimethods possible?
> So you could do the same when defining a multimethod, just give the > name (symbol) of the method the metadata ":private" with the value > "true": > > (defmulti #{:private true} my-multi my-dispatch) I'm having a bad day for typos, the example should of course be: (defmulti #^{:private true} my-multi my-dispatch) --~--~-~--~~~---~--~~ 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: Private multimethods possible?
John Harrop wrote: > I think we need some notion of semi-private as well. It would be ignored > by :use and by automation like tab-completion of symbols, doc > generation, and the like (except it would show in tab-completion inside > of its namespace) but would not actually be illegal to invoke from > elsewhere. So, it would be like private in every respect except for > invokability. I'd tentatively agree. Although perhaps another model would be to just put your semi-private declarations in a different namespace which is not normally :use'd. If you're really desperate you can get around the exception like this: user> (apples/foo 4) var: #'apples/foo is not public [Thrown class java.lang.IllegalStateException] user> (defmacro reveal [sym] `(deref ~(clojure.lang.Compiler/resolveIn *ns* sym true))) user> ((reveal apples/foo) 4) But that's no doubt a bad idea. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: invoking macros from Java
Jeff Brown wrote: > I can invoke a function using Java code that looks something like this... > > Reader reader = new FileReader("clj/demo.clj"); > Compiler.load(reader); > Var var = RT.var("demo", "add_numbers"); > Object result = var.invoke(4, 7); > System.out.println("Result: " + result); > > I am not sure how to invoke even_sillier_adder. Any help would be > appreciated. > Maybe I'm missing the point of the question, but can't you just do it exactly the same way? Reader reader = new FileReader("clj/demo.clj"); Compiler.load(reader); Var var = RT.var("demo", "even_sillier_adder"); Object result = var.invoke(4); System.out.println("Result: " + result); System.out.println("Result evaluated: " + Compiler.eval(result)); Output: Result: (foo/silly_adder 9) Result evaluated: 9 A macro is just a function that takes some code and returns some other code, so "invoking" a macro will return the code it evaluates to. If you want that to be then evaluated, then just ask the compiler to evaluate 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: Infinite sequences hang sets and maps
John Harrop wrote: > Probably the seq .hashCode should consider only the first N elements > for some maximum N and if two longer (or even infinite) sequences > collide so be it. I strongly disagree. Choosing some arbitrary magic cutoff point just seems cause for trouble and much confusion. Putting something in a hash set or using it as a map key implies evaluating it -- you'd expect summing or printing an infinite sequence to hang, so why shouldn't hashing it also hang? Also to those suggesting treating infinite sequences differently to regular ones: it's impossible to determine (in the general case) whether a sequence is infinite or not as it would involve solving the halting problem. Throwing an exception in some specific cases would require changing things like (repeat x) to use a different seq implementation class. I think this would gain you very little since there's only a couple of cases where this can be done and as soon as you do something with the seq you don't know whether it's infinite anymore. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Constructing Java Interop calls
Tiago Antão wrote: > Again, the point here is to be able to construct method names (full > call signatures, really) on runtime. > > I am lost. As in newbie clueless :( As others have suggested you need to use either Java's reflection or Clojure's eval. Here's some examples: Using reflection: (let [obj "some string" method (.getDeclaredMethod (class obj) "substring" (into-array Class [Integer/TYPE]))] (.invoke method obj (to-array [2]))) => "me string" If you want to know more about what you can do with reflection, consult: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html Using eval (which will also work for dynamically calling Clojure functions): (let [obj "some string" fname ".substring"] (eval (list (symbol fname) obj 2))) => "me string" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: cannot cast error java char-array to java string
Chick Corea wrote: > What is wrong with this code? I want to instantiate a Java String > from a Java character-array. > But I want it to be fast, hence the need to cast per the "warn on > reflection" message. > > user=> (set! *warn-on-reflection* true) > true > user=> (new String #^"[C" (make-array Character/TYPE 3 \a )) > java.lang.ClassCastException: [[C cannot be cast to [C > (NO_SOURCE_FILE:0) Note the exception, "[[C" means a two-dimensional arary. (make-array Character/TYPE 3 \a) actually means (make-array Character/TYPE 3 97) so a 3 by 97 two-dimensional array (new char[3][97] in java syntax). What you probably want is: user> (String. #^"[C" (into-array Character/TYPE (repeat 3 \a))) "aaa" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: Clojure live-repl
David Powell wrote: > >> Under Linux I had to fix the paths in liverepl.sh to include the >> build folder: >> >> java -cp "$LIVEREPL_HOME/build/*:$JDK_HOME/lib/tools.jar" >> net.djpowell.liverepl.client.Main "$CLOJURE_JAR" >> "$LIVEREPL_HOME/build/liverepl-agent.jar" >> "$LIVEREPL_HOME/build/liverepl-server.jar" "$@" > > I think liverepl.sh gets copied to the build folder, so the intent is > to run that copy of the liverepl.sh script. (Though I haven't really > tested the .sh script) > Yeah, that's how I did it (based on what the batch file was doing). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Java 7, nio, and createFile
youngblood.carl wrote: > When I try and call createFile from clojure: > (.createFile path) > > I get an exception that there is no field named createFile. If I remember correctly variable argument Java methods, which is what that "..." syntax means: abstract Path createFile(FileAttribute... attrs) {} are actually just syntactic sugar for an array argument: abstract Path createFile(FileAttribute[] attrs) {} so try: (.createFile path (make-array FileAttribute 0)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Infinite sequences hang sets and maps
John Harrop wrote: > On Wed, Oct 28, 2009 at 9:35 PM, Alex Osborne wrote: > > Choosing some arbitrary magic cutoff point just > seems cause for trouble and much confusion. > > For the specific case of hashCode, no; identical values must have > identical hashes but different values need not have different hashes. > Collisions due to the hypothetical cutoff get exponentially less likely > with each additional increment of 1 of the cutoff length. Yeah, that's true, but I meant in the usual context where you fall back to equality in the event of a collision (like, as you say, sets and maps). I think it would be very confusing if when you put an infinite sequence in one set it works (because there's no collision so it uses the cutoff) while putting the exact same sequence in a different set it hangs (because of a collision it falls back to equality). I can imagine that being a nightmare to debug particularly because in most programs it will only happen very rarely. --~--~-~--~~~---~--~~ 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: Newcomer's question about Clojure's compatibility with common lisp
Daniel Simms wrote: > On Thu, Oct 29, 2009 at 4:34 PM, Rayne wrote: >> but I would highly recommend that you just pull it from the github >> repository. > > Especially if you're going to use clojure-contrib ...or is there some > "release" of contrib synch'd to clojure releases that I missed > somewhere? There's a 1.0 compatible branch on github. You get it with: git clone git://github.com/richhickey/clojure-contrib.git cd clojure-contrib git checkout origin/clojure-1.0-compatible Or download a tarball from: http://github.com/richhickey/clojure-contrib/archives/clojure-1.0-compatible --~--~-~--~~~---~--~~ 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 make lazy seq from socket input?
timc wrote: > I think I know how to do fileLines, but not socketLines. (Each > received packet should contain one line as it would have been written > to a file, I think). Something like this? (use 'clojure.contrib.duck-streams) (read-lines (.getInputStream socket)) > My problem is not how to manage a server socket, > but how to make an ISeq -- i.e. what exactly is the contract that ISeq > defines (the source code has no comments). You wouldn't usually implement ISeq directly in Clojure code, you'd use the lazy-seq function. A simple example from clojure.core: (defn repeat "Returns a lazy (infinite!, or length n if supplied) sequence of xs." ([x] (lazy-seq (cons x (repeat x ([n x] (take n (repeat x It's lazy because lazy-seq doesn't evaluate it's body until you ask for it (by calling 'seq', 'first' or 'next' on it). As you access the seq a linked list is generated. So initially there's just a LazySeq object: Then the body of lazy-seq is evaluated creating a cons cell of the value x and (repeat x) which evaluates to another LazySeq: first next +---+---+ | x | |> +---+---+ And so on it repeats: first nextfirst next +---+---++---+---+ | x | |> | x | |> +---+---++---+---+ So we could make a simple function that returns a sequence of lines by calling .readLine over and over on an object: (defn readline-seq [rdr] (lazy-seq (cons (.readLine rdr) (readline-seq rdr However, we also want to stop at the end of the file, so we put in a check for the line being null: (defn readline-seq [rdr] (lazy-seq (when-let [line (.readLine rdr)] (cons line (readline-seq rdr) This is exactly how core/line-seq is defined, and duck-streams/read-lines is the same except it also takes care of adapting whatever you pass in (like a File or InputStream) to a BufferedReader (which provides the readLine method). As for ISeq, take a look at Range.java for a simplish example. You just need to implement the two methods, first() which returns the first thing in the seq and next() which returns a new seq (ie another instance of your class) representing the next part of the seq (so seq.next().first() is the second item, seq.next().next().first() is the third item and so on). Hope that explanation was clear enough. --~--~-~--~~~---~--~~ 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: Implementation of zipmap
John Harrop wrote: > Was something wrong with this?: > > (defn my-zipmap > "Returns a map with the keys mapped to the corresponding vals." > [keys vals] > (into {} (map vec (partition 2 (interleave keys vals) > > :) One reason might be that the original zipmap is 5-10 times faster for large numbers of entries as it doesn't create all the temporary seqs. --~--~-~--~~~---~--~~ 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: Implementation of zipmap
Chouser wrote: > On Fri, Oct 30, 2009 at 11:30 AM, Alex Osborne wrote: >> John Harrop wrote: >>> Was something wrong with this?: >>> >>> (defn my-zipmap >>> "Returns a map with the keys mapped to the corresponding vals." >>> [keys vals] >>> (into {} (map vec (partition 2 (interleave keys vals) >>> >>> :) >> One reason might be that the original zipmap is 5-10 times faster for >> large numbers of entries as it doesn't create all the temporary seqs. > > Another might be that into, partition and interleave don't exist > yet when zipmap is defined. Yep, although nothing else in core uses zipmap, so it could be moved after them. --~--~-~--~~~---~--~~ 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: idiom questions
Chick Corea wrote: > Is everything in Clojure immutable? Most things. Clojure tries very hard to be thread-safe by default. > how does one modify the value of 'x' ? > > (let [x nil] (def x true)) One does not, at least not in a let-binding. If you really want a lexical variable you can get one with a var: (with-local-vars [x 3] (println (var-get x)) (var-set x 5) (println (var-get x))) It is thread-local to enforce thread-safety. But as the others have said you should really be doing things functionally not imperatively. I've actually never used with-local-vars in a real program. > So I want to ask, am I in the minority in thinking that read-only > local bindings limit > the programmer a lot. You probably just have "gotten" functional programming yet. If you use functions like map, reduce and for and recursion instead of traditional looping you basically find yourself not needing mutable local bindings. > Do both of these statements intern a symbol? Or does the 2nd set the > currently > interned symbol to a new value ? > > (def x 1) > (def x 2) This changes the root binding of the var named by x to a new value, it does not create a new var. The reason Clojure allows this is to make interactive development and debugging easier (so you can redefine a function at run-time). user> (def x 1) user> (def a #'x) user> (def x 2) user> (identical? a #'x) true user> a #'user/x user> (type a) clojure.lang.Var > Is the proper way to change the value bound to a symbol to use > "set!" ? > > (set! x 3) > If I understand correctly, the "(binding ...)" macro specifically > applies to > "Variables", one of Clojure's STM types, thus has dynamic, thead-local > scope. Is that right? In which case, it may hide a lexical binding ? Yes, I think you are basically correct. Maybe this example will help: (def foo 5) ; thread-global nearly immutable root binding (binding [foo 7] ; creates a thread-local binding for x (set! foo 9) ; changes the thread-local binding (let [t (Thread. (fn [] (println "foo in other thread:" x) (set! foo 25)))] (.start t) (.join t)) (println "foo in main thread:" foo) (def foo 72) ; changing the root-bind (don't do this!) (println "foo in main thread after 2nd def:" foo)) (println "foo outside binding:" foo) Output: x in other thread: 5 Exception in thread "Thread-133" java.lang.RuntimeException: java.lang.IllegalStateException: Can't change/establish root binding of: foo with set x in main thread: 9 x in main thread after 2nd def: 9 foo outside binding: 72 --~--~-~--~~~---~--~~ 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: idiom questions
Alex Osborne wrote: > Chick Corea wrote: >> If I understand correctly, the "(binding ...)" macro specifically >> applies to >> "Variables", one of Clojure's STM types, thus has dynamic, thead-local >> scope. Is that right? In which case, it may hide a lexical binding ? > > Yes, I think you are basically correct. Maybe this example will help: No it won't because I totally messed it up (copy-paste errors). Sorry, I'm not completely awake yet. What I meant was: (def x 5) ; thread-global nearly immutable root binding (binding [x 7] ; creates a thread-local binding for x (set! x 9) ; changes the thread-local binding (let [t (Thread. (fn [] (println "x in other thread:" x) (set! x 25)))] (.start t) (.join t)) (println "x in main thread:" x) (def x 72) ; change root-bindings (don't do this!) (println "x in main thread after 2nd def:" x)) (println "x outside binding:" x) Output: x in other thread: 5 Exception in thread "Thread-188" java.lang.RuntimeException: java.lang.IllegalStateException: Can't change/establish root binding of: x with set x in main thread: 9 x in main thread after 2nd def: 9 x in outside binding: 72 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: can I make this faster (and leaner) ?
Chick Corea wrote: > The corresponding Java code (w/ the hash-insert omitted in the clojure > version) > runs in 5.5sec and uses 290MB. > > This code runs (which omits the hash-insert) runs in 17.8sec and uses > 353MB. > > I thought that I added all of the casts and "warn-on-reflections" that > would help. > Also, I thought using Java data structures directly would bypass some > of Clojure's > overhead. What am I missing? Not sure about the speed difference, but how are measuring memory usage? Your memory figures might include a bunch of garbage that hasn't be GCed yetm, Clojure code tends to make lots more garbage than Java code due to the immutability. You could try forcing a GC with (System/gc) and see if it changes your readings. If it's generating exactly the same structure as the java code, Clojure should be using the same amount of memory (aside from the initial overhead). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Infinite sequences hang sets and maps
Luke VanderHart wrote: > On Oct 29, 4:01 am, Mark Engelberg wrote: >> I see your point that hashCode could be made to work on infinite >> sequences, but since hashing is almost always a prelude to testing for >> equality, I'm hard pressed to think of an example of why you'd want to >> be able to do this. Can you illustrate with an example? > Wouldn't hashCode be called every time you use an infinite sequence as > a key in a hash map? Yes, but this is another case where hashing is a prelude for testing equality. If there's a hash collision then the map will have to use equality testing to distinguish between two keys. If you make hashCode always work on infinite sequences, then sometimes using them as keys in maps will work and other times -- seemingly randomly -- it won't. In my opinion this is much worse than them never working as map keys. > That strikes me as a problem, since everything else in Clojure makes > perfectly good map keys. "Everything else" in Clojure is also printable and equality testable in finite time. There's just some things you can't do reliably with infinite sequences. --~--~-~--~~~---~--~~ 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: update-proxy doc - what is "this" ?
msappler wrote: > user=> (doc update-proxy) > > It says:"the first arg corresponding to this" > > What is meant with "this"? "this" means the proxy object itself (like the "this" keyword in Java). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: clojure parser
nchubrich wrote: > Is there any way to access the clojure parser, i.e. something that > gives you all the elements contained in an expression? I.E. (parse (+ > 1 2)) would give you something like [:list [[:symbol +] [:literal 1] > [:literal 2]]]. Do you mean the reader? user=> (read-string "(+ 1 2)") (+ 1 2) user=> (first (read-string "(+ 1 2)")) + user=> (type (first (read-string "(+ 1 2)"))) clojure.lang.Symbol user=> (type (second (read-string "(+ 1 2)"))) java.lang.Integer Or perhaps quote is what you're looking for? user=> (second '(+ 1 2)) 1 There's no need for a syntax like [:list [[:symbol +]]] etc as (+ 1 2) literally is just a list of a symbpl and two Integers, you just need to use quote to tell Clojure not to evaluate 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: A couple questions about the language
Andrew wrote: > 1. Can I have compile time evaluation forms like in Lisp? For example, > I want to obtain current namespace during macro expansion, or make > Java imports in compile time. Is it possible? Unless I'm misunderstanding what you want, sure. Just access *ns* or (import 'whatever) in your macro. Also anything that is at the top-level (not in a function) will be called at compile-time (eg put in println at the top-level and compile it and the compiler will print something out). > 2. Can I precompile Clojure code (not generated classes) and load > precompiled version instead of text script? Sure. If your source file is called foo.clj (and is the in the classpath) just do (compile 'foo) and Clojure will spit out a compiled version. Put the compiled version in the classpath and then you can (use 'foo) just as if it were source code. --~--~-~--~~~---~--~~ 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: Generalizing -> & ->>
Sean Devlin wrote: > This is slightly unrealted, but how does one pronounce ->, ->> and the > like? Is this documented? The doc-strings usually give you a nice hint. I usually use "thread" for -> and "thread last" for ->>. The actual symbols I think of as "arrow" and "double arrow". Then -?> in contrib is "short-circuiting thread". Not sure about the symbol, perhaps "questionable arrow"? ;-) --~--~-~--~~~---~--~~ 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: Running out of memory when using loop/recur and destructuring
Paul Mooser wrote: > Good job tracking down that diff -- upon looking at it, unfortunately, > I obviously don't understand the underlying issue being fixed (the > inter-binding dependencies) because the "old code" basically matches > what I would think would be the way to avoid introducing this in an > outer let form Lets macro-expand Christophe's example with both the old loop and the new loop. (loop [[x & xs] s y xs] ...) So with the old loop we get this: (loop* [G__13702 s G__13703 xs] (let [[x & xs] G__13702 y G__13703] ...)) See the problem? "xs" is used before it's defined. The new loop uses the outer-let to get around this: (let [G__13697 s [x & xs] G__13697 y xs] (loop* [G__13697 G__13697 y y] (let [[x & xs] G__13697 y y] ...))) What initially occurs to me is to move the outer loop into loop*'s vector: (loop* [G__13702 s G__13703 (let [[x & xs] G__13702] xs)] (let [[x & xs] G__13702 y G__13703] x)) A problem with that is we're going to have to put in a destructuring let of all the previous arguments for each loop* argument, so it'll blow up in size pretty quickly and I guess the JVM won't optimize the unused bindings away as it can't be sure the (first s) and (rest s) that [[x & xs] s] expands into are side-effect free. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Adding meta data to a function (from a macro)
Stefan Arentz wrote: > > I'm trying to do this: > > (defmacro my-defn [name & body] >`(defn- #^{ :foo-tag "blah" } ~name [] > ~...@body)) > > The idea is that foo will be defined and that {:foo-tag "blah"} is > added to its meta-data. > > But that does not seem to work: Try this: (defmacro my-defn [name & body] `(defn- ~(with-meta name {:foo-tag "blah"}) [] ~...@body)) --~--~-~--~~~---~--~~ 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: Functions and vars and meta-data
t if use macroexpand to explicitly pass it the vector? (let [fns [greet groan]] (macroexpand (list 'get-xxx fns))) => java.lang.ClassCastException: user$greet__5100 cannot be cast to clojure.lang.Symbol Another problem. The let creates a vector function objects not of symbols. So to get this to work we need to quote greet and groan to prevent them from being evaluated: (let [fns ['greet 'groan]] (macroexpand (list 'get-xxx fns))) => [1 2] Or we can just quote the whole vector: (let [fns '[greet groan]] (macroexpand (list 'get-xxx fns))) => [1 2] But at this point get-xxx may just as well have been a function: (defn get-xxx-fn [syms] (vec (map #(get (meta (resolve %)) :xxx) syms))) (let [fns '[greet groan]] (get-xxx-fn fns)) => [1 2] Now, that is one of the reasons why the first rule of Macro Club is: Don't Write Macros. ;-) Cheers, Alex --~--~-~--~~~---~--~~ 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: equivalent to Haskell's group function
Wilson MacGyver wrote: > Does Clojure have a function like Haskell's group? > > In Haskell, > Input: group [1,2,2,1,1,1,2,2,2,1] > Output: [[1],[2,2],[1,1,1],[2,2,2],[1]] (use 'clojure.contrib.seq-utils) (partition-by identity [1 2 2 1 1 1 2 2 2 1]) => ((1) (2 2) (1 1 1) (2 2 2) (1)) --~--~-~--~~~---~--~~ 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: Consistency of the API
Mark Engelberg wrote: > 2009/11/9 Tiago Antão : >> What is the rationale for even? and contains? having different >> behaviors for the exact same error (ie, one throws the other works >> fine and just returns false on a type error)? > I imagine the rationale is efficiency. Here's the function from clojure/lang/RT.java: static public Object contains(Object coll, Object key){ if(coll == null) return F; else if(coll instanceof Associative) return ((Associative) coll).containsKey(key) ? T : F; else if(coll instanceof IPersistentSet) return ((IPersistentSet) coll).contains(key) ? T : F; else if(coll instanceof Map) { Map m = (Map) coll; return m.containsKey(key) ? T : F; } else if(key instanceof Number && (coll instanceof String || coll.getClass().isArray())) { int n = ((Number) key).intValue(); return n >= 0 && n < count(coll); } return F; } That last return could be changed to a throw and it wouldn't make things any slower (in the non-error case). Note that 'get' always behaves the same way, so I guess it's probably intentional for associative lookups, I can't see why though. (get 3 3) => nil --~--~-~--~~~---~--~~ 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 convert java Complex type to Clojure type?
Michael Jaaka wrote: > How to convert HashMap to Clojure map, sorted-map, > tree-map > > How far I'm able only to do it with > > (let [a (HashMap. { "abc" "def"}) ] >(zipmap (keys a) (vals a))) > > Note that HashMap. { ... } is here only as example, cause in fact it > is a result from Java method call. > > What with sorted-map, tree-map and any other types (set, arrays, > double dimension arrays)? > Is there any brief tutorial showing how to convert any Complex Java > type to Clojure type > I want do that because I want my data structures immutable. (into {} (HashMap. {:b 2, :a 1})) => {:b 2, :a 1} (into (sorted-map) (HashMap. {:b 2, :a 1})) => {:a 1, :b 2} (into [] (to-array [1 2 3])) => [1 2 3] (into [] (ArrayList [1 2 3])) => [1 2 3] and so on... --~--~-~--~~~---~--~~ 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: Understanding Clojure Closures
mbrodersen wrote: > In this simple recursive expression: > > (def t (fn [x] (if (zero? x) 0 (+ x (t (dec x)) > > The fn special form is evaluated within a context where t is not yet > bound. > > t is only bound AFTER fn has captured its environment. > > In other words, the closure captured by fn doesn't know anything about > t (or maybe only that t is unbound). > > And yet it still works if I call t: > > (t 5) => 15 > > My question is how Clojure ensures that t is bound to the closure > after the closure has already been captured? t is a var. The var is created before the body of def is evaluated. At that point it is unbound. The function closes over the var not the value of the binding. That's why you can re-evaluate a function, changing it's behaviour, without having to re-evaluate everything that calls it. You'll notice that with locals (which aren't vars, they're immutable) it doesn't work: (let [t (fn [x] (if (zero? x) 0 (+ x (t (dec x)] (t 2)) Also if you try to use the var in the bindings you'll get an unbound error, not an unable to resolve symbol error: (def foo foo) -- 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 print without spaces?
John Ky wrote: > How to I print without spaces? (println (str "a" "b" "c")) -- 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 write a macro
John Ky wrote: > Hi all, > > I'm looking for a way to write a defkw macro so that (defkw ABSENT) > expands to > (def ABSENT (kw "ABSENT" :ABSENT )). > Just use `(...) as a template and use ~ to unescape, like so: (defmacro defkw [sym] `(def ~sym (kw ~(str sym) ~(keyword sym (defkw ANSEMT) => (def ABSENT (kw "ABSENT" :ABSENT)) -- 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 write a macro
John Ky wrote: > I had to ~(keyword (str sym)) instead of ~(keyword sym), but now it > works well. Hmm, odd. Must have changed since Clojure 1.0. (keyword 'some-symbol) works for me on the "new" branch. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure event handling
nchubrich wrote: > I'm curious what the best idiomatic way of handling events is (e.g. > receiving a series of messages and dispatching functions on the basis > of the messages). One could use the 'experimental' add-watch(er) > functions. But it might also be nice to do something stream-oriented, > e.g. a doseq on a stream of events. But the trouble is this dies as > soon as the events stop arriving. Can event seqs be 'kept alive' > somehow (preferably without blocking)? I may be misunderstanding what you mean by events but what about just using an agent and a multi-method? (defmulti handle-event (fn [state event] (:type event))) (defmethod handle-event :party [state event] (assoc state :status :dancing)) (defmethod handle-event :explosion [state event] (assoc state :status :cowering)) (def my-agent (agent {})) (send my-agent handle-event {:type :party, :location :your-house}) @my-agent => {:status :dancing} -- 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: Datatypes and Protocols - early experience program
Mark Engelberg wrote: > Protocols: > > I don't understand whether there's any way to provide a partial > implementation or default implementation of a given > protocol/interface, and I believe this to be an important issue. > > For example, a protocol for < and > that provides a default > implementation of > in terms of < and a default implementation of < in > terms of >, so that you only need to implement one and you get the > other for free. > How about this? (defprotocol MyComparable (comparinate [x y] "Returns a negative integer if x < y, zero if they are equal and a positive integer if x > y.") (equal-to [x y] "True if x is equal to y.") (less-than [x y]"True if x is smaller than y.") (greater-than [x y] "True if x is greater than y.")) (defn mixin-comparable [type compare-fn] (extend type MyComparable {:comparinate compare-fn :equal-to (fn [x y] (zero? (comparinate x y))) :less-than(fn [x y] (neg? (comparinate x y))) :greater-than (fn [x y] (neg? (comparinate x y)))})) (mixin-comparable Integer -) (mixin-comparable String #(- (count %1) (count %2))) (less-than 8 2); => false (less-than "x" "") ; => true > I'm also thinking about the relationship in Clojure's source between > ISeq and ASeq. ASeq provides the partial, default implementation of > more in terms of next, for example. How does this kind of thing look > with the new protocol system? See above. But another way would just be to define ASeq as a map and then merge with it: (def aseq-impl {:more (fn [obj] (if-let [s (next obj)] s '() )) :count (fn [obj] ...)}) (extend MyList ISeq (merge aseq-impl {:next (fn [lst] ...) :count (fn [lst] ...) ; overrides the count from aseq-impl :cons (fn [lst x] ...)})) Code is data. :-) I don't know whether doing things this way is a good idea or not, but protocols are new: lets experiment and find out what works and what doesn't. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: local constants in functions or static locals/Hilbert curve in clojure (no images:)
ajuc wrote: > I would like to somehow hide the global hilbert-map into my function, > but I can't see how to do that. > > Is this possible? I know that I can just inert literal into my let, > but that degrades performance, when function is called many times. > > I would like to have something like static local variable in C++, or > just regular constant local variable in my function. Clojure's name gives a hint as to how do this: use a closure. :-) Just pull the let outside the defn: (let [hilbert-map {...}] (defn point-to-hilbert [...] ...)) -- 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