ANN: Autodoc 0.9.0 (Finally!)
A new version of Autodoc (0.9.0) is now available from clojars. This version should work with all versions of Clojure that exist in the wild and is generally more robust to weird dependency relationships than previous versions. For those who aren't familiar, Autodoc is the tool that is used to generate the API documentation for Clojure (http://clojure.github.com/ clojure) and the various contrib libraries (see index under construction at http://clojure.github.com). Leiningen integration has been broken out into a separate project, lein-autodoc (also 0.9.0), to provide better insulation between the two. Full documentation can be found at http://tomfaulhaber.github.com/autodoc. New features in this version: - Support for Clojure 1.3 - Single namespace projects will now longer have an extraneous overview page - An index.clj file is generated that contains all the documentation info for the project in Clojure readable form. - A bunch of little things I can't even remember Coming soon: full documentation for protocols, types and records. This version has not been tested on an extensive set of projects, so please do let me know if you see any problems. You can file issues at https://github.com/tomfaulhaber/autodoc or just email. I do sincerely apologize to everyone who has been inconvenienced by my long delay in getting this out. All the usual excuses apply. I hope this helps with all your Clojure work, Tom -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Storing clojure lists and maps in Redis
Hi Peter - I looked at deep-freeze but did not quite understand how to use it. I used the following to freeze my Clojure complex data structure - results (map of list of maps) and persist to redis: (redis/hmset k k (deep-freeze/freeze-to-array results)) Then I tried to retrieve and thaw it as follows: (deep-freeze/thaw-from-array (redis/hget k k)) The thaw gives me the following exception: java.lang.String cannot be cast to [B - (class java.lang.ClassCastException) What am I doing wrong? ThanksShoeb On Jan 4, 10:55 am, Peter Taoussanis wrote: > read/pr-str works well, but it's painfully slow relative to something > likeRedis. JSON libraries and the like would be faster, but might > require more contortions if you're using lots of Clojure data types. > My 2c: the best overall compromise atm is the Deep-Freeze > serialization library (https://github.com/halgari/deep-freeze). It > gets you very decent performance and great support for Clojure data > types. > > You don't mention whatRedisclient you're using, but be aware that if > you're going to be going the binary serialization route, you'll want > to communicate withRedisvia byte[]s rather than JVM strings. If > you're using Jedis, take a look at BinaryJedis. > > Hope that helps! > > --Peter -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Autodoc 0.9.0 (Finally!)
Thanks Tom, works like a charm. Looking forward to support for protocols and the like. Where's a good place to start helping on that front? -Daniel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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!
Holy cow, I feel anki will change my life. Thank you so much for mentioning it. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: Autodoc 0.9.0 (Finally!)
Daniel, Glad, it's working for you! Protocols and stuff are almost done, so I think I'm good there. I just took a swerve off that path for a couple weeks to get things into releasable form since so many were clearly feeling pain over it. Expect more news on that front in the next few weeks. Tom On Jan 5, 8:59 am, semperos wrote: > Thanks Tom, works like a charm. > > Looking forward to support for protocols and the like. Where's a good place > to start helping on that front? > > -Daniel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Storing clojure lists and maps in Redis
Can we get a complete code listing? Also what client are you using? It looks as if your redis client is returning a string, and we're expecting a byte array Timothy > I looked at deep-freeze but did not quite understand how to use it. > I used the following to freeze my Clojure complex data structure - > results (map of list of maps) and persist to redis: -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
How would I learn more about Clojure's class loading system?
So school has started, and I'm laden with syllabi, either in print or online. I'm a stats student, so all my professors use LaTex for...well, everything. So I have all these .pdf files. I had the idea of parsing them and extracting the homework schedules and then making a simple Android app that showed what was due depending on the date. This is admittedly kind of overengineering the whole thing, but I just got the phone for Christmas and I've been itching to write something for it. In the process of trying to extract the text (I was using Apache's PDFBox), I ran into a NoClassDefFound error when importing certain classes. I checked that all the .jars were in all the right places, etc, to no avail. I wasn't so much frustrated by the error (they happen) as with my inability to do much about it or really poke at it. According to the Java docs, NCDF occurs when a class definition that was present at (Java's) compile time is absent at (Java's) runtime. I'm not really sure how that could happen---where could I go for more insight into how java packages/classes are loaded? (I actually have the clojure.core source in front of me as I write this, but can't seem to find where "defmacro import" becomes...well, whatever java it becomes) tl, dr: If I never wanted to have a classpath/library loading issue in Clojure ever again, what should I read? Thanks, Daniel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 I learn more about Clojure's class loading system?
On Thu, Jan 5, 2012 at 12:21 PM, Daniel Bell wrote: > So school has started, and I'm laden with syllabi, either in print or > online. I'm a stats student, so all my professors use LaTex > for...well, everything. So I have all these .pdf files. > > I had the idea of parsing them and extracting the homework schedules > and then making a simple Android app that showed what was due > depending on the date. This is admittedly kind of overengineering the > whole thing, but I just got the phone for Christmas and I've been > itching to write something for it. > > In the process of trying to extract the text (I was using Apache's > PDFBox), I ran into a NoClassDefFound error when importing certain > classes. I checked that all the .jars were in all the right places, > etc, to no avail. > > I wasn't so much frustrated by the error (they happen) as with my > inability to do much about it or really poke at it. According to the > Java docs, NCDF occurs when a class definition that was present at > (Java's) compile time is absent at (Java's) runtime. I'm not really > sure how that could happen---where could I go for more insight into > how java packages/classes are loaded? (I actually have the > clojure.core source in front of me as I write this, but can't seem to > find where "defmacro import" becomes...well, whatever java it becomes) > > tl, dr: If I never wanted to have a classpath/library loading issue in > Clojure ever again, what should I read? > > Thanks, > > Daniel I don't know that anyone can help you without more details about your environment. Are you using lein? What version? What version of PDFBox? What class can't it find? etc. feel free to hop on the #clojure irc channel on freenode > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Any char-based Java file I/O with arbitrary seek?
If this doesn't seem like a question for a Clojure group, I'll preface this by saying it is motivated by writing Clojure examples for a "Clojure cookbook" [1]. So far the examples are intended to work like the Perl examples from the 1st edition of the Perl Cookbook [2], but it may grow beyond that some day (e.g. its own text, examples specific to Clojure constructs that have no direct analog in Perl). In particular, there are examples there for doing random access on files in Chapter 8, and I was wondering whether I'm on the right track. I know about the class RandomAccessFile [3], which provides byte-oriented I/O on a file with the ability to tell your current byte position, or seek to a specified byte position. I know that some of the subclasses of Reader have mark and reset methods, but those appear to have implementation-specific limitations on how far back you can go, and only let you mark one position. I'm interested in something that lets you jump anywhere. Is the only way with built-in Java classes as follows? Use a RandomAccessFile for opening and manipulating the file. When you want to read a character or string, read enough bytes into a byte array and use the String constructor with signature String(byte[] bytes, int offset, int length, String charsetName) to convert it to characters, or the CharsetDecoder class if you want more control over the details. When you want to write a string, use String's getBytes(String charsetName) method to convert it to a byte array and then write that byte array to the file. Are there other open source Java or Clojure libraries that can do this? If you know you are working with a fixed width character encoding like ASCII or ISO-8859, this seems relatively straightforward. 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. In general, restricting writing only to appending, or forgetting this idea altogether and using a database, are preferable in most cases. Thanks, Andy [1] https://github.com/jafingerhut/pleac-clojure forked from https://github.com/mbacarella/pleac-clojure It is easier to understand what the examples are intended to do if you read along with the text of the 1st ed Perl Cookbook. [2] The 2003 2nd edition is here: http://www.amazon.com/Perl-Cookbook-Second-Tom-Christiansen/dp/0596003137/ref=sr_1_1?ie=UTF8&qid=1325800290&sr=8-1 It has some section numbers and examples different from 1st ed, which you can see on line here: http://docstore.mik.ua/orelly/perl/cookbook/ [3] http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Any char-based Java file I/O with arbitrary seek?
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
Re: How would I learn more about Clojure's class loading system?
Thanks Kevin, but I'm not so much looking for debugging help on this specific issue as I'm asking what I should do if I want to be able to, say, help others with similar issues in the future. Classpath stuff is a common bugaboo even for experienced Java developers (or so I hear), and all the finer points of clojure/Java interop have been a thorn in my side for a while now. I'd like to just blow a weekend or three immersing myself in the stuff and get a more fundamental understanding of it than I have now. Your mention of lein reminds me that I should probably spend some time digging through that as well, since I use it for all my projects. Anyway, sorry to be so unclear; part of the problem is that I'm not expert enough to know exactly what I'm looking for. But thanks for taking the 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
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 > > 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!
Joshua I used http://www.mnemosyne-proj.org/ when I was learning Japanese and I experienced a dramatic improvement in my retention rates. To give you and idea I learned 1000 Chinese characters (Kanji) and about 4000 words in one year. I spent around 40 minutes per day only. Arnoldo On Jan 3, 4:45 pm, Joshua wrote: > Hi Tim, > > Great idea re: GitHub! > > I'm guessing the Clojure decks could cover, multiple things if tagged > appropriately and could be studied in various section. Or there could > be multiple decks dealing with differing material. I'm not very > familiar with github, but it is high time I really check it out and > would be a great place for this sort of project. > > Have you found using an SRS helped with more than just studying on > your own with regard to development? > > Are you experiencing good retention rates and reduced practice time > reviewing with Anki? > > -Joshua > > On Jan 3, 12:25 pm, daly wrote: > > > > > > > > > I have built several Anki SRS decks for learning. > > I am building one now on American Sign Language. > > > A Clojure deck would be a good idea. > > > We could put a simple deck on github and make it so > > others could contribute. What should it cover? > > Only language syntax? Idiomatic forms (like lazy > > sequences)? Sections on Java interop? > > > Tim Daly > > > On Tue, 2012-01-03 at 18:19 +0100, Linus Ericsson wrote: > > > 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.org etc). 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 > > > 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... > > > > -- > > > You received this message because you are subscribed to the > > > Google > > > Groups "Clojure" group. > > > To post to this group, send email to clojure@googlegroups.com > > > Note that posts from new members are moderated - please be > > > patient with your first post. > > > To unsubscribe from 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: How would I learn more about Clojure's class loading system?
Hi Daniel, While this may not be all-inclusive, there could be two main reasons for the error. 1. You don't really have all the jars required. This is easy to check. A jar is just a zip file really and can be viewed (jar -tvf ). Look for the class file in there that matches the class that is being complained about. If you can't find it in any of the jars, that's your problem right there. 2. You have all the jars, but are not including them in the classpath for your clojure program. This goes to what Kevin was asking about. The best way (IMO) to make sure you're all good there would be to run your clojure project using leiningen. Otherwise, if you are running from the command line, make sure your -cp argument includes all the jars you need (this is really java, not clojure specific). Apologies if some of the above is stuff you already know, I hoped to err on the side of explaining too much rather than too little. Let us know how you go. Cheers On Jan 6, 7:21 am, Daniel Bell wrote: > So school has started, and I'm laden with syllabi, either in print or > online. I'm a stats student, so all my professors use LaTex > for...well, everything. So I have all these .pdf files. > > I had the idea of parsing them and extracting the homework schedules > and then making a simple Android app that showed what was due > depending on the date. This is admittedly kind of overengineering the > whole thing, but I just got the phone for Christmas and I've been > itching to write something for it. > > In the process of trying to extract the text (I was using Apache's > PDFBox), I ran into a NoClassDefFound error when importing certain > classes. I checked that all the .jars were in all the right places, > etc, to no avail. > > I wasn't so much frustrated by the error (they happen) as with my > inability to do much about it or really poke at it. According to the > Java docs, NCDF occurs when a class definition that was present at > (Java's) compile time is absent at (Java's) runtime. I'm not really > sure how that could happen---where could I go for more insight into > how java packages/classes are loaded? (I actually have the > clojure.core source in front of me as I write this, but can't seem to > find where "defmacro import" becomes...well, whatever java it becomes) > > tl, dr: If I never wanted to have a classpath/library loading issue in > Clojure ever again, what should I read? > > Thanks, > > Daniel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 I learn more about Clojure's class loading system?
There are a number of different possibilities. Without anything more specific the only realistic answer is "read the source of all the libraries you are using, and of clojure, and of lein and look for tricks with classloaders" Clojure does some classloader fiddling, but so do most jvm build tools and many libraries and frameworks. >From memory: Clojure uses a dynamic classloader stored in a var in a static field on the compiler class. The parent of the dynamic classloader is either the context classloader or the system classloader. In certain cases the compiler will use a new dynamic classloader for the extent of compilation. The relevent code is in RT.java, DynamicClassloader.java, and Compiler.java On Jan 5, 2012 3:00 PM, "Daniel Bell" wrote: > Thanks Kevin, but I'm not so much looking for debugging help on this > specific issue as I'm asking what I should do if I want to be able to, > say, help others with similar issues in the future. Classpath stuff > is a common bugaboo even for experienced Java developers (or so I > hear), and all the finer points of clojure/Java interop have been a > thorn in my side for a while now. I'd like to just blow a weekend or > three immersing myself in the stuff and get a more fundamental > understanding of it than I have now. > > Your mention of lein reminds me that I should probably spend some time > digging through that as well, since I use it for all my projects. > > Anyway, sorry to be so unclear; part of the problem is that I'm not > expert enough to know exactly what I'm looking for. But thanks for > taking the 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 post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: LCUG: 17th January 2012, Malcolm Sparks - Reflections on a real-world Clojure application
On Jan 5, 11:56 am, Kevin Lynagh wrote: > Any chance the talk will be filmed and posted online? +1. Or slides posted? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Storing clojure lists and maps in Redis
Hi Tim I am using redis-clojure client: https://github.com/tavisrudd/redis-clojure Below is the complete code listing. The thaw invocation gives me the error: java.lang.String cannot be cast to [B - (class java.lang.ClassCastException) -- code (ns my-app (:require [redis.core :as redis] [deep-freeze.core :as df]) (:use [clojure.tools.logging :only (debug info)])) (defn thaw [k] (redis/with-server {:host "dev-1" :port 6379 :db 0} (let [j (redis/hget k k)] (if (nil? j) (do (info (str "Not found in redis cache " k)) nil) (do (info (str "Thawed from redis cache " k)) (df/thaw-from-array j)) (defn freeze [k results] (redis/with-server {:host "dev-1" :port 6379 :db 0} (redis/hmset k k (df/freeze-to-array results On Jan 5, 3:14 pm, Timothy Baldridge wrote: > Can we get a complete code listing? Also what client are you using? It > looks as if yourredisclient is returning a string, and we're > expecting a byte array > > Timothy > > > > > > > > > I looked at deep-freeze but did not quite understand how to use it. > > I used the following to freeze my Clojure complex data structure - > > results (map of list of maps) and persist toredis: -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Storing clojure lists and maps in Redis
Yup, Timothy is correct. Basically Redis's native datatype is a bytestring: http://redis.io/topics/internals-sds. This is actually more like a JVM ByteArray than String, so libraries like Jedis (which take Strings), do some coercions for you. clj-redis uses Jedis underneath, so it expects Strings. But deep- freeze uses byte[]s, so these coercions are what's causing you trouble. You should be able to test this by trying (redis/hmset k k (String. (deep-freeze/freeze-to-array results)) to freeze and (deep-freeze/thaw- from-array (.getBytes (redis/hget k k)) to thaw. That should work, but it's inefficient because you're coercing from byte[]s to String, then Jedis is coercing from String back to byte[]s. A better solution would be to communicate with Redis directly with byte[]s in the first place. This is possible using BinaryJedis, but there's no support in clj-redis for it yet. I've forked clj-redis and am slowly doing some experiments here: https://github.com/ptaoussanis/clj-redis (see binset/binget), but that's FAR from being useable now. The real problem here is clj-redis not being a good fit for binary serialization at this point. That will probably improve in time, so if you'd prefer to stay with clj-redis and you're not in a hurry for performance I'd probably stick with read/pr-str for now to keeps things simple. If you really need the extra performance right now, you'll need to interface with BinaryJedis directly for values you want to freeze/ thaw. Hope that helps a bit at least, -- Peter -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Storing clojure lists and maps in Redis
Oh wow, sorry- I didn't see your reply in time and for some reason figured you were using clj-redis. This is actually easier since (if I recall correctly) redis-clojure is able to write byte[]s and has an as-bytes macro for reading. So you'd want something like this (untested): (defn thaw [k] (redis/with-server {:host "dev-1" :port 6379 :db 0} (let [j (redis/as-bytes (redis/hget k k))] (if (nil? j) (do (info (str "Not found in redis cache " k)) nil) (do (info (str "Thawed from redis cache " k)) (df/thaw-from-array j)) (defn freeze [k results] (redis/with-server {:host "dev-1" :port 6379 :db 0} (redis/hmset k k (df/freeze-to-array results -- Peter -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en