Re: "Soft" failures with spec?
There is a good talk by Chris Houser, "Condition Systems in an Exceptional Language" [1] where he systematically goes through many of the aspects on handling exceptions in batch processing (like the problem Josh describes). An interesting way to build a conditional error handler is outlined towards the end of that talk, the essential idea is to define dynamic functions which receives the exceptions and decides how to continue. If we look into the example outlined in Josh's question, there is some object with a :created-field. The :created-field can be suspicious in that equals beginning of unix epoch. One thing to note with detectable errors, like the zero-timestamp, that the check for this is probably best represented as a predicate function like non-zero-timestamp?, and that the call to such a function is a actually some kind of pre-emptive branching. This branching could be represented as two different types, maybe like [:valid-date #inst "2017-01-02T10:01:22.231Z"] or [:invalid-date "1970-01-01T00:00:00.000Z"]. This makes it nescessary for all logic afterwards to be able to handle both of these types, but de-couples all other logic from deciding what is a valid date or not. In an application specialized in converting dirty data this is probably a worthy trade-off. I think the most important thing when handling this type of situation is that the inconsistency has to be embraced and that the data representation of the system has to be able to contain both wanted and unwanted values. In this case, it would mean that the "outer", most general spec for such a timestamp must be able to contain both valid dates and things which are sorted out as not valid. These non-valid dates may still have to live up to certain properties (being a "correct error object"). This distinguishes handle-able errors from programming errors which is usually what we want to detect during tests for. It is very hard to construct specs which are certainly disjunct, if they are not different types or similar. When it comes to various maps it is certainly possible to construct specs for various types of maps, but it's very complicated to make dispatches based on values of keys in the map (which probably is the most common way to distinguish various types of objects in clojure). A very useful feature of clojure.spec is conform. With conform, one "upsert" any value to something which is according to our specs. Example: parsed-date-spec is a spec accepting {:unparsable-date ...} as well as some representation of correct timestamps, and suspicous timestamps. (defn parse-date "conform, which accepts a broad range of arguments" [o] (cond? (s/valid? parsed-date-spec o) o (inst? o) o ;; java.util.Date is ok (string? o) (try (parse-date o) (catch Throwable t {:unparsable-date o :exception t}) :else :clojure.spec/invalid) ;;something is wrong with the program if it's not an internal date representation, a string, or inst. When we know that the thing we have is something which we have control over, it is much easier to construct a predicate which checks validly parseable-dates for being 0 timestamps (or to far in the future, or anything). I suggest you 1. create a representation that makes it possible for you and your application to handle correct and in-correct values in a unified manner and that "normal errors" are embraced by the application logic. 2. strive to use predicate- or other simple functions (rather than complicated clojure.spec setups) to identify invalid entities in the input-data. 3. handle such errors inside the scope of the function / part of the program that handles the correct path of the program. 4. uses :clojure.spec/invalid and informative exceptions when there are unforeseen programming errors which the program cannot possibly recover from. The idea of using clojure spec to classify error messages in data-validation "all the way" is interesting. One problem is that the logic that want to make use of the diagnosis-data needs to know quite much about the general structure of the data (and the specs). /Linus [1] Chris Houser, "Condition Systems in an Exceptional Language" https://www.youtube.com/watch?v=zp0OEDcAro0 On Saturday, February 18, 2017 at 12:42:25 AM UTC+1, Josh Tilles wrote: > > Has anyone explored using spec for “soft” failures? For example, if I’m > writing an ETL system to migrate legacy customer account data, all I might > *require* of a record’s :created field is that the value is a > syntactically valid date-time string. If any record claimed that it was > created on "1970-01-01T00:00:00.000Z", of course that would almost > certainly be bad data; but instead of crashing the program or refusing to > process the record, let’s say I want to log (at the WARN level) some of > that record’s data, or perhaps even store the output of s/explain-data with > the record in the target database. To describe
Re: Clojure.spec, maps, restrict valid keywords, easier way?
It would be great if an editor highlighted a (possibly qualified) keyword that was used only in that particular place (given all code loaded). This wouldn't be bullet-proof, but would have highlighted mistakes like :encypted (but could still confuse :encrypted? with :encrypted, and whatnot). /Linus On Friday, February 3, 2017 at 1:49:20 AM UTC+1, tbc++ wrote: > > A good editor should auto-complete your keywords for you. Since using this > feature in Cursive (same sort of thing is available in other editors) the > cases where I've mis-spelled a keyword have dropped dramatically. It's a > lot harder to mis-spell a keyword when you can just do: :egg/th and > the rest is auto-filled. > > On Thu, Feb 2, 2017 at 5:37 PM, Alex Miller> wrote: > >> Ugh, don't do that. Introducing layers that add no value is a bad idea. >> Just use the keyword directly. >> >> -- >> 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. >> > > > > -- > “One of the main causes of the fall of the Roman Empire was that–lacking > zero–they had no way to indicate successful termination of their C > programs.” > (Robert Firth) > -- 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: Streamlining dev environment startup
You can hardcode the nrepl-server port with :repl-options {:port 4001} as seen at [1]. When thinking about it, maybe you could script tmux or similar to show all running terminals at once, like shown in [2]. [1] https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L354 [2] http://stackoverflow.com/questions/5447278/bash-scripts-with-tmux-to-launch-a-4-paned-window I will try out the tmux thing myself :) /Linus On Tuesday, December 1, 2015 at 5:32:06 PM UTC+1, Webdev Tory Anderson wrote: > > I recently read something hinting at ways of streamlining the startup > process for the dev environment, so I'm hoping you good folks can give me > some tips. I'm developing a web app in Linux, Clojurescript/Clojure > (incidentally using the Luminus architecture). I use emacs (that part's > non-negotiable; sorry). The cumbersome startup process I usually have goes > like this: > > M-x shell >> mongod # start the mongo daemon >> >> M-x shell >> lein run # start the app and server >> >> M-x shell >> lein figwheel #start CLJS development >> >> (open a .clj file) >> C-c M-c # (cider-connect) >> # insert localhost, port num, which proj. to connect to >> >> > This is usually bearable since I only have to do it once or twice a week, > but it's definitely the sort of redundancy that would be nice to eliminate. > The "lein run" is good to have foregrounded because I can see timbre > statements and cleanly reboot when necessary. Figwheel, at the moment, has > to be foregrounded because that's where the figwheel prompt ends up (I'd > love to have that in Cider somehow, though). > > Any recommendations on how to chop some of these steps off? > > > -- 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: How to move an element within a vector?
It is correct that vectors aren't a suitable choice for datastructures that need random-access-removal. The problem is that you seem to need both fast index lookup and be able to access elements after removed elements quickly even when there are holes in the backing array. There are some solutions. One is to use clojure.core/subvec, to keep the parts of the vector that should be kept, and concat these two sub vecs. I'm not sure if the removed element will be garbage collected - subvec reuses the structure of original vector, no copying seems to be done, so no removed element will be garbage collected until all subvecs of the original vector are realized as some other collection! If you are unsure about why (or, equally likely, prove me wrong), please refer to http://hypirion.com/musings/understanding-persistent-vector-pt-1 There are also the finger-trees, which are not as wide as PersistentVector and are more suitable for splitting etc. Probably one could construct a datastructure more suitable for random access removal with that. https://github.com/clojure/data.finger-tree If the hotspot of your application is to quickly lookup things in vectors and quickly remove individual elements it feels like it exists some clever datastructure that, given an virtual index in the (partially shadowed) vector, increments the lookup index for each removed element before the virtual position, to compensate for the holes in the vector, but that was probably not really your question. However, the problem is to find datastructures which both allow quick lookup and can keep track of the lookup when parts of the datastructure are marked as removed. What ever you do, make sure to profile it so that you don't hunt for performance in vain. /Linus On Wednesday, August 26, 2015 at 12:12:28 AM UTC+2, Georgi Danov wrote: How about filtering? BTW I don't see how it would help converting to array - what would be the solution then? On Tuesday, August 25, 2015 at 7:06:30 PM UTC+2, Hussein B. wrote: Hi, For a vector like [A B C D E], how to remove an element to a specific location? For example [A D B C E] ? I thought about converting the vector into array but I would feel bad if I did that. What would be the idiomatic way to do that in Clojure? Thanks for help and time. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- 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: #{:rant} Questions about contribution policy and clojure compiler source.
It is sad that Zach and Kyle thinks they spent time in vain. Clojure is less about code and more about holistic considerations and intentions than most other software projects. Jira (and mail chains such as this) are probably the worst possible hammers on communicating intentions and more holistic considerations in a focused way which IMHO seem to be what erred here. In cases like these I would strongly suggest Zach, Kyle and the Clojure Core-team to strive to communicate by phone or video-calls, and spend less time misinterpreting each other in asynchronous ticket comments. When in doubt, try to call each other ASAP and sort things out. I do optimistically assume that the Clojure Core team would gladly strive to set away some amount of time to discuss considerations for - not every incoming issue - but such exceptional, clear and well explained issues as these, where there's an overwhelming risk that a lot of work would end up being in vain. Thanks all for your exceptional work, Linus On Sunday, July 19, 2015 at 1:09:17 AM UTC+2, Magnar Sveen wrote: Linux and Linus? Github vs Jira? Enough of these distractions. The issue here is that brilliant people like Zach Tellman is strongly disinclined to make contributions to the core Clojure implementation in the future. That Kyle Kingsbury, another brilliant developer, feels stonewalled - and even tho he loves Clojure the language and the community - is considering moving on. Because of the way the contribution process works. Or does not work, in these cases. I think Zach summed it up nicely in his gist. I don't think the sky is falling in any way. But don't try to boil this down to a patches vs pull request bike shedding. It is certainly a much more important topic than that. On Saturday, July 18, 2015 at 11:14:58 PM UTC+2, Luc wrote: You mentionned RedHat Linux centric type corporations. There are a lot more businesses that are not Linux centric business wise. They use it but provide something else on top. Did you even read this article against your own statement ? :) A huge number of occasional contributors were not reluctant to log a ticket and submit a patch instead of ranting about it. This is the main point you missed. That 'entry barrier' of yours does not stand with Linux. I would think hard about the reasons behind these numbers. There has to be some value added in the process of submitting patches. Luc P. On Sat, 18 Jul 2015 23:02:30 +0300 Bozhidar Batsov bozh...@batsov.com wrote: On 18 July 2015 at 22:52, Luc Préfontaine lprefo...@softaddicts.ca wrote: Each linux kernel release involves hundreds of people. Many release had above a thousand contributors. This is for your enlightenment and are old figures: http://royal.pingdom.com/2012/04/16/linux-kernel-development-numbers/ Did you even read this article? 75% – The share of all kernel development that is done by developers who are being paid for their work. This doesn't exactly contract what I said. There are as many people not officially hired to work for linux operating system focused businesses that submit patches through the ticketing system. As for the development lifecycle of the linux kernel: http://www.linuxfoundation.org/content/22-lifecycle-patch You can read the other sections, if you find the Clojure dev. lifecycle arcane, you will freak at this one. Obviously, these guys must all be old fashion outdated folks in this era of instant communication and snapchat like media, there's no other explanation for such a bureaucratic process :) How much pain is it to upgrade to a new Clojure version ? Nil. How much pain is it to upgrade to a new linux kernel ? Not nil but considering the size of this project, its ramifications and the hardware changing every 6 months, not big. On par with Clojure I would say. How much pain to upgrade to a new version of Ruby on Rails ? Huge. I know, I have been through this a number of times. Not just major releases, even maintenance ones are a nightmare to upgrade. Disclaimer: I am not saying that Rails has a bad lifecycle, I am just stating feedback from me and other people that actually lived this. Gee, I sound like Mallard Fillmore... That's for the political correctness of this post. And to avoid being harassed, sued, whatever. I would like us to compare carrots with carrots, not with apples or strawberries but if you insist To me the result is utterly important. We deliver 24/7 software under linux using Clojure. We have up times of more than 300 days. One upgrade a year. This is the world that live into. Making it 'harder to contribute' like you state is the price to pay for some form of quality control. Contributing to something that eventually
Re: #{:rant} Questions about contribution policy and clojure compiler source.
Dear Mr/Ms/Mme/PhD Dynamics, I have this epic joke I would like yo send you, please fill in your fax number in the boxes below (please write clearly and use a pen with black ink, make sure the two carbon papers are correctly aligned). [_|_|_|_|_|_|_|_|_|_] Thanks, Linus Sent from my Ericsson Hotline Combi 450 Mobile Telephone Den 19 jul 2015 02:56 skrev Fluid Dynamics a2093...@trbvm.com: On Saturday, July 18, 2015 at 8:22:35 PM UTC-4, Linus Ericsson wrote: In cases like these I would strongly suggest Zach, Kyle and the Clojure Core-team to strive to communicate by phone My God. First contributor agreements that have to be submitted by Pony Express, and now *phone calls*? What is this, the Dark Ages? We're dealing with medievalism here, Jim! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- 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/IXKll8tgAXA/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/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.core.match: AssertionError: Pattern row reuses wildcards
Use the :tx-data as a $-database! The only pitfall is that the second position, the attribute, and all other references (reference type) is just a reference to the attribute entity (a long). Let's say you find :db/txInstant to be 53, and :community/category to be 112 the query would look like (q '[:find ?tx-eid . in $ :where [?tx-eid 53 _ ?tx-eid true] [_ 112 free stuff ?tx-eid false]] tx-data-as-database) If this query returns the ?tx-eid, and not nil, the contraints was fulfilled - test passed. Given that this is unit testing and performance is probably not a big issue, maybe it would be possible to write a function generating a datomic query like the one above, but with conveniences like it automatically inlines the attribute-entids (or extends the query to automatically looking them up using some reference to the db with the current schema installed). Given that Datomic compiles every new query that is not parameterized this could be quite heavy if it was used in production. But in short, you can query the tx-data using datalog, the only pitfall is that datoms are mostly primitives which must be looked up in the datomic db they came from. I think datoms have a reference to the database they came from, but I don't know how to use that fact. It's full of stars. /Linus On Wednesday, July 1, 2015 at 9:47:07 PM UTC+2, Alan Thompson wrote: Hi - I am trying to write some unit tests for Datomic using core.match to keep things succinct. I was hoping to use a match pattern like this: [ {:e tx-eid :a :db/txInstant:v _ :tx tx-eid :added true} {:e _ :a :community/category :v free stuff :tx tx-eid :added false} ] to show that the transaction EID (tx-eid) shows up in 3 places in the datoms result of a transaction. However, I am getting the error: Exception in thread main java.lang.AssertionError: Pattern row 1: Pattern row reuses wildcards in [[{:e tx-eid, :a :db/txInstant, :v _, :tx tx-eid, :added true} {:e _, :a :community/category, :v free stuff, :tx tx-eid, :added false}]]. The following wildcards are ambiguous: tx-eid. There's no guarantee that the matched values will be same. Rename the occurrences uniquely., So I am apparently unable to use core.match in the way I was hoping. Are there any workarounds to this problem? Thanks, Alan -- 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: Testing and infrastructure management for large Clojure app - how are you doing it?
I really cant see how the testers could NOT be able to use a repl to do some exploratory testing. Clojure's strength is really that you can align the code very closely to the domain, although this modelling is (as always) challenging. And the application logic does not have to be tested through and http-based interface, sometimes it's a good start to test it through the Repl. If this is hard to use, then everything will be hard with the application. /Linus Den 29 okt 2014 10:07 skrev Colin Yates colin.ya...@gmail.com: I also meant to say that it is worth doing a cost-benefit analysis on testing. When I did my consultant thing I frequently saw massive investment in tools, process, emotion(!) etc. in things that on paper were a good thing but in reality weren't mitigating any real risk. All testing isn't equal - what risks do you currently face right now (e.g. are you playing whack-a-moley due to developer's poor impact analysis, or for example, are the developers consistently producing great code which doesn't piece together well and so on)? Put your energies into resolving those risks. Most testing processes and resources I see are by definition re-active - they find effects (bugs) of the cause (which is typically developer insufficiency in terms of requirements). In my view resources should all be about mitigating the cause. Why not get your testers (although I really don't like segmenting resources by calling them testers) to sit with a developer just before they do a new piece of work and think through the impact analysis? Have your testers take the use cases and start building the test scenarios immediately. Have your testers review the developers unit tests - if it doesn't make sense to a (technically orientated) tester than the developer is probably doing it wrong and so on. Simply spotting effects is helpful but all resources should be focused on mitigating the cause of those effects and more often than not I see a whole bunch of testing activity which isn't really solving any real problems but is certainly slowing down the flow. Please let me clear - I am not challenging the _requirements_ of the traditional testing process (e.g. ensuring quality), I am claiming the way most people do it is incredibly expensive and inefficient. I can hear the internet taking a breath saying No!, he didn't just go there :). On Wednesday, 29 October 2014 00:12:52 UTC, David Mitchell wrote: Hi Colin Thanks for your reply. My post is almost exclusively technology oriented because I think the technology is what's killing us! We've got what you'd probably call BDD lite working, in that we've got a mutant form of agile process running whereby we work in 2 week sprints, but there's rarely an installable product that emerges at the end of the 2 weeks. I won't go into detail as to what I feel are the root causes in a public forum - however I'm convinced that our adoption of Clojure is at least partly to blame. Just to make it clear, I absolutely believe Clojure is a good tool to use for this project, and personally I'll be actively seeking out other Clojure projects in the future. I'm saying that from the viewpoint of someone who's employed in the testing area, but who also has quite a bit of Clojure development experience. There's just this gulf at present between the people who know Clojure (almost exclusively developers) and other technical staff involved in the application lifecycle (testers, infrastructure owners, all the various technical managers) that we're finding very difficult to manage. For example, it'd be great if we could pair up our testers and developers, have them working side by side and rapidly iterating through e.g. Cucumber feature definition, coding and testing. That would be absolutely ideal for this particular project, where a complete set of test cases can't be 100% defined up front and lots of minor questions arise even within an iteration. If this working arrangement was viable, every time we hit a point that needed clarification, the tester could engage the product owner, get clarification and jump back in to their normal work with minimal disruption. However, our testers simply can't provide enough useful input into development - they're currently stuck waiting for developers to hand their code over *in a form that the testers can test it*, and often there's a lot of extra (wasted?) effort involved to take working Clojure code and make it testable using non-Clojure tools. To say this is an inefficient working model would be a massive understatement. What we're seeing is that our developers work like mad for the first week of a 2 week iteration, while the testers are largely idle; then code gets handed over and the developers are largely idle while the testers work like mad trying to finish their work before the end of the iteration. Our automation testers are valiantly trying to use SoapUI and Groovy
Re: Modelling in Clojure
Jason, the summary is good, but I'm missing the more efficient data structure array-map that probably wastes less space than the hash-map for the same size of object. [1] Also Zach Tellman has made some effort with clj-tuple which however use indexes, not keys. [2] [1] http://clojuredocs.org/clojure.core/array-map [2] https://github.com/ztellman/clj-tuple /Linus 2014-10-22 6:25 GMT+02:00 Jason Wolfe ja...@w01fe.com: Hi Tom, Maybe this post from would be of use? https://github.com/Prismatic/eng-practices/blob/master/clojure/20130926-data-representation.md It's my best attempt (albeit a year or so old) to answer many of these questions. Happy to answer questions if you've got them. Cheers, Jason On Thursday, October 16, 2014 2:19:32 PM UTC-7, Tom Oram wrote: Hello Clojure people, First up, apologies because this is going to be a long message. Howver, if you do have the time to read and respond, then I would be extremely grateful! Recently I've decided to give Clojure a proper go. Over the past year or so I've paid it a bit of attention: I've read books all about how to use it and I've spent a bit of time working through tutorials to create little web apps and so on. I understand the language (although not to any great depth yet), but I'm still unsure about the best approaches to actually working with it. I've got many years of OOP experience, and I'm a big fan of principles like SOLID and approaches like DDD. What I want to do now is, try and learn how to build well designed models using Clojure, while using best practices! I've started having a bit of a crack at it by building a simple app, but I'm finding myself trying to transfer a lot of my existing OOP techniques into Clojure. It's working, but I'm wandering if I'm overdoing it or perhaps just not doing things the Clojure way. So, my very first question is are there any good books or resources on modelling, application architecture or best practices, using Clojure? Next up, maps vs records. I've read that the typical approach is to use maps until the design starts to solidify and then you can move to records. Is the the general attitude of Clojure developers or do some like to dive straight in with records? The next question is encapsulation: I've taken the approach that I'm kind of using namespaces like classes. If I want to create customer entity I create a namespace for it, then add a make function to it which returns a map of the right shape. I'm then shying away from accessing the map directly, and rather doing it through other methods in the namespace which take the instance as a parameter. E.g. (ns app.domain.customer) (defn make [name, email] {:name name :email email}) (defn get-name [customer] (:name customer)) Is this a reasonable approach? If not, what might be a better one? This leads on to safety and defensive programming. Using the approach above, how much type safety is required? Obviously, in any API which is going to be used by other programmers, you've got to handle bad inputs well. But what is the Clojure approach in the domain model? Coming from the DDD mindset, where models are designed to be un-breakable, part of me wants to use records for all entities and typehint for them everywhere. However, I wander if the Clojure way is more about rigorous testing to make sure the wrong values don't get put in in the first place? Also, what about libraries like https://github.com/Prismatic/schema, this could be used in :pre conditions to be more explicit, is that a common thing? Next up, how far do you go with creating types vs using primitives? Again, referring back to DDD, both the email and the name in the example above are suitable candidates for value objects. In Clojure, would you consider hiding the data behind a set of specialised functions to create, access and use it? Or would you just pass the primitive string/map/vector/whatever about and work on it directly? Example: ; Given (defn make-customer [name email] {:name name, :email email}) ; Examples (def customer1 (make-customer Tom em...@address.com)) ; vs... (defn make-name [name] name) (defn make-email [email] email) (def customer2 (make-customer (make-name Tom) (make-email em...@address.com))) I think that's all I want to ask about now. I do have other questions about dependency inversions, but I'll leave that for another time. If you've read this far then thank you very very much! Also,I know that no one really wants to just sit and read though random peoples code, but, if you are interested in my (very very early stages) experimental project, then I've put in on https://github.com/tomphp/clojure-cocktails - any comments, critiques, PRs or questions would be really great! Thanks you so much for your times and I look forward to any thoughts or suggestions! Tom -- You received this message because you are subscribed to the Google Groups Clojure
Re: agent validation fails in STM
You are right! If, say, a file write, fails the data would reside only in your memory refs. One way to make sure the two thing are always in sync is to be able to rollback the in-memory state (and replaying all subsequent actions) by holding on to the old version until the agent could be derefed as correctly updated to or maybe even beyond the expected version of the datastructure. I think. Im not sure how you would persist the queue of incoming actions by the same pattern, though. I guess you should have a look on Two-phase commits. /Linus Den 15 okt 2014 20:15 skrev shahrdad shadab clojure.langu...@gmail.com: Hi folks I know when I send/send-off an action to an agent within a STM transaction no action will be dispatched if transaction fails to commit. I was expecting similar behaviour when agent fails: the transaction does not commit when the action puts the agent in an invalid / failed state. It seems my expectation is wrong because the sent action will be dispatched only when transaction successfully committed which by the time it is too late to un-commit things. In such scenario the resource (database, file,...) will be out of sync with the modified collection in STM. Am I missing any thing here? Any comments is highly appreciated. Thanks a lot Best regards Shahrdad -- 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. -- 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: Adding up numbers, quickly
There are primitive vectors. Extraordinary clever. http://clojuredocs.org/clojure.core/vector-of /Linus Den 16 okt 2014 00:02 skrev Jony Hudson jonyepsi...@gmail.com: Thanks, that's really useful! Jony On Wednesday, 15 October 2014 20:53:40 UTC+1, Jony Hudson wrote: Hi all, another performance question ... this time about arithmetic on vectors :-) Let's say I have two vectors of numbers (specifically, things with type clojure.lang.PersistentVector, containing things of type java.lang.Double). And let's say I want to sum the differences [1] between corresponding elements of the lists i.e. (a1 - b1) + (a2 - b2) + ... Any suggestions on how to do this quickly. What I find is that if I use the 'obvious' high-level construction: (reduce + (mapv #(- %1 %2) a b)) then it goes pretty slowly. On my laptop I measure about 180us for 1000 element lists. If I try using `loop`: (loop [sum 0.0 i 0] (if ( i 1000) (recur (+ sum (- (nth a i) (nth b i))) (inc i)) sum)) it does better, at about 100us. But these are still a ways off what I might think is the best that could be done. If I run a similar computation in Java, it takes about 8us, which ties up with what my gut feeling would be. So ... does anyone have any advice on closing the gap here? Thanks in advance, again, Jony [1] Actually I want to sum the absolute differences, but that brings in java interop which I want to leave out lest it confuse matters. -- 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. -- 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: reading to learn and acquire the skill of writing optinal Clojure code
Andy, I would go for quantity over quality here. There's really a lot of libraries but only some applications (where I think LightTable is one of the most polished applications). Don't miss the quite good catalogue http://www.clojure-toolbox.com/ some things are a bit outdated, but it doesn't matter! Some nice libraries and applications to skim through would be https://github.com/flatland/useful everything in the Clojure's github repo https://github.com/clojure/ LightTable (although mostly using ClojureScript) https://github.com/LightTable/LightTable There are small examples of web applications here and there, but really most things are parts that is meant to be put together, which is not eas to begin with. Pedestal is a quite complete web-framework, but abandoned its frontend because of a more promising road ahead with Om (which is based on React.js but still quite alpha). https://github.com/pedestal/pedestal https://github.com/swannodette/om Riemann is partly a complete Clojure application, but with a web frontend in Ruby, I think. https://github.com/aphyr/riemann Overtone is a quite large music synthesizer project https://github.com/overtone/overtone be sure to checkout at-at as well: https://github.com/overtone/at-at Apart from that, read all source code you can, most that is put up is quite good, and usually very concise! /Linus 2014-09-26 3:41 GMT+02:00 Andy Gibraltar andy.gibral...@gmail.com: Hi everyone, I am learning Clojure. I finished reading the book Clojure Programming. I think reading the source code of a Clojure project would help me accelerate acquiring the skill. Which codebase do you think is the most appropriate for a starter. A code base that I can use as a reference, something concise yet has almost all the best practices. Small enough that I can internalize and use it as a reference for my own projects. Sorry for asking such an open ended question. Thanks, Andy -- 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. -- 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: Calling the main static method of a class
You can set system properties with System/setProperty. See more here: http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html /Linus Den 26 sep 2014 15:58 skrev paracomunicacionesinforma...@gmail.com: hi, I've got a traditional java class invoked from the command line: public class Aclass public static void main(String[] a) throws Exception { } java -Doneoption=onevalue Aclass and I want to invoke THAT main class from the command line and to simulate the options from the command line ( -Doneption...) , how can I achieve this in clojure ? greetings -- 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. -- 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: How do I track down a painfully long pause in a small web app?
If you turn on verbose gc for the JVM you could at least rule out GC pauses. Hmm, exactly how do you route the requests through the apache server? It almost sounds like your applikation is restarted every now and then, iirc Apache only servers a limited amount of requests per server thread. If this somehow started a new JVM per apache thread things would go strange. What does $ps ax --forest say? /Linus Den 15 sep 2014 06:44 skrev Shantanu Kumar kumar.shant...@gmail.com: Few thing to consider: 1. Which API calls pause? If only certain calls pause, then probably you have something specific to suspect. Try adding a dummy REST call - see if that call pauses while others do. 2. Is any of your services running on a t1.micro or a burst-oriented EC2 instance on AWS? Try changing the instance type in that case. 3. Can you mock out the components that you suspect could be a problem? Begin by mocking out everything you suspect, then replace the mock with actual impl one component at a time until you isolate the problematic component. 4. Have you tried running a profiler? 5. Have you tried printing GC info? Maybe this could be useful: http://blog.ragozin.info/2011/09/hotspot-jvm-garbage-collection-options.html Shantanu On Monday, 15 September 2014 09:45:14 UTC+5:30, larry google groups wrote: I have an embarrassing problem. I convinced my boss that I could use Clojure to build a RESTful API. I was successful in so far as that went, but now I face the issue that every once in a while, the program pauses, for a painfully long time -- sometimes 30 seconds, which causes some requests to the API to timeout. We are still in testing, so there is no real load on the app, just the frontenders, writing Javascript and making Ajax calls to the service. The service seems like a basic Clojure web app. I use Jetty as the webserver, and the libraries in use are: Ring Compojure Liberator Monger Timbre Lamina Dire When someone complains about the pauses, I will go test the service, and I can hit with 40 requests in 10 seconds and it has great performance. The pauses actually seem to come after periods of inactivity, which made me think that this had something to do with garbage collection, except that the pauses are so extreme -- like I said, sometimes as much as 30 seconds, causing requests to timeout. When the app does finally start to respond it again, it goes very fast, and responds to those pending request very fast. But I have to find a way to fix these pauses. Right now I packaged the app as an Uberjar and put it on the server, spun it up on port 24000 and proxied it through Apache. I put a script in /etc/init.d to start the app using start-stop-daemon. Possible things that could be going wrong: Maybe Jetty needs more threads, or maybe less threads? How would I test that? Maybe the link to MongoDB sometimes dies? (Mongo is on another server at Amazon) How would I test that? Maybe it is garbage collection? How would I test that? Maybe I have some code that somehow blocks the whole app? Seems unlikely but I'm trying to keep an open mind. Maybe the thread pool managed by Lamina sometimes gets overwhelmed? How would I test that? Maybe when Timbre writes to the log file it causes things to pause? (But I believe Timbre does this in its own thread?) How do I test that? This is a small app: only about 1,100 lines of code. I don't have much experience debugging problems on the JVM, so I welcome any suggestions. -- 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. -- 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] Clojure 1.7.0-alpha2
The volatile construct seems very useful in some particular cases! I have been missing ugly-mutable variables for things such as certain types of heaps/queues or write-intensive, slightly probabilistic stuff where one missed write doesn't matter that much. For people who don't have a Java background, I just want to point the very useful package java.util.concurrent.atomic, in which one can find gems such as AtomicLong, which is almost unbeatable as a counter. An example in which an AtomicLong is about three times quicker than an atom: https://gist.github.com/claj/6711556#file-countertest-clj Javadoc for AtomicLong: http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLong.html In the sake of completeness, Linus 2014-09-11 11:06 GMT+02:00 Frantisek Sodomka fsodo...@gmail.com: Using my timings macro: https://gist.github.com/fsodomka/5890711 I am getting that: - creation derefing is 60% faster - swapping is 25% faster - resetting is about the same ;; volatile vs. atom ;; (report (timings 1e7 (deref (volatile! 42)) (deref (atom 42 ; | :expr | :time | :ratio | :perc | ; |+---++---| ; | (deref (volatile! 42)) | 30.688238 |1.0 | 39.81 | ; | (deref (atom 42)) | 77.081141 | 2.51 | 100.0 | (report (let [v (volatile! 42) a (atom 42)] (timings 1e7 (vswap! v inc) (swap! a inc ; | :expr | :time | :ratio | :perc | ; |+++---| ; | (vswap! v inc) | 136.052946 |1.0 | 75.08 | ; | (swap! a inc) | 181.218748 | 1.33 | 100.0 | (report (let [v (volatile! 42) a (atom 42)] (timings 1e7 (vreset! v 10) (reset! a 10 ; | :expr | :time | :ratio | :perc | ; |+---++---| ; | (reset! a 10) | 98.755318 |1.0 | 96.69 | ; | (vreset! v 10) | 102.13944 | 1.03 | 100.0 | On Thursday, September 11, 2014 6:18:08 AM UTC+2, puzzler wrote: I'm curious: how much faster are volatiles than atoms? -- 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. -- 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: Pause a go loop
For instance you can use schejulure [1] or at-at [2] and make sure the scheduled function calls put an item (event) on the channel and then made the scheduler do the pausing work. All the listeners attached to the channel will receive the events at the time the scheduler releases them, and you don't have to manage anything regarding timing/pausing. /Linus [1] https://github.com/AdamClements/schejulure [2] https://github.com/overtone/at-at 2014-09-11 13:52 GMT+02:00 Jeremy Vuillermet jeremy.vuiller...@gmail.com: Hello, here is my use case (defn replay [history] (go (doseq [millis history] (! (timeout millis)) (prn millis history is a vector of duration: [1000 2000 4000] Now I would like to pause this doseq. One way is to use an atom pause?, check for the pause and block until a new value in a resume chan. But there may be an other way with channels only and avoid global/shared pause atom. I was naively thinking of a pause channel and at each loop I check if there is a value but I'm not sure it's better and I couldn't manage to do it 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 --- 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. -- 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: HTTP server that supports ring handlers, but asynchronously?
Pedestal pedestal-service handles requests asynchronously by extending the ring standard with Interceptors, sort of a state machine queue version the wrapped handlers of ring. /Linus Den 3 sep 2014 10:35 skrev Laurens Van Houtven _...@lvh.io: Hi James, Thanks for your response! Replies inline. On 02 Sep 2014, at 18:53, James Reeves ja...@booleanknot.com wrote: Ring uses blocking I/O by default, because that's often sufficient for most web servers, and is generally easier to reason about. HTTP works best when the response is returned ASAP, which means blocking I/O typically isn't much of a bottleneck. However, since Ring 1.2, all of the standard middleware has also been available to use asynchronously, in order to support frameworks like Pedestal. So it's certainly possible to use Ring in an async environment, at least with the core Ring libs. Although HTTP Kit doesn't use core.async channels itself, the async protocol used isn't complex. You should be able to hook up core.async/take! to http-kit/send!. Something like: (defn handler [req] (httpkit/with-channel req http-ch (let [resp-ch (async-handler! req)] (httpkit/on-close (fn [_] (a/close! resp-ch))) (a/take! resp-ch (fn [resp] (httpkit/send! http-ch resp) (httpkit/close http-ch)) That’s what I wanted to do, but then I saw the warning on http-kit’s website at http://http-kit.org/server.html#channel , which states: Data is sent directly to the client, NO RING MIDDLEWARE IS APPLIED. … which leads me to believe that the send! API just totally sidesteps any middleware, and it’s not so much up to the middleware whether or not it supports asynchronous operation. Unless of course it actually works fine, and that’s simply some stale documentation? That said, I'd be wary about having HTTP clients wait around on the server. If it's just a few seconds, that seems reasonable, but any longer and you should consider redirecting to a job resource instead. Yeah, I’ve been considering that. Looking at the distribution of response times right now, 5-10s is a small, but non-negligible part of the responses. However, the point of this software is being able to give third parties capabilities (in the object-capability sense), so typically some of the requests involve secrets the caller doesn’t get to know about (like API credentials). As a result, I’m trying to be hyper-conservative in terms of stuff that can leak information. I’ll have to think more about that one :-) hth lvh -- 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 streams
(Rich Hickey is the only one who could answer finally but...) I think this information is old and outdated, streams didn't really make it into clojure. The things that survived was the *sequence* abstraction (which is used almost everywhere), later the *reducers* (facilitating javas fork-join constructs nicely interleaved with the clojure b-tree-like data structures) and last but not least the *transducers* concept, where transducers actually are very similar to the outlines of the streams abstraction in the link you mentioned with their continously spinning transform functions. http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming Core.async is somewhat similar, but has other use cases in mind (sane wrapping of an event stream of various side-effects). /Linus 2014-08-29 20:56 GMT+02:00 Greg MacDonald gtmacdon...@gmail.com: Hi Everyone, Does anyone know the status of clojure streams is? I would like to try them out but I can't find the svn repository mentioned on the website: http://clojure.org/streams. Thx! -Greg -- 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. -- 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: Is Clojure a language for growth?
Well, for better or worse we don't like conflicts that much. This has benefits when it comes to some kinds of problem solving (the way to consensus in Swedish companies is worth at least a chapter in a big book about antrophology). This shyness for open conflicts can lead to stagnation. This means that status quo is not turned over that easily, but when it does, it happens like an avalanche (cow oscillator comes to mind). Stockholm University has Clojure and Erlang in its second year curriculum for computer science. Just saying. Apart from that, its 3kloc database queries and Java classes galore and Wordpress shops all over, like everywhere else. The single larges group of workers in Stockholm is of course computer programmer. 33000 people out of a million of so. If an investor were kicking people out, its usually because money is running low or for other more diffuse reasons. If an investor or boss somewhere where kicking out people at random, he would quickly loose respect from his other employeers. The rest would soon leave as well. In Sweden we have a system... the ironic saying goes, but the truth is that even though the housing situation is outright catastrophic, you would not ever be put on the street if you wasn't psychotic enough not to accept the help offered (worst case you would end up in a sad, sleepy, far far out suburb with long commuting distances, but hey). The social security system is simply generous enough to make sure people gets back on track, should it be long time unemployment or whatever (this, and elderly care jobs, are powering much of the popular music industry here). Ah, everybody generalizes all the time. Henrik can nuance the picture. I have been programming and promoting Clojure quite aggressively for some years (it's hard not to), and the last months people have been starting to say yeah, my java friends really likes it or yes, my bf likes it too. Wind of change. /Linus working at Agical AB, a consultancy in love with technology and sometimes hosting Clojure Meet ups with Stockholm Clojure User Group and wov, so much thing I really can help companies with everywhere, epic win On Wednesday, August 20, 2014, Quzanti quza...@googlemail.com wrote: Just looked at your profile. Sweden? A very enlightened place. I am a big fan of the Paradox Interactive games. What happens in Sweden when investors lose their money? On Wednesday, August 20, 2014 7:16:55 PM UTC+1, Henrik Eneroth wrote: … as soon as anything goes wrong whether it has anything to do with the technology choice or not you become mr fall guy, to be blamed and fired so that other people can keep their jobs. Seen it happen so many times. Good lord, truly? Perhaps this is a good time to ask what culture OP lives in. This wouldn't happen where I live/work. -- 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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: setrlimit from Clojure
According to this [1] post one can reachything in Glibc with JNA. I have never tried. /Linus [1] http://unix.stackexchange.com/questions/1681/invoke-syscalls-from-java On Wednesday, August 20, 2014, Chai Tadada chai.tad...@gmail.com wrote: Hello, Is it possible to call the setrlimit syscall on Unix (I want to increase the NOFILE limit from my program)? Is there a Clojure or Java binding for this? Tried to Google clojure setrlimit and java setrlimit, but did not get anything useful. -- 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 javascript:; 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 javascript:; 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 javascript:;. 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: Benchmarking structural sharing
You could likely use System/identityHashCode to count the similarity of objects all the objects. I created a small function that only honors the clojure-visible structure, and exposes every item in a tree structure (apart from the arrays in PersistentVectors and some PersistentMaps) (defn steam-roller [l] gives a representation of all object pointers in a nested structure by both adding pointers to everything seqable as well as its contents it also takes out keys and vals of maps, as well as the whole map (let [l [l]] (loop [l1 l l2 '()] (cond (sequential? (first l1)) (recur (concat (first l1) (rest l1)) (cons (first l1) l2)) (map? (first l1)) (recur (concat (keys (first l1)) (vals (first l1)) (rest l1)) (cons (first l1) l2)) (empty? l1) (reverse l2) :else (recur (rest l1) (cons (first l1) l2)) (inspired by slovic's version of flatten at http://clojuredocs.org/clojure_core/clojure.core/flatten) Example output is: (steam-roller *[:a :b {:c 2 3 4}]*) - (*[:a :b {:c 2, 3 4}]* :a :b {:c 2, 3 4} :c 3 2 4) You could then make some trivial statistics collection like (map #(System/identityHashCode %) (steam-roller {1 2 3 4})) - (359344022 504432400 1778018115 1172818142 256714182) where (set) gives the unique HashCodes. The reasoning behind not taking out mapEntries of maps, but just the keys and vals is that maps usually is k-v-pairs in an Object-array or a shallow tree of those Objectarrays. This does *not* take care about either implementation details in either PersistentVector or rrb-vector. I guess one could use https://github.com/arohner/clj-wallhack or https://github.com/zcaudate/iroh to walk around inside the inners of PersistentVector and rrb-vector. The conclusion of this is I think the easiest way to make this work is to just run the algorithm in both versions and watch the object allocation statistics closely in VisualVM or similar. My intuition is that the there will be a lot of copied arrays, but that's quite quick (not as quick as shuffling longs with sun.misc.Unsafe, though). /Linus 2014-08-11 14:56 GMT+02:00 Paul Butcher p...@paulbutcher.com: Is there any way to benchmark the degree of structural sharing achieved by a Clojure algorithm? I'm evaluating two different implementations of an algorithm, one which uses zippers and one which uses rrb-vector. It would be great if there were some way to quantify the degree to which they both achieved (or didn't) structural sharing. -- paul.butcher-msgCount++ Silverstone, Brands Hatch, Donington Park... Who says I have a one track mind? http://www.paulbutcher.com/ LinkedIn: http://www.linkedin.com/in/paulbutcher Skype: paulrabutcher Author of Seven Concurrency Models in Seven Weeks: When Threads Unravel http://pragprog.com/book/pb7con -- 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. -- 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: A more general case of some-?
Check out pedestals interceptors, they handle both error and pause/resume-request functionality. Seems you could have great use of it. Pedestal-service is the repo. pedestal.io /Linus On Monday, July 21, 2014, Leon Grapenthin grapenthinl...@gmail.com wrote: The predicate parameter introduces an additional predicate check on a per-step basis which can be avoided under most circumstances. If check-auth or check-balance return just their input value where that is valid, threading has no use here. They could be modified to only return something if there is an error, otherwise nil. For clarity, they could then be called auth-error and balance-error. They could be composed with some-fn and be used in a handler to serve the error as early as possible. E. g. (def my-handler-error (some-fn auth-error balance-error)) (defn my-handler [request] (or (my-handler-error request) ;; serve response )) On Monday, July 21, 2014 6:20:50 PM UTC+2, Max Countryman wrote: Hi, Recently I found myself wanting a macro similar to some- or some- but one where I could specify an arbitrary predicate instead of nil?. For example, I have a Ring request map which I wish to pass through a number of functions. Any of these functions might return an error response and if so I do not want to evaluate any remaining forms—much like how some- will not evaluate after a nil response. To do this, I wrote a macro that is essentially some- but which takes a predicate. Here’s the macro I ended up with: (defmacro until-pred- Like some- but evalutes via - until or if a predicate is true. [pred expr forms] (let [g (gensym) pstep (fn [step] `(if (~pred ~g) ~g (- ~g ~step)))] `(let [~g ~expr ~@(interleave (repeat g) (map pstep forms))] ~g))) An example of how I might use this: (defn my-handler [request] (until-pred- error-response? request check-auth check-balance …)) That said, I’m wondering if there is a more idiomatic way of passing Ring request maps through a series of functions, each of which might be a terminal step? I’m also curious if there’s a particular reason some- wasn’t implemented in a more general way; perhaps the fact that I can so easily write a macro that achieves this myself is a good enough reason? Thanks, Max -- 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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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 Averaging function
You should try Clojure Programming (Halloway, Bedra). I felt enlightened after reading the first edition, the second edition is also very good! http://pragprog.com/book/shcloj2/programming-clojure /Linus On Thursday, July 10, 2014, Stephen Feyrer stephen.fey...@gmail.com wrote: Hi Sam, Lee. Thank you both. It would appear that I am faced with the old adage, A little knowledge is a dangerous thing. Again thank you, you ' ve been a great help. If I may impose upon you a little further? Would either of you be able to recommend an introductory book either for Clojure or FP that might fit well with Clojure, for the mildly bewildered? I have a book Programming Clojure but it is written with an assumption of prior knowledge/experience which I don't have. By the way, Programming Clojure is a good book, I just don't think I fit within the target audience. On 10 July 2014 02:41, Lee Spector lspec...@hampshire.edu javascript:_e(%7B%7D,'cvml','lspec...@hampshire.edu'); wrote: On Jul 9, 2014, at 9:31 PM, Lee Spector lspec...@hampshire.edu javascript:_e(%7B%7D,'cvml','lspec...@hampshire.edu'); wrote: You could patch (not recommended!) this by adding do to the beginning of that list: Or -- I now see, instead of adding the do you could just remove the outermost parentheses after the parameter list. But as Sam and I said this is a bad way to go anyway -- you want to avoid the nested defs. -Lee -- 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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: OT: Github Alternatives
gitolite? I think we used it on one of my jobs. https://github.com/sitaramc/gitolite /Linus On Monday, June 30, 2014, Di Xu xudi...@gmail.com wrote: gitlab[1]? [1] https://about.gitlab.com/ 2014-06-30 18:34 GMT+08:00 Adrian Mowat adrian.mo...@gmail.com javascript:_e(%7B%7D,'cvml','adrian.mo...@gmail.com');: Hi All, Sorry for the off topic thread but my company is looking at alternatives to gihub that are a) hosted internally and b) cheaper (!) I was wondering what everyone else is using out there? The features we use most on github are easy creation and navigation of repos, commit/diff browsing and user/team management facilities Many Thanks Adrian -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: lazy list comprehension
You probably want map-indexed http://clojuredocs.org/clojure_core/1.2.0/clojure.core/map-indexed /L 2014-06-27 17:10 GMT+02:00 Leonardo Borges leonardoborges...@gmail.com: Try using map : (map str '(my-list-of-crap) (iterate inc 0)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To 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. -- 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: When to use (ensue) ?
See points 2, 3 and 8 at http://clojure.org/refs It is just a way to obtain the change lock of the ref in the dosync transaction, without rewriting it. The alternative would be to explicitly modify it to the same value as it was before, which is potentially wasteful. One possible case where this could be useful would be when you have some synchronized state that should not be touched while another is. Fictional elevator example: (def elevator-doors (ref :closed)) (def elevator-floor (ref 1)) ;; Elevator doors should NOT be opened while the elevator changes floor (dosync (alter elevator-floor inc) (ensure elevator-doors)) /Linus On 2014-06-19 17:35, Patrick Kristiansen wrote: I believe it is to avoid write skew. Check this Wikipedia page: http://en.m.wikipedia.org/wiki/Snapshot_isolation -- 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: Understanding when compilation occurs - for function producing functions
On Saturday, June 21, 2014, Di Xu xudi...@gmail.com wrote: Suppose at my REPL I do... (defn direct-report-oneplustwo [] (println (str Direct one plus two is ((fn [n] (+ 1 n)) 2) .))) ...then I presume that the compiler has compiled my direct-report-oneplustwo function, and that this has included compilation of my anonymous function (fn [n] (+ 1 n)). So that now if I run... (direct-report-oneplustwo) ...at my REPL it just needs to run this precompiled code to tell me my answer 3 - no additional compilation required. So far so good. But what if instead I do this at my REPL... (defn adder-make [m] (fn [n] (+ m n))) (defn indirect-report-oneplustwo [] (println (str Indirect one plus two is ((adder-make 1) 2) .))) ...Now at this point, both adder-make and indirect-report-oneplustwo should have been compiled. But unlike our first approach, the anonymous function (fn [n] (+ 1 n)) has not yet been created by (adder-make 1) and so presumably (??) has not yet been compiled?? I am presuming that it is only when we actually run the report function... (indirect-report-oneplustwo) ...that (adder-make 1) is actually run, thereby producing the anonymous function (fn [n] (+ 1 n)), which then gets compiled right then-and-there, immediately followed by its execution?? Well, you misunderstand it, as far as I know, clojure treat all fn as object, so in your adder-maker example, clojure compiled two fn as object, that's adder-maker itself and anonymous function it returns. The compiled add-maker is just instantiate that anonymous with `m`, and return it. So (adder-maker 1) will produce that instantiated anonymous function, and since it's a function and it's in the first position of list, clojure will invoke it with 2, and that anonymous function will do actual computation. functions are compiled at once when clojure reader meet them, and invocation is just the matter of instantiate. Thanks, Di Xu What's the reason for asking? If you aim for making efficient code (that is running very many times in tight loops), I think most of this will be inlined by the JIT, as long as it is not confused by side effects and other things. As long as the JVM can optimize the procedure, it's of lesser importance how Clojure solves it in one-shot scenarios. Maybe I somewhat dodge the question, but dynamic just in time compilation is so mindblowing cool that an hypothesis about the quickest possible way to solve the problem combined with profiling is what matters most in practice. /Linus -- 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: BeagleBone Black Continuous Analog Reads
I would say it's not so much about programming paradigm rather than system calls. It all boils down to how often you would want to read the data. If it's not more than some times per second, and it's not super important with timing, you could probably put a reading function in a SchedulingThreadPool (you can add Clojure functions as is since they are Runnable) or have a look at the at-at library spawned from overtone. https://github.com/overtone/at-at One way to react on the incoming values are to swap! or reset! them into an atom, which has a watcher-function added which could things based on the new and old values. http://clojuredocs.org/clojure_core/clojure.core/add-watch shows an example with agents, but it works for atoms as well. If you want to store an incoming series of values for further processing, either use the clojure.lang.PeristentQueue or some Java equivalent. If you want to sample in very high frequency, (kilohertz) you'll need to fetch the values in some loop close to machine an batch it into Clojure by primitive-buffers or similar (like soundcards, UARTs and network stacks do). /Linus 2014-06-18 5:08 GMT+02:00 Jeremy Wright wright...@gmail.com: The main way of reading the inputs (analog or digital) on a BeagleBone Black is through the Linux file system. http://beaglebone.cameon.net/home/reading-the-analog-inputs-adc I'm still pretty new to Clojure and come from an object oriented background. I would like to do a continuous read of the BBB's analog inputs through the file system and make decisions based on the values. There are different ways of handling this from an OOP perspective, but I'm not sure how to approach it from a functional perspective. Can someone point me in the right direction? -- 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. -- 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: using hidden parameters?
A more commonly used feature are bindings, which are sort of pluggable (or rather overridable) dynamic vars. http://stackoverflow.com/questions/1523240/let-vs-binding-in-clojure In short you declare a variable as dynamic and then use some binding around the function-call. Sort of a reusable let-body, but with slightly different characteristics. /Linus On Saturday, June 14, 2014, Mars0i marsh...@logical.net wrote: Here's a way to do it. Not sure if this is what you want. (let [x (atom 12)] (defn next-number [] (swap! x inc))) Functions are clojures, which means that next-number can retain a pointer to a variable that it can see when it's defined. If some of the ideas here are unfamiliar: The atom function gives you something that you can modify in place, in effect, and swap! is one way to modify it. Passing inc to swap! applies inc to the value in the atom x, and stores the result back into the atom. (I'm not sure if my wording here is precisely correct, but the idea should be clear enough.) You can also use a top-level variable instead of a local one defined by let: (def x (atom 12)) (defn next-number [] (swap! x inc)) @x ;= 12 ; [the @ operator gets the value out of the atom.] (next-number) ;= 13 @x ;= 13 (next-number) ;= 14 With the let form, (next-number) is your *only* way of accessing x, which could be a good thing or a bad thing--unless you define other functions in the scope of the let at the same time that you define next-number: (let [x (atom 12)] (defn next-number [] (swap! x inc)) (defn undo-next [] (swap! x dec)) (defn check-number [] @x)) (check-number) ;= 12 (check-number) ;= 12 (next-number);= 13 (check-number) ;= 13 (undo-next);= 12 (check-number) ;= 12 (Perhaps many Clojure programmers *would* consider all of this perverse, but similar things are considered ... cool in the some corners of the Scheme and Common Lisp worlds. (cool doesn't necessarily mean useful often--just *cool*--and maybe useful now and then.)) On Friday, June 13, 2014 7:16:09 PM UTC-5, Christopher Howard wrote: This might be kind of perverse, but I was wondering if it was possible to write a function or macro that takes hidden parameters, i.e., uses symbols defined in the scope of use, without passing them in explicitly. For example, function next-number takes hidden parameter x, so = (let [x 12] (next-number)) Would return 13. With the whole code is data paradigm it seems like this should be possible, but I haven't figured out how to do this yet without getting an error. -- 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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: time expression of clojure produces different results on cascalog queries
It says Criterium ran four batches of 60 samples in each (it tries to make the jvm då garbage collection etc between each such batch). In total, 240 samples (ie timed test runs). The statistics are better looked up at wikipedia, but lower quartile here means the 2.5% of the 240 samples (0.025 * 240 = 6) that had the lowest time where 229.8 ms etc. Outliers are intresting, since there can be some that takes much much longer time than other. Overhead (in this case negible small) is the time criterium takes in the samples, I think. Your results looks consistent, the one minute delay you saw initially COULD have been delayed by a full Garbage Collection. These can be triggered at random in production, so try to collect metrics (there's both clojure and java libs for that, named something metrics) in production or with realistic loads! And remember you can tweak the GC in many ways to make it less rude to your application. /Linus On Saturday, June 14, 2014, sindhu hosamane sindh...@gmail.com wrote: Thanks a ton for ur reply's Andy and Thomas . I used Criterium and got results like below : Evaluation count : 240 in 60 samples of 4 calls. Execution time mean : 265.359848 ms Execution time std-deviation : 25.544031 ms Execution time lower quantile : 229.851248 ms ( 2.5%) Execution time upper quantile : 310.110448 ms (97.5%) Overhead used : 2.708614 ns But i don't understand the output . What does Evaluation count : 240 in 60 samples of 4 calls. mean ? Also little unclear about other details too. Could you please make me understand a little about above output !! Would really appreciate ur help . Cheers, Sindhu -- 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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Use Nodejs modules in Clojurescript code that targets browsers?
Yes, by using externs: http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html A bit dated, but I think this is still the way to go! /Linus 2014-06-08 6:36 GMT+02:00 Gabrien phuthuycuoimayhut...@gmail.com: Is there any way to use nodejs modules (the browserifiable ones) in Clojurescript code that targets browsers? AutoSaved textareas Restored textareas Cleared AutoSaved data AutoSaved textarea data available -- 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. -- 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: Advice on managing random number generators across threads
(I think your stepwise problem is better to be solved without agents, see below.) I realized that the *rng* actually is conflated, it keeps both the state for the random number generator AND the algorithm used for the random number generation. This is usually not a problem, since the state-size and usage is dependent on the particular random number generator, but it becomes a problem when we need to separate and multithread things. One solution would be to either re-implement the algorithm (by Knuth) used in the original Sun Java random implementation, or use the experimental library Four [1] by Gary Fredericks that does exactly this. What you would like to do is to be able to feed the rng-algorithm with the state (it is just a 64 bit long), and simply take the random-result generated from it, and store the state in the agent together with the rest of the simulation state. Dubious Speculations: This makes it necessary to know that the agents are called in the same order (if the influence on each other). Given the non-guarantee of ordering in the nature of Java Threads and how agents rely on them I don't think you can expect your result to be reproducible. Here I assume that the incoming calls to agents aren't guaranteed to strictly ordered among different agents, even though the agents reside in one of two thread-pools (the send- vs. send-off pools). If two agents sent messages that arrived a third agent in different order, the rng-state would differ between the runs). Please correct me if I'm wrong on this one. A possible clever way around this could be to send the rng state together with the message arriving at the agent, to make the agent at least react to the state in a similar way. If you have some kind of continous magnitudes in the simulation - like pheromones - the simulation would maybe converge to similar results since the interaction effects would be reproducible but this is indeed a very far-fetched hypothesis. So only if your Person transform functions are commutative (ie gives the same result whichever order they was called in every timestep) the simulation could be reproducible by storing the local random generator seed in each Person. If it's just speed you are after, do use either the java 1.7 ThreadLocalRandom (at least try out if this really gives any performance boost). A naive ThreadLocalImplementation implementation of clojure.core/rand would be: (defn rand Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive). {:added 1.0 :static true} * ([] (.nextDouble (java.util.concurrent.ThreadLocalRandom/current)))* ([n] (* n (rand but as you can see in the source code, random integers are generated using a call to (rand), multiplied with the integer and floored (when converting to int), so there are ways to get an limited range int more efficiently (check the source code for java.util.Random, which makes various tricks for getting just enough random bits out. As always, measure performance (Hugo Duncans Criterium, criterium.core/bench is a really good start). Numerical double operations are cheap, memory accesses - in this case to resulting data structures or other agents and likely context switches - could as well be the more expensive part. BTW: It looks like the problem you want to solve would benefit much from being formulated as a two-step problem, one where you applied all the incoming calls to each Person, and another where you sorted the messages to each Person in some reproducible order, like * = has an incoming message initial state: Person A will hit Person B, just for the lulz. apply map: A* B C resulting actions sorted by Receiver: [A hits B] apply these: A B* C [B gets mad and throw raspberry pies at both A and C] A* B C* [A yells at B, C yells at B] - mind the ordering! Always apply A's action before Cs (or let B's random seed shuffle a sorted ordering of the same to avoid ordering biases and make it reproducible) A B* C [B sends a stern look to A and C] no further actions If you makes the message passing explicit instead of Java-thread-call-uncertain-implicit (which IS possible and parallelizeable in a stepwise simulation!) you can still parallelize it in many ways (for example with reducers) and at the same time make simulations reproducible, and you'll avoid a lot (N²) of potentially expensive context switching. /Linus - take everything I say with a sand-pile avalanche of salt-grains. [1] https://github.com/fredericksgary/four 2014-06-06 18:37 GMT+02:00 Mars0i marsh...@logical.net: One more point: I would save the system-time-determined seed of the initial RNG to a file (i.e. the RNG used to generate seeds for each Person's RNG). I believe this will allow me to re-run a simulation with identical results, by seeding the initial RNG with the seed saved from the previous simulation run. Let me know if this doesn't make sense. Thanks. -- You received this message because you are subscribed to
Re: use :only in ns
Either :use with [seesaw.chooser :only [choose-file]] like (ns ... (:gen-class) (:use [seesaw.chooser :only [choose-file]]) or the beefed up refer functionality: http://clojuredocs.org/clojure_core/clojure.core/refer which can have :only, :exclude and :rename to avoid collisions, which is more powerful. More info here: http://clojure.org/libs and yes, the seemingly random wrapping of things in lists/vectors that sometimes should be quoted and sometimes not is confusing and has been up to discussion several times. in practice it works quite well, though. /Linus On Thursday, June 5, 2014, Glen Rubin rubing...@gmail.com wrote: In my ns i am using a couple of libraries, e.g. (ns providence.core (:gen-class) (:use seesaw.chooser)) However, I only want to use 1 or 2 commands from these libraries, for example (choose-file) from the above seesaw.chooser. How do I specify only a single library? thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Past and future of data.generators
I do agree that the name data.generators is not where to look for a controllable random source. A more specific name for these functions should be considered. The java.util.Random has been an issue for me in stress-testing random read and writes to a huge memory-area by several threads. If I was to do it again I would use the java.util.concurrent.ThreadLocalRandom to generate random numbers in parallel. (j.u.c.TLR is only availiable in jdk = 1.7.0, clojure.core aims for 1.6.0 as well. The core.async library do use ThreadLocalRandom. The reducers functionality has a conditional import, which I think is only to be used as a very last resort in clojure.core. A surprise and caveat is that the performance was really bad when live-generating random memory addresses - likely because of cachetrashing. The performance was indeed much higher when using a prerealized (very long) random sequence of random data. A functionality for generating random memory addresses would likely benefit from having a buffer for helping the hardware pre-fetch memory (which is often a realistic scenario in stream processing). summary: - better namespace for random object/number generation - ThreadLocalRandom is only avail in jdk 1.7.0 - stresstests do benefit from buffering incoming random data, which is more realistic as well. I will dig deeper in criterium to see if this is already implemented there. /Linus On Thursday, June 5, 2014, Mars0i marsh...@logical.net wrote: clojure.core provides a minimal set of functions for random effects: rand, rand-int, and rand-nth, currently with no simple ability to base these on a resettable random number generator or on different RNGs in different threads. (But see this ticket http://dev.clojure.org/jira/browse/CLJ-1420 pointed out by Andy Fingerhut in another thread.) data.generators includes additional useful general-purpose functions involving random numbers and random choices, but this is entirely not obvious when you read the docstrings. (Some of the docstrings are pretty mysterious.) It's also not necessarily what one would guess from the name of the library. (None of this is a criticism of anyone or anything about the project. Data.generators is at an 0.n.m release stage. I'm very grateful for the work that people have put in on it.) As I understand it, data.generators was split off from test.generative, which sounds like a good idea.So data.generators was intended to provide functions that generate random data for testing. (I imagine that the existing documentation makes more sense in the context of test.generative, too.) However, what's in data.generator has more general applications, for people who want random numbers, samples, etc. outside of software testing. (In my case, that would be for random effects in scientific simulations.) Off the top of my head, it seems to me that these other applications might have slightly different needs from the use of data.generators by test.generative. For one thing, efficiency might matter a lot in some simulations, but not in software testing. (At least, *I* wouldn't care if my test functions were slow.) I'm not saying that functions in data.generator are slow, but I don't think there's a good reason to worry about making them efficient if they're only intended for software testing. Further, there are other needs than are currently provided by test.generators. See the sampling functions in bigml/sampling https://github.com/bigmlcom/sampling or Incanter http://incanter.org/, for example, and lots of other random functions that Incanter provides. Some of those should remain in Incanter, of course, but I wonder whether Clojure would benefit from a contributed library that satisfied a set of core needs for random effects. (Incanter partly builds on clojure.core's rand at this point.) Maybe data.generators is/will be that library. Or maybe parts of data.generators would make more sense as part of a separate library (math.random? data.random? math.probability?) that could be split out of data.generators. (If it doesn't make sense to split data.generators, then would a new name for the library be more appropriate?) Just some things I was wondering about. Curious to see what others say. (Fun tip: Check out data.generators' anything function, which is like Emacs' Zippy the Pinhead functions for people who prefer industrial atonal music composed by randomly filtered Jackson Pollock paintings, to speech. Or: People who want to thoroughly test their functions by throwing random randomly-typed data at 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 javascript:_e(%7B%7D,'cvml','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
Re: Allow reseeding/rebinding RNG behind rand?
Data.generative already has this function and many more, I realized. /Linus On Wednesday, June 4, 2014, Mars0i marsh...@logical.net wrote: On Wednesday, June 4, 2014 2:55:20 AM UTC-5, Gunnar Völkel wrote: Once you notice that you usually need a fast solution. Yes! The easiest solution is to just pass around an instance of java.util.Random which you create with the desired seed. Another options is to have a constructor function returning a rand function. (defn prng [seed] (let [rnd (java.util.Random. (long seed))] (fn rand [] (.nextDouble rnd Thanks. This is very helpful. I have not been thoroughly immersed in the Java world for many years, so I have to spend a bit of time studying in order to figure out this sort of thing on my own. (I like Clojure because I usually only need to deal with Java when I want to, but there are times when it's necessary.) But having a built-in rebindable (thread-local) rand is preferable in the long run. Yes, especially since rolling one's own version means coding up any higher-level functions that use randomness, when others who have thought more about relevant algorithms have already done that work. Then again, their source code is usually available, so one can copy it. For my present purposes, data.generators or bigml/sampling might do what I need. -- 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 javascript:_e(%7B%7D,'cvml','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 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com'); For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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: Allow reseeding/rebinding RNG behind rand?
Sorry, of course i meant the clojure.data.generators library https://github.com/clojure/data.generators esp. the *rnd* that can be bound around many of the functions in the library. /Linus On Wednesday, June 4, 2014, Linus Ericsson oscarlinuserics...@gmail.com wrote: Data.generative already has this function and many more, I realized. /Linus On Wednesday, June 4, 2014, Mars0i marsh...@logical.net javascript:_e(%7B%7D,'cvml','marsh...@logical.net'); wrote: On Wednesday, June 4, 2014 2:55:20 AM UTC-5, Gunnar Völkel wrote: Once you notice that you usually need a fast solution. Yes! The easiest solution is to just pass around an instance of java.util.Random which you create with the desired seed. Another options is to have a constructor function returning a rand function. (defn prng [seed] (let [rnd (java.util.Random. (long seed))] (fn rand [] (.nextDouble rnd Thanks. This is very helpful. I have not been thoroughly immersed in the Java world for many years, so I have to spend a bit of time studying in order to figure out this sort of thing on my own. (I like Clojure because I usually only need to deal with Java when I want to, but there are times when it's necessary.) But having a built-in rebindable (thread-local) rand is preferable in the long run. Yes, especially since rolling one's own version means coding up any higher-level functions that use randomness, when others who have thought more about relevant algorithms have already done that work. Then again, their source code is usually available, so one can copy it. For my present purposes, data.generators or bigml/sampling might do what I need. -- 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. -- 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: Search seqs in seqs
Maybe reduce-fsm could be useful? https://github.com/cdorrat/reduce-fsm It creates a simple state finite state machine that can be applied on any sequence. /Linus 2014-06-03 11:04 GMT+02:00 Ulrich Küttler kuett...@gmail.com: Hi, what is the preferred way to find sub-seqs in a seq? I am trying to convert [:a :b :c :d :a :b :c :d :a :b :c] into ((:a) (:b :c) (:a :d) (:b :c) (:a)) using the sub-seq (:b :c) instead of positions. partition, partition-by and the like all look at one element at a time. What I need is a search based on seqs. Are there functions that support such a search / split? Uli -- 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. -- 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: Short tutorials on ClojureScript
This looks really promising. One question: when one builds modern-cljs, is there any extra configuration needed for getting the clojurescript compiler up and running? I get a java.lang.String cannot be cast to clojure.lang.Associative when doing $ lein buildcljs once, which I don't really know where to go on from. I have the clojurescript compiler installed... somewhere. /Linus 2012/11/7 Mimmo Cosenza mimmo.cose...@gmail.com Thanx jaju… I'll try my best to go on with modern cljs tutorial in my spare time. I just published the 4th tutorial (form validation). Hope to be useful and fun. Mimmo On Nov 7, 2012, at 9:14 AM, Ravindra Jaju ravindra.j...@gmail.com wrote: Perfect! Had been waiting for some thing like this, and I followed the first two parts - worked flawlessly! Thanks! -- jaju On Mon, Nov 5, 2012 at 8:59 PM, Mimmo Cosenza mimmo.cose...@gmail.comwrote: Hi, I started a short series of tutorials on ClojureScript that I'm writing in my spare time. You can find them at https://github.com/magomimmo/modern-cljs hope could be useful...and to have enough time to go on with the next ones... Mimmo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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: What's the efficient functional way to computing the average of a sequence of numbers?
or to increase a counter while reducing it, a function like inc+ returning {:sum sum :count count} and then take the sum/counter, which is the mean. The problem is possible to state as a clean map-reduce problem with only one traversing of the data. It's also possible to remove items form the mean operation (ie, the problem is associative). /Linus 2012/3/29 simon.T simon.j@gmail.com The obvious way is like the following, which traverse the sequence 2 times. Wondering what will be the efficient way... (defn avg [coll] (/ (reduce + coll) (count coll))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A New Core.logic Primer
2012/3/14 David Nolen dnolen.li...@gmail.com On Wed, Mar 14, 2012 at 4:09 PM, Daniel Gagnon redalas...@gmail.comwrote: On Wed, Mar 14, 2012 at 3:00 PM, David Nolen dnolen.li...@gmail.comwrote: Thanks to Edmund Jackson we have a new primer for core.logic: https://github.com/clojure/core.logic/wiki/A-Core.logic-Primer Feedback appreciated! David It's pretty good and I think it's very accessible. If you compare to Learn Prolog Now! http://www.learnprolognow.org/lpnpage.php?pageid=online it lacks in the Pulp Fiction references department but it's still good. I think you should say a word about prolog and mention that unlike it core.logic isn't turing complete and can't have infinite loops (unless I'm mistaken about core.logic) core.logic suffers the same pitfalls as Prolog for the most part :) Thank you for making learning resources availiable in this vibrant and powerful clojure-functionality. I'm missing a (very) short note on how to get started. Using leiningen with :dependencies [[org.clojure/clojure 1.3.0] [core.logic 0.6.1-SNAPSHOT]] and defining a file for the primer as (ns logictest.primer (:refer-clojure :exclude [==]) (:use [clojure.core.logic])) according to the Readme.md just renders a Could not locate clojure/core/logic__init.class or clojure/core/logic.clj on classpath: for me when executed, which is unexpected. Will carry on trying, but I remeber this have bitten me before when trying to hacking core.logic. What is a correct minimal experimental setup? /Linus -- 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: datomic has been announced
Mindblowing! I can imagine many applications for datomic, it looks like a very powerful abstraction which is overcoming many of the problems I've been encountering when I've built applications. Thanks, Rich! Chris Grangers awesome experimental UI for developing javascript games is covered in Wired's blog Webmonkey: http://www.webmonkey.com/ (I found it browsing the http://Wired.com!) Congratulations! /Linus 2012/3/5 kovas boguta kovas.bog...@gmail.com Since not everyone reads twitter or hacker news, http://datomic.com/ has been updated with an unveiling of Rich's new project. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: [clojurescript one] Where does Clojurescript One come from?
The rationale for Clojurescript is available here: https://github.com/clojure/clojurescript/wiki/Rationale I would say it's a way to wrap the large possibilities of javascript in a saner and quite well known environment for Clojurians. The way to use the Google Closure libs+compiler is very clever, I must say. The idea is that you use java-Clojure in the background to compile things to browsers since they often need a webserver somewhere for sane persistence anyway. Therefore Clojurescript is missing eval and some other clojure/lisp constructs. It's a compiled lisp, with the aim on robustness and the ability to use it in production with the least effort (which, from what I understand, is quite substancial). Also, javascript is singlethreaded, so everything that uses threads in ordinary Clojure is faked in javascript. Some constructs (the refs among other things) is not implemented yet. /Linus 2012/2/28 Denis Labaye denis.lab...@gmail.com Hi, I discovered Clojurescript One recently, it is amazing, but it's also very alien to me, I never seen something like this before, as it says on the Github's README: ClojureScript One is hard to classify. It is not a library or a framework. It is more like a classroom, a laboratory or a starter kit. Could anyone point me to the projects that inspired Clojurescript One? (I suspect some Ruby-ish stuff, or maybe more ancient Lispy or Smalltalky(?) roots). Thanks, Denis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: notes on Mathematica pattern transformation Clojure predicate dispatch
2012/2/23 Cedric Greevey cgree...@gmail.com On Thu, Feb 23, 2012 at 2:41 PM, kovas boguta kovas.bog...@gmail.com wrote: In general the way repl's handle state is pretty busted. Ever create a piece of data and then later wonder, how the heck did I make this? One simple thing would be if the repl logged sessions to sequentially-numbered files. You'd be able to do a lot with just grep and a text editor to retrace your steps, and even to distill repl experiments down into .clj source files. A great idea. I would also love that the source + unixtime was attached to meta when the function was interactively inserted, since that usually isn't that big overhead + great for checking it out later on... /Linus ...getting a bit excited. -- 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: ns :import / reflection
Wrong type of parens! This works for me: (ns test (:import [java.io File])) it's a bit of a gotcha, though. /Linus On 2/18/12 10:29 PM, ClusterCat wrote: Hello, I have two newbie questions: First - (ns test (:import (java.io File))) I can use File like this (let [file (File. filename)]))) When using this import (ns test (:import (java.io.File))) I get an Unable to resolve classname: File which I don't understand. Second -- With this small piece of code (ns test (:import (java.io File))) (set! *warn-on-reflection* true) (if (nil? *command-line-args*) (println No command line arguments given.) (let [filename (first *command-line-args*)] (println filename) (let [file (File. filename)]))) I get an Reflection warning, X:\workspace\ClojureTest\bin\test.clj:9 - call to java.io.File ctor can't be resolved. which I also don't understand. Thanks in advance, Marcel -- 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: Newbie to Clojure..
Nazar, I don't know what you mean by Intelligent but please checkout WebNoir [1] for a quick way of building web applications in Clojure. If you are into rich web applications (ie clever client side) ClojureScriptOne [2] also might be an option for you. To just get started with the language (which took me a while), I can recommend Programming Clojure by Stuart Halloway, but there are other really good books as well. They are all well worth their money. Don't hestitate to elaborate if you have further questions. I would love to write a short overview of the different frameworks and architectural possibilities in Clojure targeted to newcomers. /Linus [1] http://www.webnoir.org/ [2] http://clojurescriptone.com/ On 2/18/12 4:38 PM, nazarhussain_s wrote: Hi Folks, Im a newbie to Clojure. I am an IT Developer and into web application development in J2EE. Can anyone please provide info as to whether and how clojure will help me in developing Intelligent web applications and services and any resources for getting started on Clojure. Thanks in Advance Nazar -- 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: Lack in the documentation
A treasure! I will from now on start to jot down whatever I do also. /Linus 2012/2/16 Sean Neilan s...@seanneilan.com Of course, I won't be able to write the entire Recipe Book by myself. I will contribute all the recipes I have discovered with test cases. On Thu, Feb 16, 2012 at 11:40 AM, Sean Neilan s...@seanneilan.com wrote: I'm working on something like this by keeping notes on everything I've encountered so far in Clojure 1.3.0. Please understand that these are* personal notes* and as such are very, very messy. http://seanneilan.com/Clojure.html When I have the time, I will volunteer to clean up my notes and turn it into a Clojure 1.3.0 Recipe Book in the same vein as the Python Documentation. It will be a mix of Java and Clojure that tells you what to do and how to do it. No more no less. On Thu, Feb 16, 2012 at 11:16 AM, David Nolen dnolen.li...@gmail.comwrote: On Thu, Feb 16, 2012 at 12:04 PM, Gregg Williams greg...@innerpaths.net wrote: Would it kill somebody to write a library of simple functions that would answer most beginners' simple needs, then have it blessed as canonical? I'd write it myself, but I still don't know enough! If every beginner has to painfully figure these things out, most beginners are going to bail--which means that Clojure remains a niche language, unknown to a lot of people who could have brought their considerable creativity to the Clojure community. We are patiently waiting for *you* to do / start / lead this. If it's a real paint point for enough people - folks will happily contribute, you don't need to know / think of everything. I've found this to be case with ClojureScript, core.match, and core.logic. I'm working on ClojureScript support for core.match and core.logic and I happily welcome any patches that will make them work on the CLR. It's tiresome to hear people complain about something they do not contribute anything towards. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: noob question/request for guidance vis a vis connecting to SQL Server
Hi! Long way! To start with I would head for using webnoir+korma for starters. I think its a better lighted up road for people to start with (eventually you could dump the jvm after a while and run everything in node.js or something but for now thats a risky road for someone new to the language IMO.) Start with installing lein, then go to webnoir for getting a webserver up. Then add korma and connect it to sql. You can use clojurescript for the cool website but to run the backend in cljs seems a bit overwhelming for a start. Does that sound reasonable to start with? Once you have lein, noir is very easy. Swank + slime is geat when you want to test the backend/sql without the website first. Just ask if you have further questions, we try to clean the way of mines as fast as we can with documentation and everything. /Linus Den 17 feb 2012 15:06 skrev VaedaStrike supercriticalfl...@gmail.com: I'm really new to programmIng. Started in relational database design and got myself a SQLServer based database for which I want to create a web based clojure/clojurescript/clojurescriptone based front end. I started learning programming (oop) with vb.net and vs and got to realize that to get to where I want to be I have to be able to develop faster and better than vb could let me so I finally figured out how to get started with Emacs and am now stumbling through clojurescriptone via the emac repl (getting to this point has been a LONG journey for me). So where I'm at presently is trying to build forms etc in clojurescriptone that can be the front end for my database, using stored procedures. I have virtually no idea as to how to start this. Where in clojurescriptone would I place make the connection? I've been told that it would have something to do with remoting but I've never done anything like that and can't seem to find info via search engines. I've looked up what I can find in the wikibook about connecting to SQL Server http://en.wikibooks.org/wiki/Clojure_Programming/Examples/JDBC_Examples#Microsoft_SQL_Server but aside from downloading the jdbc I'm lost In the wikibooks article it states that the solution depends on the Clojure Contrib library org.clojure/java.jdbc but I, in my great nascent noobness, haven't the foggiest idea of how to, or where to, state the dependency in the clojurescript app (does it entail downloading files from org.clojure/java.jdbc??? If so where/how do I place them?). I'd also like to be able to test calls against my stored procedures in the/a repl (clojurescriptone or otherwise) but I just have no clue where to begin. Can any patient soul either tell me OR point me in the best dirrection to figire this 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 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: Lack in the documentation
Regarding don't want to learn Java. I understand fully, but can I suggest downloading a major java-IDE and make some small and simple java-katas in it? I would suggest IntelliJ IDEAs Community Edition (there are other, ofc) and then going through some examples from the surprisingly well written Java tutorials on Oracles site: http://docs.oracle.com/javase/tutorial/ Understanding how java works is the key to understand a lot of the sometimes apparently quirky java-interop stuff and you probably wont die in the meantime, I promise. There's also a few strange things going on in readers, streams and exceptions that is really good to have a clue of. This could be four or five very well spent hours on your way to master Clojure. Stop when programs goes into a 100 rows or so, those programs can usually be done much much quicker in Clojure. Best regards, Linus 2012/2/16 Sean Corfield seancorfi...@gmail.com I don't think your tone is very helpful Armando. It's perfectly reasonable to ask for specific examples - so that there are actionable tasks we as a group can take on, rather than just some vague the documentation is too Java-centric complaint. When I read the OP, I was not sure what he was really complaining about or asking for. I don't agree with the assertion that all the documentation assumes Java knowledge - and clearly a lot of non-Java programmers have managed to pick up Clojure just fine. Even tho' I have Java experience, I had no experience with Maven so the whole library dependency thing was new to me - but it didn't seem Java-centric. I had experienced the classpath aspect of Java but, frankly, Leiningen completely hides that. The only required Java experience, as far as I can see, is if you _choose_ to use Java libraries within Clojure - and even that is just a matter of reading a library's documentation and applying the interop rules... Your snide remark about a build tool is not appropriate given how popular Leiningen is and how much work Phil and many others have put into it. Sean On Wed, Feb 15, 2012 at 7:38 PM, Armando Blancas abm221...@gmail.com wrote: Can you provide some more specific examples of what's missing? Surely you're joking, Mr. Hagelberg. I don't know any Java and was able to manage pretty well. This is no time for modesty, lest the OP might feel his troubles aren't even valid. Perhaps better to say that a rudimentary grasp of Java (language, libraries, tools) can go a long way. Then one day... we'll get a killer build tool or something. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Templating, how to?
I want to generate rules with constant and/or functions producing parts of the rules: (defn rulemaker [] (str SCOPE global-constant ; (some-global-function) ;)) which could be called with (with-super-closure model-in-file-reference (rulemaker)) Is there a way to make some temporary global constants that could be reached from a function without passing it the this state or closure explicitly? What's the simpler way? Should I simply make a search-replace table which I prepare and run all the templates through or is there another way? I would love to be able not to pass around a state, like (defn rulemaker [z] (str SCOPE (some-generator-function z))) since that's a bit error-prone and verbose. Is this one of few occasions for a macro or should I somehow create a namespace or something explicitly for this code-generation? All magic allowed, since it's a very restricted domain that rather should be as convenient as possible to use. /Linus -- 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: Need help to translate a simple java program into Clojure program
2012/1/9 Nicolas Garcin nicolas.etienne.gar...@gmail.com Hello, I'm new to functional programming and Clojure and I'm trying to translate a simple java program into Clojure. My program must build from 2 input lists (stored in a vector) 2 output lists (also stored in a vector) which have same number of elements as input lists for both output lists. The elements' values of the output lists will be the result of a very simple arithmetical calculation based on input lists' elements. Since my java program iterates on lists, I wanted to use a 'higher order function' in the Clojure version of the program (like the 'map' function). But I didn't manage to write the equivalent program in Clojure. Could someone please help me? Below is the java program that I'd like to translate. Thanks a lot, Regards, Nicolas I've started sketchy below, but the matching function would really be happier if it had one or two comments. Usually it's a lot easier to implement clojure code from algoritmic ideas rather than existing java code since they are quite different. For instance I would change the object to a hash map {:name :value} and NOT change the input vector, the actions taken would actually return a new nested vector. I guess you could make a much better algoritm in the matching function using reduce or some other higher order function. Also, null is nil which is mostly the same but less prone to break, which could probably remove a few of the if-statements as well. Sorry for sketchy answer, but hopefully it's a start. The solutions to the problem would be quite different than the java version, and the clojure version will be a somewhat more compact. Rich Hickey have made some really really good introductions to Clojure where he touches many of concepts you could have good use of in the code below named Clojure for Java Programmes pt 1 and 2 http://blip.tv/clojure/clojure-for-java-programmers-1-of-2-989128 http://blip.tv/clojure/clojure-for-java-programmers-2-of-2-989262 Hopefully this will get you started! /Linus // first file (these are the elements of my lists): public class Pos { public String name; public int value; public Pos(String newName, int newValue) { name = newName; value = newValue; } @Override public String toString() { return Name: + name + , Value: + value + \n; } } A pos could be described as {:name IBM :value 150}. (defn pos-str [pos] (str Name: (:name pos) , Value: (:value pos) \n)) // second file that contains the method I'd like to translate using a higher order function (method called match): import java.util.ArrayList; import java.util.List; import java.util.Vector; public class Matching { public static void main(String[] args) throws Exception { ListPos options = new ArrayListPos(5); Pos option1 = new Pos(IBM, -50); Pos option2 = new Pos(ACCOR, -30); Pos option3 = new Pos(IBM, -10); Pos option4 = new Pos(APPLE, -20); Pos option5 = new Pos(AIRFRANCE, -20); options.add(option1); options.add(option2); options.add(option3); options.add(option4); options.add(option5); ListPos actions = new ArrayListPos(4); Pos action1 = new Pos(IBM, 55); Pos action2 = new Pos(ACCOR, 40); Pos action3 = new Pos(AIRFRANCE, 10); Pos action4 = new Pos(LUFTHANSA, 100); actions.add(action1); actions.add(action2); actions.add(action3); actions.add(action4); VectorListPos input = new VectorListPos(2); input.set(0, options); input.set(1, actions); (ns matching.thing) (def options [{:name IBM :value -50} {...} ...]) (def actions [{:name IBM :value 55} {...} ...]) (def input [options actions]) ;;or just write everything in one declaration System.out.println(Options: + options); System.out.println(Actions: + actions); VectorListPos res = Matching.match(input); System.out.println(Options: + res.get(0)); System.out.println(Actions: + res.get(1)); (println Options: options) ... (println Matched: (match options)) ;;since you have immutability you get a new vector, no changing of the old above, so you have to catch the result somehow } ;;The code below is a can of worms for someone who don't know what the algoritm is supposed to do public static VectorListPos match(VectorListPos optionsAndActions) { ;;if null return null (would probably not be needed to catch when using nil) if (optionsAndActions == null) { return optionsAndActions; } ;;if one or zero elements they're already matched, return it as a whole if (optionsAndActions.size() 2) { return optionsAndActions; } ;;this code is quite opaque to me: VectorListPos modifiedOptionsAndActions = new VectorListPos(2); if (optionsAndActions.get(1) == null)
Re: Any char-based Java file I/O with arbitrary seek?
How about a memory mapped file? Not lazy at all, but could be quick, given that you have enough memory. http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/MappedByteBuffer.html There can be times where a database is too low performant or clumsy for quick searching in a large utf-8 file, but some kind of indexing seems necessary if exact char position is needed quickly, skiplists or frames where one is told how many and how long escapechars was used since the beginning with some heuristic search would be possible solutions. Maybe there are more efficient data structures (bzip?) when one need fast access during ram memory constraints and have information with low entrophy (accesslogs). /Linus 2012/1/5 Steve Miner stevemi...@gmail.com On Jan 5, 2012, at 5:07 PM, Andy Fingerhut wrote: I realize that with variable-length multi-byte character encodings like UTF-8, it would be a bad idea to seek to a random byte position and start trying to decode a UTF-8 character starting at that byte position. I'm thinking of cases where you have an index of byte positions of interest you want to jump to in the future that are known to be the first byte of a character in the appropriate encoding. I also realize that one must be very cautious in writing to the middle of such a file, since byte lengths of strings are variable. I can't help too much, but the comment about UTF-8 rang a bell. It's actually not that hard to find a valid character by jumping to a random position. You just need to be able to back up a few bytes. http://en.wikipedia.org/wiki/UTF-8 * All continuation bytes (byte nos. 2-6 in the table above) have 10 as their two most-significant bits (bits 7-6); in contrast, the first byte never has 10 as its two most-significant bits. As a result, it is immediately obvious whether any given byte anywhere in a (valid) UTF-8 stream represents the first byte of a byte sequence corresponding to a single character, or a continuation byte of such a byte sequence. * As a consequence of no. 3 above, starting with any arbitrary byte anywhere in a (valid) UTF-8 stream, it is necessary to back up by only at most five bytes in order to get to the beginning of the byte sequence corresponding to a single character (three bytes in actual UTF-8 as explained in the next section). If it is not possible to back up, or a byte is missing because of e.g. a communication failure, one single character can be discarded, and the next character be correctly read. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Use You a Spaced Repetition System for Great Good!
Hi Joshua! I've been using Anki for repeating unsorted Clojure-stuff in about a year. It's good for knowing all the instructions and source code, but the key to success is always to solve more or less complicated problems (4clojure.orgetc). On the practical side I have a lot left to learn, also since I'm not very skilled in algoritms in other languages [because the have so much boilerplate and therefore is boring to program in]. /Linus 2012/1/3 Joshua jos...@milehighcode.com Anybody else using a spaced repetition system (SRS) for Clojure learning? What about just general programming? How did it work out for you? I've just started using Anki and I uploaded a Clojure Sequence API shared deck. I'm hoping others might be interested in adding other Clojure related material to Anki. If you aren't familiar with the SRS concept, I wrote a short blog entry about it and how to import the Sequence API deck: http://blog.milehighcode.com/2012/01/use-you-spaced-repetition-system-for.html -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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
Mechanism for escaping of predefined entities missing in clojure.xml
Hi! I have been in the wondrous world of XML-parsing last week and I've found a missing mechanism in clojure.xml - the escaping the predefined entities: Example: (use 'clojure.xml) (def xmlelem (parse (new org.xml.sax.InputSource (new java.io.StringReader tag greet=\Clojureamp;co\/ ;; parsing string tag greet=Clojureamp;co/ xmlelem ;; looks like this: {:tag :tag, :attrs {:greet Clojureco}, :content nil} (emit-element xmlelem) tag greet='Clojureco'/ This output is not standard compliant and is not even re-parseable with the code above. The problem is the sole ampersand (). Wikipedia [1] says There are five *predefined entities*: - lt; represents - gt; represents - amp; represents - apos; represents ' - quot; represents Would it be a good idea to make a small search-and-replace function to call from emit-element and escape these chars in the string when nescessary? Today there is no such mechanism in clojure.xml, but it would be simple to implement. The singlequote is easily changed in the emit-element function if needed - is there anyone interested in options for this? The escaper for predefined entities would be of general interest, I think. Should I put this in Jira? Should I try to make a patch and send to someone? This would be my first commit so I would be most grateful if someone just gave an acknowledge of any kind so I'm not entirely off track. [1] http://en.wikipedia.org/wiki/Xml /Linus -- 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: Literate programming/TDD with Leiningen + midje + marginalia
Yes, it does. I had problems with some midje-facts crashing the rendering in marginalia, but was able to just give the files as consecutive arguments as a work around. lein marg src/app/core.clj src/app/another/file.clj wildcards works fine as well. This problem with midje-facts being incompatible with marginalia needs further investigation from my side though. btw - is there a possibility to hide comments in emacs/slime? Midje-mode have this great feature of collapsing fact-clausules for reducing clutter. Would love to have the same thing when I have pages and pages of comments. /Linus 2011/12/23 Alex Baranosky alexander.barano...@gmail.com Hi Adam, It seems like making it so that Marginalia allows you to specify which directories to use would be the ideal case, instead of feeling a need to lump all your tests in the src directory. I wonder if Marginalia already supports this? Alex On Wed, Dec 21, 2011 at 11:25 PM, Adam Getchell adam.getch...@gmail.comwrote: Thanks for all the replies! I'm trying midje first (keeping expectations in mind for later) as it seems to support writing tests and then code (i.e. top down testing). (This video https://github.com/marick/Midje/wiki/Top-down-testing was useful, thanks for making it!) In generating documentation with marginalia (particularly useful for when I figure out how to get LaTeX formulae in there), I note that marginalia doesn't pickup files in /test but only /src. So it seems that I need to embed tests directly in my code in order to self-document. Is this a huge no-no, better ways to accomplish this? P.S. (Newbie) what's the difference between (:use [clojure.test]) and (:use midje.sweet)? Both seem to work. -- Invincibility is in oneself, vulnerability in the opponent. -- Sun Tzu -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ranged types
Hi Marek! I would def a protocol CustomArithmetics and include the the nescessary methods for arithmetics, and then a deftype for each custom arithmetics. It would be possible to extend the protocol for Longs and Integers as well, if needed. If you would like to use the normal operator-names +,- etc then make sure that exclude those in the ns-declaration where I would use refer :exclude ... and then redefine them as above. Oh sorry for the handwaving, but maybe this at least could get you in the right direction. /Linus Den 21 dec 2011 06:56 skrev Marek Kubica ma...@xivilization.net: Hi, I am idly thinging on how to create types with special restraints on them, like being only in the range 1-1000 or only even numbers etc and all normal operations like + and - still being valid. Anyone has an idea how to implement that? In Python I'd subclass the number type and implement all oparators, but how would one do this in Clojure? regards, Marek -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Ranged types
2011/12/21 Marek Kubica ma...@xivilization.net Hi, Thanks for your mail, glad to get ideas so fast :) On Wed, 21 Dec 2011 09:51:04 +0100 Linus Ericsson oscarlinuserics...@gmail.com wrote: I would def a protocol CustomArithmetics and include the the nescessary methods for arithmetics, and then a deftype for each custom arithmetics. It would be possible to extend the protocol for Longs and Integers as well, if needed. If you would like to use the normal operator-names +,- etc then make sure that exclude those in the ns-declaration where I would use refer :exclude ... and then redefine them as above. So I'd have to exclude them, include them by some other name, and use them for the normal number types, so I don't break + for normal numbers, right? But that also means, that any consumer of my ranged numbers, would be forced to use my own version of +, - etc. Right? I'm exploring what is possible with Clojure, this is not anything that I actually need for something. Now I'm mostly speculating, but the reason one doesn't have the nice Protocols around +,- etc already is because of efficiency. However, it wouldn't be to hard to add a method for normal integers to call for the ordinary clojure.core/+ in this particular case (even though they would have quite sever performance losses). For the customized algebra it would be easy to throw exception like odd result when one made an unfortunate division on a number 4n+2 etc. The main difference between Clojure and usual OOP seems to be that the functions is not too connected to the data structures, which IMHO makes the applications simpler to manage in some common use cases. /Linus -- 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: core.memoize v0.5.1
Wov! There have been some great and very educational blog posts on how to improve the memoization functionality for various use-cases but this makes it even more effort free to use the techniques. This is brilliant! Thank you! /Linus 2011/12/14 Fogus mefo...@gmail.com core.memoize v0.5.1 Release Notes = core.memoize is a new Clojure contrib library providing the following features: * An underlying `PluggableMemoization` protocol that allows the use of customizable and swappable memoization caches that adhere to the synchronous `CacheProtocol` found in [core.cache](http://github.com/ clojure/core.cache) * Memoization builders for implementations of common caching strategies, including: - First-in-first-out (`memo-fifo`) - Least-recently-used (`memo-lru`) - Least-used (`memo-lu`) - Time-to-live (`memo-ttl`) - Naive cache (`memo`) that duplicates the functionality of Clojure's `memoize` function * Functions for manipulating the memoization cache of `core.memoize` backed functions core.memoize is based on a library named Unk, found at http:// github.com/fogus/unk that is planned for deprecation. * [Source code](https://github.com/clojure/core.memoize) * [Ticket system](http://dev.clojure.org/jira/browse/CMEMOIZE) Changes from Unk --- The v0.5.1 version of core.memoize is based almost wholly on the final version of Unk, with the following changes: * All cache factory functions have been moved to core.cache * The `SoftCache` backed implementation was buggy and removed for now Plans - The following capabilities are under design, development, or consideration for future versions of core.memoize: * LIRS backed memoization * A [defn-memo](https://github.com/richhickey/clojure-contrib/blob/ 1c805bd0e515ea57028721ea54e6db4b0c791e20/src/main/clojure/clojure/ contrib/def.clj#L143) macro * A [MapMaker](http://google-collections.googlecode.com/svn/trunk/ javadoc/com/google/common/collect/MapMaker.html) style ctor interface * Reimplementation of a cache based on soft references * test.generative usage * Deprecation of Unk * Documentation and examples More planning is needed around capabilities not listed nor thought of. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: xml-zip
Thank you Tom! Exactly was I was looking for! I will TRY to add some documentation to clojuredocs.org just so people won't be that afraid, this xml-functionality is a very sane way of doing it, it's just takes a while to get used to it (I'll check that it's refered to the correct namespace as well). I guess next step would be making a clojar avaliable, but I have no clue on how to do that yet. /Linus 2011/12/13 Tom Faulhaber tomfaulha...@gmail.com Hi Linus, Zippers and their associated helpers are woefully undocumented, so I'm not surprised you fell into the swamp. I think that the help you're looking for can be found in the clojure.data contrib project (see https://github.com/clojure/data.zip for the source and http://clojure.github.com/data.zip for the autodoc). Using that, the xpathy thing you're looking for is something like this: (ns play.xml-example (:require [clojure.zip :as zip] [clojure.data.zip :as zf] [clojure.xml :as xml]) (:use clojure.data.zip.xml)) (def mz (zip/xml-zip (xml/parse dataabove.xml))) (defn get-all-dimensions [] (doseq [id (xml- mz zf/descendants (attr= :id 2) zf/children :e (attr :id))] (println (apply str id Note that I had to make a couple of fixes to the above XML to make it right. I hope that's useful! Tom On Dec 12, 7:06 am, Linus Ericsson oscarlinuserics...@gmail.com wrote: Hello! What's the clever way to read the E-tags thisone and andthis in the XML-file below given I don't know their id on beforehand? a bbla bla/b bbla bla/b c id=wanted d id=1 e id=notthisone//d d id=2 e id=thisone/ e id=andthis//d d id=3 e id=not-intresting/d /a My solution so far would be something like (def mz (zip/xml-zip (xml/parse dataabove.xml))) (defn get-all-dimensions [] (filter #(and (= 2 (:id %)) (= :e (:tag %))) (zip/children mz but I'm looking for some descending solution (- mz (zip/down a) (zip/down c :where (= :id wanted)) (zip/down d :where (= :id 2)) zip/children) (an xpath-like solution would most awesome) According to it's own page Enlive is not very good for xml and I cannot figure out the way to dynamically walk with zippers (like go into the tag :d with id=...). Would Enlive work for my needs here? When I got this sorted out I will try my best to add some examples on clojuredocs.org, zippers is good but I don't know if it's for everything. /Linus -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
xml-zip
Hello! What's the clever way to read the E-tags thisone and andthis in the XML-file below given I don't know their id on beforehand? a bbla bla/b bbla bla/b c id=wanted d id=1 e id=notthisone//d d id=2 e id=thisone/ e id=andthis//d d id=3 e id=not-intresting/d /a My solution so far would be something like (def mz (zip/xml-zip (xml/parse dataabove.xml))) (defn get-all-dimensions [] (filter #(and (= 2 (:id %)) (= :e (:tag %))) (zip/children mz but I'm looking for some descending solution (- mz (zip/down a) (zip/down c :where (= :id wanted)) (zip/down d :where (= :id 2)) zip/children) (an xpath-like solution would most awesome) According to it's own page Enlive is not very good for xml and I cannot figure out the way to dynamically walk with zippers (like go into the tag :d with id=...). Would Enlive work for my needs here? When I got this sorted out I will try my best to add some examples on clojuredocs.org, zippers is good but I don't know if it's for everything. /Linus -- 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: Trying to use CDT on 1.3.0
Swank is not built in by default. Have you added a :dev-dependencies [[swank-clojure 1.4.0-SNAPSHOT]] map entry to project.clj and runned lein deps and the lein swank? (1.4.0-SNAPSHOT worked for me a few days ago, maybe 1.4.0 is out sooner or later) /Linus 2011/12/9 Richard Tiger Melville melvilleti...@gmail.com New to lein, coming from SBCL where slime setup is effortless! Any ideas why this fundamental step is failing? bash-4.1$ lein version Leiningen 1.6.1 on Java 1.6.0_25 Java HotSpot(TM) Client VM bash-4.1$ lein swank That's not a task. Use lein help to list all tasks. bash-4.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 -- 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: Unexpected behaviour in unchecked-multiply when using vars as arguments
2011/12/5 Stuart Sierra the.stuart.sie...@gmail.com (side note: what is different between Long/MAX_VALUE and the function call (Long/MAX_VALUE)? None. Both are syntax sugar for (. Long MAX_VALUE) It seems like unchecked-multiply doesn't like vars, but thats surprising. What am I doing wrong here? unchecked-multiply only does unchecked arithmetic when the arguments are primitive. Vars cannot have primitive values, they must be boxed as java.lang.Long. So it reverts to normal Clojure arithmetic. The unchecked-* functions are intended as a performance optimization when doing operations with primitives. OK, then the problem seems to be to refer to primitives with symbols with unchecked-* functions. How do I do that? The loop where high performance is required is hash = -3750763034362895579 for each byte b in array-of-bytes-to-be-hashed do : hash = hash * 1099511628211 (without caring about overflowing) hash = hash ^ byte return hash and I really cannot see how to do this without using something that hold values somehow, but how do I bypass the numeric stack in clojure? I have tried with the following approach (just for the first step): fnv (def hash (Long. -3750763034362895579)) #'fnv/hash fnv (def hash2 (Long. (unchecked-multiply hash 1099511628211))) ; Evaluation aborted. (because of integer overflow) How should I do to get it working correctly? There simply must be a way to store primitives, but I'm apparently have gotten something wrong here. (the hash in question is the quite quick FNV-hash, which is in public domain, nice and everything) /Linus -- 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: Unexpected behaviour in unchecked-multiply when using vars as arguments
David and Stu to the rescue. Of course that's the way to do it. Thank you both, /Linus 2011/12/5 David Nolen dnolen.li...@gmail.com You can't store primitives in vars. But you can cast their contents to primitives with (long ...) (int ...) etc David On Mon, Dec 5, 2011 at 12:16 PM, Linus Ericsson oscarlinuserics...@gmail.com wrote: 2011/12/5 Stuart Sierra the.stuart.sie...@gmail.com (side note: what is different between Long/MAX_VALUE and the function call (Long/MAX_VALUE)? None. Both are syntax sugar for (. Long MAX_VALUE) It seems like unchecked-multiply doesn't like vars, but thats surprising. What am I doing wrong here? unchecked-multiply only does unchecked arithmetic when the arguments are primitive. Vars cannot have primitive values, they must be boxed as java.lang.Long. So it reverts to normal Clojure arithmetic. The unchecked-* functions are intended as a performance optimization when doing operations with primitives. OK, then the problem seems to be to refer to primitives with symbols with unchecked-* functions. How do I do that? The loop where high performance is required is hash = -3750763034362895579 for each byte b in array-of-bytes-to-be-hashed do : hash = hash * 1099511628211 (without caring about overflowing) hash = hash ^ byte return hash and I really cannot see how to do this without using something that hold values somehow, but how do I bypass the numeric stack in clojure? I have tried with the following approach (just for the first step): fnv (def hash (Long. -3750763034362895579)) #'fnv/hash fnv (def hash2 (Long. (unchecked-multiply hash 1099511628211))) ; Evaluation aborted. (because of integer overflow) How should I do to get it working correctly? There simply must be a way to store primitives, but I'm apparently have gotten something wrong here. (the hash in question is the quite quick FNV-hash, which is in public domain, nice and everything) /Linus -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Unexpected behaviour in unchecked-multiply when using vars as arguments
Thats a great feature as well! It is very good not to clutter the code with magic constants, but to be able to name them in a sane way. Thank you all again, /Linus Den 5 dec 2011 18:38 skrev David Powell djpow...@djpowell.net: On Mon, Dec 5, 2011 at 5:29 PM, Linus Ericsson oscarlinuserics...@gmail.com wrote: David and Stu to the rescue. Of course that's the way to do it. Not sure if this is what you want, but Clojure 1.3 introduced ^:const. This lets you store a primitive constant value: (def ^:const hash -3750763034362895579) Then you can use hash anywhere as if you'd inlined the value. hash will be stored as a primitive, and will work with unchecked-multiply. -- Dave -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Unexpected behaviour in unchecked-multiply when using vars as arguments
I try to do multiplication where overflowing is expected and the result should be handled modulo ie the multiplication results in a truncated long. user (unchecked-multiply (Long/MAX_VALUE) (Long/MAX_VALUE)) 1 ;;is ok and expected also classificator.fnvhash (unchecked-multiply Long/MAX_VALUE Long/MAX_VALUE) 1 (side note: what is different between Long/MAX_VALUE and the function call (Long/MAX_VALUE)?) BUT: user (def max1 Long/MAX_VALUE) #'user/max1 user (def max2 Long/MAX_VALUE) #'user/max2 user (unchecked-multiply max1 max2) results in a integer overflow. I have tried to type hinting and what not. It seems like unchecked-multiply doesn't like vars, but thats surprising. What am I doing wrong here? I'm using Clojure 1.3.0. /Linus -- 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 would you model this data?
I don't know what data the vectors depict, but if they are like floating point numbers and you want to do distances etc (like geodata), and need high performance on various strange matchings you should consider something like R-trees http://en.wikipedia.org/wiki/R-tree (or check if there is some GIS-related stuff i clojure using this or similar algoritms already) Or if you have other needs, maybe create two datastructures in parallell (maybe they could sorted or some other kind of indexing good for your needs) and make lookups on either one depending on the question. If time is more important than memory it could be a good idea to bloat the structure a little. /Linus 2011/12/3 Stephen Compall stephen.comp...@gmail.com On Sat, 2011-12-03 at 13:14 -0800, Base wrote: I need to identify entries in this map where *either* the first or the second value in the key matches a predicate. Unfortunately, you can only have one notion of key equality per map, so you need to either introduce some linear-search component (as your nested-maps example does), or add another map. One or the other is faster depending on how many values you have. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Avout: Distributed State in Clojure
In Clojure in Action (still in MEAP i think) there's a chapter about using (Erlang/OTP-based) RabbitMQ message queue server for making Clojure scalable in a Hadoopish map-reduce-way. Avout seems to solve many of the problems that easily could occur in such an approach by not needing a centralized reduce server for every calculation. Another similar way of solving problems of concurrency seems to be Operational Transformation, which is used in many Google products. http://en.wikipedia.org/wiki/Operational_transformation Otherwise +1 for Erlang. /Linus On 11/30/11 10:53 AM, AndyK wrote: If you're willing to dig into another language, 'Erlang and OTP in Action' gives a great overview of Erlang and the distributed principles underlying that language. Though different from the approach of distributed STM, the concepts of distributed applications are baked into the core of Erlang. On Nov 30, 2:03 am, Harrison Maseko lis...@gmail.com wrote: Could anyone please recommend a good introductory book about distributed application development? The release of Avout has gotten me interested in the subject. Thanks, Harrison. On Nov 29, 7:38 pm, liebke lie...@gmail.com wrote: Today we are releasing Avout, which brings Clojure's in-memory model of state to distributed application development by providing a distributed implementation of Clojure's Multiversion Concurrency Control (MVCC) STM along with distributable, durable, and extendable versions of Clojure's Atom and Ref concurrency primitives. Here's the post announcing the project:http://clojure.com/blog/2011/11/29/avout.html And here's the project's website:http://avout.io David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Proper parallelism?
There's an approach using agents described here: http://travis-whitton.blogspot.com/2009/07/network-sweeping-with-clojure.html It's a bit old, so somethings in the example could be a bit outdated, but the idea may help you forward, /Linus 2011/11/22 AndyK andy.kri...@gmail.com I have been using Clojure to write tests on RESTful applications. Since the requests are independent, parallelizing would speed things along. What is the best approach? Using pmap is the obvious first step. Afaik, pmap only creates a small pool of threads. Is there more to gain by going to the Java API's threading classes (like ExecutorService, or building a pool of threads triggered by a CountDownLatch)? What experience have folks had with different approaches? thx -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: All subsets of a vector
(map #(vec (take (inc %) a1)) (range (count a1))) does it the lovely map. /Linus 2011/11/9 Shoeb Bhinderwala shoeb.bhinderw...@gmail.com Is there a more elegant/idomatic way to achieve the following result: user= a1 [a b c d] user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1) (repeat a1))) ([a] [a b] [a b c] [a b c d]) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Nested Syntax Quote, Quote and unquote example
No one can be told what the matrix is. Well, the best way to understand the macros is to try it out yourself. John Lawrence Aspden published some really helpful tutorials om macros, and a kata - try it! Links in the end. There are some other code examples around, also look in the source-code of clojure core and various clojure contrib libraries for a lot of examples, some of which you have to contemplate and come back to later. They have some macros in the code. Also beware that you most often don't want to use macros in the first place, since you can solve most problems with the incredible powerful functions as well. Last but not least I would recommend getting some good books on Clojure, I started with Programming Clojure of Stuart Halloway and it was really helpful for me. Most problems can be expressed as a sequences of key-value-maps to which you apply map and reduce (or nowadays protocols for more speed). Be prepared to spend some time getting your head around the transition to functional, lazy, immutable code with macro-programming, it will be worth it. You will still have good use of you java-knowledge, but will probably structure your programs differently. I also had great help of the beginning of Paul Grahams Practical Common Lisp avail free at: http://pragprog.com/book/shcloj/programming-clojure Macro kata: http://www.learningclojure.com/2010/11/syntax-quote-kata-for-confused.html Macro tutorial: http://www.learningclojure.com/2010/09/clojure-macro-tutorial-part-i-getting.html Clojure source code repositories: https://github.com/clojure/ Programming Clojure: http://pragprog.com/book/shcloj/programming-clojure /Linus 2011/10/31 vikbehal vikbe...@gmail.com Can anyone give me some basic example which contained nested quotes and unquotes? with explanation at each step! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Losing your head with side effects
Range is lazy. First you define a range, which is just a promise that the variable will be rendering a seq with 10M when asked for the elements. When you count the sequence you realize it and it takes up much space. When you let go if it it's of course GCed. The problem is that you hold on to the head (first element) of the sequence. If you do (count (range 1000)) clojure will go through it lazily and throw away elements as they are counted, hence much less memory usage. Let go of the head! :) /Linus 2011/10/25 Mike cki...@gmail.com It appears I'm not understanding how something works in the REPL (or maybe deeper). For instance: (def big (range 1000)) ; memory is small now (count big) = 1000 ; memory is huge now (System/gc) ; memory is still huge now (def big nil) (System/gc) ; memory is small again So somehow when count realizes big, I'm guessing it gets memoized and stuck in some sort of cache attached to the var big. If I: (do (System/gc) (count (range 1000)) (System/gc)) ; memory is small before and after I think the version I wrote originally is fine; I just wasn't testing it properly. Sorry to bother folks! Mike -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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: Swarming experiment at Conj?
Would it be possible to store the original defn s-expression source code in metadata added to the java byte-code function? It would be highly inefficient (and most of the time meaningless) for autogenerated functions, but quite a small overhead for the few locs a developer spits out during a hack-togheter-sessions - which btw sounds marvelous! /Linus 2011/9/21 Colin Yates colin.ya...@gmail.com Have you considered opening it to remote users? I wouldn't be able to contribute anything, but I would love to watch... On 21 September 2011 14:07, Brian Marick mar...@exampler.com wrote: On Sep 9, 2011, at 11:55 AM, Christopher Redinger wrote: Thursday evening we'll have the time, space and power to do this post-supper. A round table may be hard to come by, but I'll see what we can do. Keep me in the loop on what else you'll need. Thanks Chris. Not enough people (2) said they were interested for this to go forward. - Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile www.exampler.com, www.twitter.com/marick -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Example of a real-world ClojureScript web application
You get Selenium running by using the clj-webdriver [1], thanks to Semperos for that one! [1] https://github.com/semperos/clj-webdriver /Linus 2011/8/11 Filip de Waard f...@vix.io On Thu, Aug 11, 2011 at 4:03 AM, Timothy Washington twash...@gmail.comwrote: Good on you. I've been looking to find a reliable way to have Javascript unit testing run in a v8 (or any JS) shell. I've tried Jasmine and am now trying Google Closure's unit testing framework, but have so far come up short. Have you come up with anything that works? For now, i'm just having the tests run in the browser. But trying with Nodejs is the next step. I don't have it at hand, right now, because I'm not at home, but I think the Google Closure book suggests using Selenium to automatically run the tests. Alternatively, using script/repljs might work. Do you have the tests running a browser window already? If so, I'd love to have a look at how you did that, because I haven't gotten that far yet myself. I'm going to give this another shot soon, because I've learned quite a lot about ClojureScript since I last tried to get testing to work. -fmw Keep it up Tim On Tue, Aug 9, 2011 at 8:53 PM, Filip de Waard f...@vix.io wrote: I'm working on Vix, which is a document repository and content management system written in Clojure with a CouchDB backend. After the announcement on July 23 I immediately got excited about ClojureScript and the Google Closure toolkit, so I dropped the existing Backbone.js and jQuery code and rewrote all client-side functionality in ClojureScript. Despite (or maybe because of) the fact that the functionality is still very minimal I wanted to share this code as an example of ClojureScript in the wild. Be warned that: - this is not perfect, clean example code written by a ClojureScript expert (in several places I've used hacks and shortcuts to make things work), but hopefully at least a starting point for others working on similar functionality, - you should read the installation instructions carefully (e.g. there is still a hardcoded path in src/vix/db.clj at the time of this writing, which I hope to correct in the near future), - I'm actively developing this application, so things will change and new features will be added frequently, - the application isn't done yet, although it has a working prototype. I'm concentrating on adding features that will allow users to manage feeds (currently blog is the default feed), add media files like images and to manage users. I had trouble getting unit testing to work properly for the ClojureScript part of the application, so I grudgingly wrote it using a non-TDD approach. Retrofitting unit tests into the ClojureScript part is a priority. The user interface is also lacking some bells and whistles that I had previously implemented in jQuery, but still have to rewrite using Google Closure. Eventually, I want to turn Vix into a commercial SaaS offering, with a focus on performance (e.g. Amazon CloudFront support), scalability and webshop functionality. The application itself, however, will be perpetually available as open source software, because I'm committed to sharing my code. Here is the GitHub page for Vix: https://github.com/fmw/vix This is not a launch post for Vix, because we're not ready for supporting typical end-users yet, but I hope that the code will be useful to other developers in the meantime. I'm also happy to receive any feedback (positive as well as negative) and answer questions. You can reply to this post, but if you prefer to contact me privately you can also find my contact information on Github (https://github.com/ fmw). Sincerely, F.M. (Filip) de Waard / fmw P.S. I'd like to thank the ClojureScript developers. There are surprisingly few glitches considering that the project has only just been released. The language is incredibly well designed and a pleasure to use. Thanks for making client-side development more enjoyable! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to
Re: Tree vaadin?
Maybe (map #(.addItem tree (.toString (first %))) planets) where #(.addItem tree (.toString (first %))) should be replaced with the correct java interop for inserting into the tree, and the % becomes one and one of the items in the planets vector (that is regarded as a sequence) the argument. /Linus 2011/6/27 Antonio Recio amdx6...@gmail.com How I can translate this in clojure? for (int i=0; iplanets.length; i++) { String planet = (String) (planets[i][0]); tree.addItem(planet); -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Variable types changes over namespaces
I find this behaviour a little surprising: --foo/core.clj: (ns foo.core (:require [foo.bar :as test])) (def ark (test/a-var test/another-var)) --foo/bar.clj: (ns foo.bar) (def a-var {:animal dog}) (def another-var {animal: cat}) REPL: in the repl I get: foo.core (map class ark) = (clojure.lang.Symbol clojure.lang.Symbol) and (consequently) foo.core (:animal (first ark)) = (nil) but foo.core (class test/a-var) = clojure.lang.PersistenStructMap and I can use :animal to get dog. I guess it's java classpermissions biting, but I'd love to know why it happens. To me it's like clojure doesn't look up a symbol that resides in another namespace, but that explanation is quite weak. /Linus -- 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: Need some help with static files and ring...
This tutorial covers the subject pretty well, I assume you've already read it. http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html according to it you should use Next, include the necessary Ring middleware: (:use ring.middleware.file) (:use ring.middleware.file-info) and update the middleware stack to look like: (def app (- #'handler (wrap-file public) (wrap-file-info) (wrap-request-logging) (wrap-reload '[adder.middleware adder.core]) (wrap-bounce-favicon) (wrap-stacktrace))) I really hope that can be of help, I remeber I struggled about this myself, I don't remeber if I finally got it working. /Linus 2010/10/18 lprefonta...@softaddicts.ca Hi everyone, I have been banging my head on the walls for a few hours now and really cannot figure out the proper way to serve static files in a Compojure application deployed on Tomcat or Glassfish... Feeling pretty dumb in fact... I tried to configure the default servlet to catch up requests but I feel that I cannot escape the Ring routes so this never worked. The static files reside in the folder stylesheets at the very top of the application folder. The application path is IDEMDossierPatient. The HTML link references stylesheets/... I get the following stack trace: SEVERE: Allocate exception for servlet IDEMDossierPatient java.lang.Exception: Directory does not exist: stylesheets at ring.middleware.file$ensure_dir.invoke(file.clj:13) at ring.middleware.file$wrap_file.doInvoke(file.clj:23) at clojure.lang.RestFn.invoke(RestFn.java:426) at ring.middleware.static$wrap_static.invoke(static.clj:13) at idem.mr.clinic.webaccess.medicalrecord$eval1206.invoke(medicalrecord.clj:52) ... The routes are the following (after several attempts with the file wrapper): (defroutes app-routes (GET /patient [patient-id] (render-page Dossier médical) (render-page (load-patient-mr patient-id))) (GET /req req (str req)) (GET /file [] (doto (java.io.File. .) (.getAbsolutePath))) (GET / [] (render-page Saisie du # de patient patient-form)) (route/not-found Page inconnue) ) (wrap! app-routes :stacktrace) (wrap! app-routes (:static stylesheets [stylesheets])) Any ideas where I am going with this aside from a dead end ? Is there another way to specify the folder for static file ? Should I specify an absolute path (ugly but given where I am right now I would not care...) ? Should I move the folder elsewhere ? Blblblblblblbl... Thank you, Luc -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How often do you use REPL?
Why not? The only thing I found very practical (even though it does not yet work 100% (like autoloading the open code in the repl) for me) is the possibility to fire of longer commands and function definitions (or the like) in Slime (or vi-equivalent). The repl is a great way to debug your thoughts, but it's harder to gain the overview to build more complex programs (with more than a few rows or functions, that is). REPL ftw! /Linus 2010/9/27 Christian Guimaraes cguimaraes...@gmail.com It's a noob question... I know But in my studies I use REPL 80% of the coding time. More advanced users still uses REPL so many times? thanks. -- christian guimaraes -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Fighting with Emacs ;-)
I recognize that one. The repl haven't loaded the file your editing. My (temporary) solution is to do a (load-file the file your editing) after each edit that I want to debug, but that's a bit boring. I guess there is some kind of reload feature somewhere... /Linus 2010/9/27 psfblair psfbl...@gmail.com I found the old thread below, but unfortunately the solution isn't working for me. If I have a foo.clj file in a buffer and evaluate region on (defn foo [] (+ 1 2)) I get #'user/foo in the minibuffer. If I then evaluate region on (foo) I get 3 in the minibuffer. The slime REPL is giving me a prompt user so I'm assuming it's in the user namespace, but I can't seem to get expressions from the text buffer to evaluate in there. On Mar 28, 5:01 am, Michał Marczyk michal.marc...@gmail.com wrote: On 27 March 2010 22:25, alux alu...@googlemail.com wrote: But now I see people use the result of this evaluation in their REPL (I see this in videos, so I cant ask 'em :). This doesnt work at all for me. I get the result in the minibuffer (this thing at the very bottom) and thats it. If the form you evaluate is of the def* variety, it's going to affect the namespace it resides in and not the namespace of the REPL. Thus, if you have e.g. (ns foo) at the top of the file, yet you're working in the user namespace at the REPL, then after using C-x C-e to evaluate a function definition in your file, you'll have to say something like foo/bar to reach it from the REPL. (Or (use :reload-all 'foo), if you prefer.) If there is no namespace declaration in the file, then the expression will be evaluated in the user namespace, which means that you'll be able to use it straight away if that's your REPL's namespace. (If you say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say something like user/bar to reach your function.) Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Extending Clojure's STM with external transactions
Persistant variable handling is one of the things which I have spent much time on as a beginner and former SQL-illiterate (Among getting the swank to finally work (it's a dream!)). I have however got into databases quite a bit among the way - but it was not my main goal and it has taken some time from the real task. I have looked into clj-record, which seems to be highly usable as well, but the persistant refs-idea IMHO may feel a bit more elegant. An easy way of persistence would be highly valuable when developing web applications with compojure in :reload-mode, since it seems to lose normal persistant refs after each reload in the browser. It would be valuable in production environments as well, of course. /Linus 2010/9/2 Alyssa Kwan alyssa.c.k...@gmail.com I'll go one step further and say that we shouldn't have to call persist namespace. It should be automatic such that a change to the state of an identity is transactionally written. Let's start with refs. We can tackle the other identities later. The API is simple. Call (refp) instead of (ref) when creating a persisted ref. Passed into the call are a persistence address (file path, DB connection string, etc.) and a name that has to be unique to that persistence address. Not all refs end up being referred to by a top-level symbol in a package, and multi-process systems are hard... Ensuring uniqueness of name is up to the programmer. Upon creation, Clojure checks to see if the refp exists in the store; if so it instantiates in memory with that state, else it uses the default in the call. In a dosync block, the function runs as normal until commit time. Then Clojure acquires a transactional write lock on each refp that is alter-ed or ensure-d. It checks the value against memory. If it's the same, commit data store changes. If not, retry after refreshing memory with the current contents of the store. If the data store commit fails, retry a number of times. If the data store commit still can't proceed, roll back the whole thing. commute and refset are slightly different, but for an initial implementation, just treat commute as an alter, and ignore refset. Does this make sense? My intention is to cover the 80% case. The implementation would necessarily be chatty, since the API is chatty. That's OK for most systems. This API has the benefit of being able to be shared across Clojure instances. It's a nice bonus. A dosync block may contain symbols pointing to refp's spanning different data stores, which isn't too hard to handle. It simply requires that if this is the case, each data store must support two- phase commit or some other distributed transaction supporting protocol. For an initial implementation, I would just throw an exception. I've begun working on an implementation using BDB. What do people think? On Aug 30, 5:02 pm, nchubrich nchubr...@gmail.com wrote: I'm not aware of any, but +1 for seeing persistence handled as part of the language. A big project and a long-term one, to be sure, but could it not be considered a goal? In my student days, I was talking to a well-known Lisper (name suppressed for fear of Google indexing) about some data structures in MIT Scheme. When I asked about saving them to disk, he said in effect, You're on your ownthat's something that \should be handled, but never is. I think people are so used to this state of affairs they forget how ugly it really is. Programming languages are like Moses without Joshua: they lead your data in the wilderness, but when it comes to finding it a permanent home, you have to talk to someone else. And these someone elses (who seem to be as numberless as the sons of Abraham) each have their own habits and ways of talking. Persistence libraries always end up warping the entire codebase; I've never succeeded in keeping them at bay. Using data with Incanter is different from ClojureQL, which is different from just using contrib.sql, and all of it is different from dealing with just Clojure. (I've never even tried Clojure + Hibernate.) You might as well rewrite the program from scratch depending on what you use. Maybe other people have had better luck; but whatever luck they have, I'm sure it is a fight to keep programs abstracted from persistence. I'd like to be able to work with mere Clojure until my program is complete, and then work in a completely separate manner on how to read and write data. Or maybe there would be off-the-shelf solutions I could plug in for different needs: low latency, high read, high write, large stores, etc. On the Clojure side, you would simply call something like persist namespace, which would save the state of your current or given namespace (unless you pass it the names of variables as well, in which case it only saves those). And to read data, you would simply require or use it into your namespace: you could
Somnium.congomongo missing contribs json
I have problems loading somnium.congomongo. My Leiningen project.clj looks like this: (defproject system1 0.1.0 :description System1 :dependencies [ [org.clojure/clojure 1.2.0-master-SNAPSHOT] [org.clojure/clojure-contrib 1.2.0-SNAPSHOT] [org.clojars.kjw/mysql-connector 5.1.11] [org.clojars.liebke/congomongo 1.0.0] ] :dev-dependencies [[swank-clojure 1.2.1]]) and I'm trying to load the congomongo by (ns system1.mongo (:require [somnium.congomongo :as mongo])) which does not work. When trying it in the REPL by (ns system1.mongo) and then (use 'somnium.congomongo) I get the following error: Could not locate clojure/contrib/json/read__init.class or clojure/contrib/json/read.clj on classpath: [Thrown class java.io.FileNotFoundException] When do a (use 'clojure.contrib.json) I do however only get a nil, which, afaik is an indication that clojure finds that package. Any pointer or hints would be of much help! /Linus -- 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: Reorder a list randomly?
I'm overwhelmed by the answers, thank you all! Now back to the REPL. /Linus 2010/4/5 Per Vognsen per.vogn...@gmail.com On Mon, Apr 5, 2010 at 11:33 AM, Lee Spector lspec...@hampshire.edu wrote: Ah -- maybe that foiled my timings too. I didn't expect it to be fast -- just clear (at least to this Lisp programmer). Embrace recursion combinators! They are warm and fuzzy! Here's a gist of the final cleaned up version of my code. The code itself is only three lines; the rest consists of very general purpose utilities that I find myself using again and again. http://gist.github.com/356035 -Per -Lee On Apr 5, 2010, at 12:11 AM, Per Vognsen wrote: Wow, you're right. The partial laziness of his code was foiling my benchmark. -Per On Mon, Apr 5, 2010 at 11:05 AM, Mark Engelberg mark.engelb...@gmail.com wrote: On my system, knuth-shuffle performs several times faster than Spector's recursive functional shuffle on smallish lists, and the difference grows even more dramatic as the list grows, which is what I'd expect (since knuth-shuffle is O(n) and shuffle is O(n^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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject. -- Lee Spector, Professor of Computer Science School of Cognitive Science, Hampshire College 893 West Street, Amherst, MA 01002-3359 lspec...@hampshire.edu, http://hampshire.edu/lspector/ Phone: 413-559-5352, Fax: 413-559-5438 Check out Genetic Programming and Evolvable Machines: http://www.springer.com/10710 - http://gpemjournal.blogspot.com/ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Reorder a list randomly?
Hello Clojure! Is there any straight-forward way to randomly reorder a list? ie: (randomize-list (list 1 2 3 4)) - (3 2 1 4) Regards, Linus Ericsson -- 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 To unsubscribe, reply using remove me as the subject.