Re: ANN: Clojure web application using NHPM for server push
On Thu, Dec 23, 2010 at 1:53 AM, rob levy r.p.l...@gmail.com wrote: Hi Anders, thanks. If I understand what you are asking, in fact the server in my case does not care if anyone is listening, however you can set how long the messages live in the queue. The client holds the responsibility of keeping track of what messages it has already seen based on the date in the response header. If you want to make sure your client doesn't miss messages you set a very long time to live and let the client catch up to what it hasn't seen yet in the spew of messages when it signs back on. For my application this was not necessary, as I treat push messages as ephemeral short lived things. When the client comes back on the direct request to the server to log in gives its next waiting event as a plain old response to the request to the application maintaining this state. Does this answer your question? Yes it does thanks. Always interesting to hear about architectural aspects :-) I'm more and more thinking that for my application where clients listening is low and the cost of creating a message is high, that I would want something like websockets. Because it would easier allow me to know when a client has disconnected. On Dec 21, 2010 5:50 PM, Anders Rune Jensen anders.rune.jen...@gmail.com wrote: On Mon, Dec 20, 2010 at 6:06 PM, rob levy r.p.l...@gmail.com wrote: I have posted a repository containing the code for a web application I made using a server push (AKA Comet, long polling) architecture. The front end is in Javascript, and the back end is in Clojure. The clojure code is able to send notifications to clients' browsers effectively through use of nginx's push module, which the clients subscribe to. With websockets presently out of reach this can be a good way of doing this sort of thing, and at least on my small-scale testing it is a super responsive way of simulating a socket. Hi Rob Interesting project. I havn't looked at the machine learning part of it, although that also sounds interesting, but at first I was more interested in the long polling aspect of your application. I was looking at something similar but in the end I decided that given my use case (mostly a single client polling) it didn't make much sense to use nginx. I'm guessing that in your architecture, nginx makes more sense because you have a lot of clients polling the same interface? That way you know that it is much more likely that there will be at least one subscriber left for a message when the server actually has something to send. And I guess the way the back-end knows that there is still someone that wants to know about a message is that nginx says that there is still clients waiting when it delivers the message. Could you maybe elaborate a bit more on this? https://github.com/rplevy/sayoperation The application itself is online (for now) at: http://www.robertplevy.net/sayoperation/ A little bit of context is necessary here. This is a game I made as part of my final project for a course I am in (I am taking courses part time as part of an MA program I will eventually complete) on the topic of Machine Learning and Natural Language Processing. The purpose of the game is to collect game move data. I'm in the process of figuring out how to train a classifier to learn to make the same sorts of game moves (though the text generation piece is out of scope), to have 1/2 of an AI game player. If you want to play the game and help me collect training data, here are some things to know: 1. You will be asked to give an instruction to your team mate, given the information on the screen. The red is the target, and the green is what your teammate will move to the target. Notice that the target is always an empty space. For example put the crab above the butterfly would make sense if the crab had a green border, and there were a red bordered target above the butterfly. 2. Use clear and natural language when entering data., try to explain in the way you would explain to a person. Punctuation and capitalization is stripped out/lowercased. 3. The rounds work like this. Player 1 instruct - Player 2 move -- Player 2 instruct -- Player 1 move. The game automatically presents your next available move just like in RIAs such as gchat or facebook (no need to refresh). 4. Multiple concurrent games are encouraged. The game should be responsive and will immediately tell you if you have a move to play in any of your games. 5. Caveat: The application has been tested thoroughly in Firefox and Chrome. While there is no inherent reason why it shouldn't be possible to make it work in Opera or Internet Explorer, I have not tested it in IE (so it probably doesn't work in that browser), and I am aware that it doesn't work in Opera. This is just a matter of time and effort, that I need to spend on the NLP side of this project at the moment.
complex number performance enhancement...
Hello everybody, I have a numerically intensive code. after getting it to work I started profiling the code .. and zeroed down that my complex number operations are the most called functions and probably among the slowest due to my naive implementation. The code I am using is in the following post. https://gist.github.com/755484 I had earlier asked a similar question with out doing any profiling .. But Stuart sierra had suggested that I look at one of his pastes .. which is http://paste.lisp.org/display/93387 It uses protocols and deftype I noticed that it was an old post .. I could not get it to compile to try it out.. I was complaining about likes of trying to convert a name-space-qualified to a type name .. w.r.t ::Complex . I tried a couple of things to get it working with out success.. Any suggestions to improve my code or to get stuart's code compiled so that I can try it would be very help full. Thanks, Sunil. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Let's see how fast we can make this
I don't know why I thought Java used UTF-8, thank you for the correction. So yeah, would be interesting to see the tests on C done with wide char in UTF-16. On Dec 26, 1:54 am, Glen Stampoultzis gst...@gmail.com wrote: On 26 December 2010 03:00, Ivan ivankob...@gmail.com wrote: Would be interesting to see tests done on UTF-8 strings as this is the only type that Java supports. Do you mean UTF-16? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Question about when to use protocol+record and compilation warnings
Hello, In an effort to learn a little more about clojure (and possibly introduce it at work) I decided to write a native client for the Beanstalk work queue. See http://kr.github.com/beanstalkd/ for more information about the queue and https://github.com/drsnyder/beanstalk for the client. One of the decisions I wasn't sure about was whether to use a protocol or a struct map for the (socket, reader, writer) tuple. I started using a struct-map and then switched over to defprotocol/defrecord. See https://github.com/drsnyder/beanstalk/blob/82f301f1f825bb05aa14d85a220ec57c1dea61b2/src/beanstalk/core.clj#L117 for the definition. Is one preferred over the other (struct vs record)? Using the protocol +record idiom maps really well to the queue protocol-- you end up with statements like (.put object params), (.reserve object) etc which are very clear and intuitive from the developers perspective. It creates a one-to-one mapping to the beanstalkd protocol commands. If I were using a struct-map I might have methods like (beanstalk-put object params) etc. But one issue I encountered with defprotocol is that there appears to be a possible symbol table/space issue. When I compile, I get warnings like the following: Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting function read Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting function peek Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting function use WARNING: read already refers to: #'clojure.core/read in namespace: beanstalk.core, being replaced by: #'beanstalk.core/read WARNING: peek already refers to: #'clojure.core/peek in namespace: beanstalk.core, being replaced by: #'beanstalk.core/peek WARNING: use already refers to: #'clojure.core/use in namespace: beanstalk.core, being replaced by: #'beanstalk.core/use WARNING: read already refers to: #'clojure.core/read in namespace: beanstalk.core-test, being replaced by: #'beanstalk.core/read WARNING: peek already refers to: #'clojure.core/peek in namespace: beanstalk.core-test, being replaced by: #'beanstalk.core/peek WARNING: use already refers to: #'clojure.core/use in namespace: beanstalk.core-test, being replaced by: #'beanstalk.core/use Is there something I'm can do to prevent these collisions aside from using a different name for the method? Thanks, Damon -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
But one issue I encountered with defprotocol is that there appears to be a possible symbol table/space issue. When I compile, I get warnings like the following: Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting function read Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting function peek Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting function use WARNING: read already refers to: #'clojure.core/read in namespace: beanstalk.core, being replaced by: #'beanstalk.core/read WARNING: peek already refers to: #'clojure.core/peek in namespace: beanstalk.core, being replaced by: #'beanstalk.core/peek WARNING: use already refers to: #'clojure.core/use in namespace: beanstalk.core, being replaced by: #'beanstalk.core/use WARNING: read already refers to: #'clojure.core/read in namespace: beanstalk.core-test, being replaced by: #'beanstalk.core/read WARNING: peek already refers to: #'clojure.core/peek in namespace: beanstalk.core-test, being replaced by: #'beanstalk.core/peek WARNING: use already refers to: #'clojure.core/use in namespace: beanstalk.core-test, being replaced by: #'beanstalk.core/use Is there something I'm can do to prevent these collisions aside from using a different name for the method? You should change your toplevel ns declaration to something like this - (ns beanstalk.core ;; Don't refer to the following clojure.core functions (:refer-clojure :exclude [read peek use]) (:use [clojure.contrib.condition :only [raise]] [clojure.string :only [split lower-case]] [clojure.pprint :only [pprint]] [clojure.java.io]) (import [java.io BufferedReader])) This won't refer to the conflicting functions and your life will be easy :) If you still need those functions, you can call them by namespace-qualifying the symbols like clojure.core/read, etc. Hope that helps. Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
printf output from threads
What do people use for logging debug output from threads? Either native threads created with Thread. or implicit threads via agents or pmap etc? I tried passing *out* to my thread function and then binding it to *out* in the thread, and this works but then makes the threads execute one at a time, and I'm presuming that is because my use of *out* in the binding block is blocking for the other threads which use it. Justin -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: partitioning iterative list
On Fri, Dec 24, 2010 at 8:38 PM, Glen Rubin rubing...@gmail.com wrote: Can I do the following without using loops?? I have list, e.g. '(4 6 66 33 26 6 83 5) I want to partition it so that I get a subset of lists that build up to the original: ( (4) (4 6) (4 6 66) (4 6 66 33) ) (defn sublists [s] (map #(take (inc %) s) (range (count s -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
complexity
Hi everyone, I was in the project euler page and i tried to solve the question 8 using clojure. No big deal, was really cool. So , i cant figure out what is the time complexity for the *code* below I thought that was O(n^2), but running the code for different input seems that the complexity is O(n). (def list-of-list (list (list 1 2 3 4 5) ( list 2 3 4 5 6) ( list 9 8 7 6 5) )) (defn project-euler-8 [ ] (let[begin (System/currentTimeMillis) ] (println (str Result = * (**apply** **max** **(**map** #**(**reduce** * %1**)* * **(**for** [i **(**range** **(**count** list-of-list**)**)**] * ***(**take** 5 **(**drop** i list-of-list**)**)**)**)**)**)**)* (println (str Time = ( - (System/currentTimeMillis) begin ) ) ) ) ) The map reduce could be translated like two nested for ? This is O(n^2), isn´t ? for ( list-of-list ) for ( sublist) product *= element Regards Dantas, Thiago ps: Sorry for my english, im not a good writer ! :) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: websockets w/ clojure
I don't have any publicly available jetty/clojure/websocket code. I'll see if I can throw something together tomorrow. Cheers, Jay On Dec 24, 2010, at 11:58 PM, Sean Allen wrote: Jay, Do you have any publicly released code I could take a look at? I've only found a couple of jetty/clojure/websocket examples and would love to have more I could study. -Sean- On Fri, Dec 24, 2010 at 7:53 PM, Jay Fields j...@jayfields.com wrote: I've written a few Clojure websocket apps and used Jetty. Things worked out fine and there wasn't much code at all to integrate. I'd recommend it. Sent from my iPhone On Dec 24, 2010, at 11:58 AM, Sean Allen s...@monkeysnatchbanana.com wrote: We did a prototype application using websockets for work using node.js as the server. Websocket client connects, sending some basic info... said info is used to repeatedly get new data from a database that is pushed down as it arrives in the db to the client which displays. There will be more than 1 client, each with its own data constraints that are used to get the data to send. If it goes into production we need to run on the jvm so I've been rewriting in clojure. I spent a couple hours yesterday trying to figuring out the best websockets option to use w/ the clojure based server before I gave up. I realized w/o any background I'm just running blind. Given the basic idea of the application, what is the best websockets abstraction to use w/ clojure? Aleph? The jetty websocket support? Something else? Pointers from anyone will more experience doing a websocket server in clojure greatly appreciated. Thanks, Sean -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Question about when to use protocol+record and compilation warnings
Damon Snyder drsny...@gmail.com writes: One of the decisions I wasn't sure about was whether to use a protocol or a struct map for the (socket, reader, writer) tuple. I started using a struct-map and then switched over to defprotocol/defrecord. See https://github.com/drsnyder/beanstalk/blob/82f301f1f825bb05aa14d85a220ec57c1dea61b2/src/beanstalk/core.clj#L117 for the definition. Struct maps were in the language for a long time before defrecord was added. Records are supposed to replace them for most purposes. So if in doubt between the two use a defrecord. The decision tree is basically: * Am I implementing a data structure (like a hash-map or vector)? = Use deftype. * Do I need to use polymorphism? = Use defrecord. * Otherwise = Use a normal hash-map instance. I'd probably also try to implement basic functionality against an existing Java or Clojure interface where possible. For example for close you could use the java.io.Closeable interface. If possible (I'm not familiar with beanstalk's model) I'd also try to implement parts of java.util.Queue. That way you could use the object with existing code that knows how to use those interfaces. You can still have Clojure helper functions to avoid clients having to do type-hinting and so the functions can be used first-class. Just define the helpers against the interface: (defn close [^java.io.Closeable closeable] (.close closeable)) What you've got seems pretty reasonable though. If I were writing client code using your library, I guess I'd consume it something like this: (ns myapp (:require [beanstalk.core :as bs])) (def *running* true) (with-open [q (bs/new-beanstalk ...)] (while *running* (let [[id len] (bs/reserve q)] (do-some-work (bs/peek q id)) (bs/bury q id))) I wonder if there's room for some higher-level helpers in your library? For example if the above pattern is really common would something along these lines be useful: (defn do-work Grabs work items from the queue and processes them with f. Stops when f returns false. [queue f] (while (let [[id len] (reserve queue) result (f (peek queue id))] (bury queue id) result))) Perhaps in a new thread? Perhaps you need a try/catch to release failed jobs or something? Whatever makes sense for the normal beanstalk usage pattern. Would it make sense to implement clojure.lang.Seqable for a pull-style interface? (map f queue) (doseq [job queue] (f job)) (let [some-jobs (take 10 queue)] ...) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
On Sun, Dec 26, 2010 at 7:18 PM, Alex Osborne a...@meshy.org wrote: Damon Snyder drsny...@gmail.com writes: One of the decisions I wasn't sure about was whether to use a protocol or a struct map for the (socket, reader, writer) tuple. I started using a struct-map and then switched over to defprotocol/defrecord. See https://github.com/drsnyder/beanstalk/blob/82f301f1f825bb05aa14d85a220ec57c1dea61b2/src/beanstalk/core.clj#L117 for the definition. Struct maps were in the language for a long time before defrecord was added. Records are supposed to replace them for most purposes. So if in doubt between the two use a defrecord. Isn't one advantage of structmaps over records that you don't need to AOT your structmaps? And can thus change them on the fly during REPL-driven programming, debugging, and experimentation instead of having to do a discrete edit, build, test cycle? I'd suggest at least using structmaps until you've debugged the algorithms and finalized the design of the structmap itself (its fields and their semantics) and then perhaps convert them to records and, perhaps, add nice behaviors like seqability or whatever layered onto the already-tested functionality. Jumping straight to defrecord might, in some cases, be premature optimization, too. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: complex number performance enhancement...
Sunil S Nandihalli sunil.nandiha...@gmail.com writes: http://paste.lisp.org/display/93387 It uses protocols and deftype I noticed that it was an old post .. I could not get it to compile to try it out.. I was complaining about likes of trying to convert a name-space-qualified to a type name .. w.r.t ::Complex . I tried a couple of things to get it working with out success.. Any suggestions to improve my code or to get stuart's code compiled so that I can try it would be very help full. Here's how to get Stuart's working. 1. Replace ::Complex with Complex everywhere. 2. Change (deftype Complex [r i]) to (defrecord Complex [r i]). 3. Put a . after the Complex constructors so they look like this: (extend-double add Complex Complex (fn [c1 c2] (Complex. (+ (:r c1) (:r c2)) (+ (:i c1) (:i c2) You should end up with something vaguely like this: https://gist.github.com/755758 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
Ken Wesson kwess...@gmail.com writes: On Sun, Dec 26, 2010 at 7:18 PM, Alex Osborne a...@meshy.org wrote: Struct maps were in the language for a long time before defrecord was added. Records are supposed to replace them for most purposes. So if in doubt between the two use a defrecord. Isn't one advantage of structmaps over records that you don't need to AOT your structmaps? And can thus change them on the fly during REPL-driven programming, debugging, and experimentation instead of having to do a discrete edit, build, test cycle? Actually you don't need to AOT compile records or types. They work fine for interactive development. The official struct-map documentation even recommends you should consider using a record instead: http://clojure.org/data_structures#Data Structures-StructMaps Jumping straight to defrecord might, in some cases, be premature optimization, too. For business logic, like actual records then certainly, a hash-map is usually preferable unless you need polymorphism. {:name John Smith, :phone 12345678} In this case Damon is basically implementing a type though not a record. I probably should have explicitly mentioned that deftype would be a better choice in this case -- that's what the decision tree was supposed to show. Records get you these features, all of which make no sense for a queue object: * value-based equality and hashCode * (immutable) metadata support * associative support * keyword accessors for fields * extensible fields -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Knuth's literate programming tangle function in Clojure
That's really cool. I was _just reading_ your comments from 2006 at http://www.mail-archive.com/gardeners@lispniks.com/msg01006.html and wondering about how hard something like this would be to write. If possible, could you expand on how one might use this in a development work-flow with emacs or texmacs? Is there some sort of lisp-pamphlet mode that could be extended to clojure? I'm assuming you've already solved all these problems and more while working with Axiom. I'd appreciate any pointers or best practices you might have found. Thanks so much for your work! --Robert McIntyre On Sun, Dec 26, 2010 at 1:01 AM, Tim Daly d...@axiom-developer.org wrote: ; 0 AUTHOR and LICENSE ; 1 ABSTRACT and USE CASES ; 2 THE LATEX SUPPORT CODE ; 3 IMPORTS ; 4 THE TANGLE COMMAND ; 5 SAY ; 6 READ-FILE ; 7 ISCHUNK ; 8 HASHCHUNKS ; 9 EXPAND ; 10 TANGLE ;;; 0 AUTHOR and LICENSE ;;; Timothy Daly (d...@axiom-developer.org) ;;; License: Public Domain ;;; 1 ABSTRACT and USE CASES ;;; Don Knuth has defined literate programming as a combination of ;;; documentation and source code in a single file. The TeX language ;;; is documented this way in books. Knuth defined two functions ;;; tangle - extract the source code from a literate file ;;; weave - extract the latex from a literate file ;;; This seems unnecessarily complex. Latex is a full programming ;;; language and is capable of defining environments that can ;;; handle code directly in Latex. Here we define the correct environment ;;; macros. Thus, the weave function is not needed. ;;; If this tangle function were added to Clojure then Clojure could ;;; read literate files in Latex format and extract the code. We create ;;; the necessary tangle function here. ;;; This program will extract the source code from a literate file. ;;; A literate lisp file contains a mixture of latex and lisp sources code. ;;; The file is intended to be in standard latex format. In order to ;;; delimit code chunks we define a latex chunk environment. ;;; Latex format files defines a newenvironment so that code chunks ;;; can be delimited by \begin{chunk}{name} \end{chunk} blocks ;;; This is supported by the following latex code. ;;; So a trivial example of a literate latex file might look like ;;; (ignore the prefix semicolons. that's for lisp) ; this is a file that is in a literate ; form it has a chunk called ; \begin{chunk}{first chunk} ; THIS IS THE FIRST CHUNK ; \end{chunk} ; and this is a second chunk ; \begin{chunk}{second chunk} ; THIS IS THE SECOND CHUNK ; \end{chunk} ; and this is more in the first chunk ; \begin{chunk}{first chunk} ; \getchunk{second chunk} ; THIS IS MORE IN THE FIRST CHUNK ; \end{chunk} ; \begin{chunk}{all} ; \getchunk{first chunk} ; \getchunk{second chunk} ; \end{chunk} ; and that's it ;;; From a file called testcase that contains the above text ;;; we want to extract the chunk names second chunk. We do this with: ; (tangle testcase second chunk) ; which yields: ; THIS IS THE SECOND CHUNK ;;; From the same file we might extract the chunk named first chunk. ;;; Notice that this has the second chunk embedded recursively inside. ;;; So we execute: ; (tangle testcase first chunk) ; which yields: ; THIS IS THE FIRST CHUNK ; THIS IS THE SECOND CHUNK ; THIS IS MORE IN THE FIRST CHUNK ;;; There is a third chunk called all which will extract both chunks: ; (tangle testcase all) ; which yields ; THIS IS THE FIRST CHUNK ; THIS IS THE SECOND CHUNK ; THIS IS MORE IN THE FIRST CHUNK ; THIS IS THE SECOND CHUNK ;;; The tangle function takes a third argument which is the name of ;;; an output file. Thus, you can write the same results to a file with: ; (tangle testcase all outputfile) ;;; It is also worth noting that all chunks with the same name will be ;;; merged into one chunk so it is possible to split chunks in mulitple ;;; parts and have them extracted as one. That is, ; \begin{chunk}{a partial chunk} ; part 1 of the partial chunk ; \end{chunk} ; not part of the chunk ; \begin{chunk}{a partial chunk} ; part 2 of the partial chunk ; \end{chunk} ;;; These will be combined on output as a single chunk. Thus ; (tangle testmerge a partial chunk) ; will yield ; part 1 of the partial chunk ; part 2 of the partial chunk ;;; 2 THE LATEX SUPPORT CODE ;;; The verbatim package quotes everything within its grasp and is used to ;;; hide and quote the source code during latex formatting. The verbatim ;;; environment is built in but the package form lets us use it in our ;;; chunk environment and it lets us change the font. ;;; ;;; \usepackage{verbatim} ;;; ;;; Make the verbatim font smaller ;;; Note that we have to
Re: complex number performance enhancement...
thanks Alex for your response . I tried it ... It compiled fine .. but the double dispatch does not seem to work correctly .. It some how reverses the arguments and then dispatches to the correct function for the reversed arguments and the function works properly .. i.e. when I do (- (Complex. 1 3) 3) .. I would expect (Complex. -2 3) but I get (Complex. 2 -3) which is what I would expect to get when I do (- 3 (Complex. 1 3)) . I am trying to make it work right .. but I thought some of you may better able to fix it. Thanks, Sunil I am trying to debug it .. but would like some I am still trying to understand the code and figure it out.. But I just thought I On Mon, Dec 27, 2010 at 6:03 AM, Alex Osborne a...@meshy.org wrote: Sunil S Nandihalli sunil.nandiha...@gmail.com writes: http://paste.lisp.org/display/93387 It uses protocols and deftype I noticed that it was an old post .. I could not get it to compile to try it out.. I was complaining about likes of trying to convert a name-space-qualified to a type name .. w.r.t ::Complex . I tried a couple of things to get it working with out success.. Any suggestions to improve my code or to get stuart's code compiled so that I can try it would be very help full. Here's how to get Stuart's working. 1. Replace ::Complex with Complex everywhere. 2. Change (deftype Complex [r i]) to (defrecord Complex [r i]). 3. Put a . after the Complex constructors so they look like this: (extend-double add Complex Complex (fn [c1 c2] (Complex. (+ (:r c1) (:r c2)) (+ (:i c1) (:i c2) You should end up with something vaguely like this: https://gist.github.com/755758 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that 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: Question about when to use protocol+record and compilation warnings
On Sun, Dec 26, 2010 at 8:20 PM, Alex Osborne a...@meshy.org wrote: Ken Wesson kwess...@gmail.com writes: On Sun, Dec 26, 2010 at 7:18 PM, Alex Osborne a...@meshy.org wrote: Struct maps were in the language for a long time before defrecord was added. Records are supposed to replace them for most purposes. So if in doubt between the two use a defrecord. Isn't one advantage of structmaps over records that you don't need to AOT your structmaps? And can thus change them on the fly during REPL-driven programming, debugging, and experimentation instead of having to do a discrete edit, build, test cycle? Actually you don't need to AOT compile records or types. They work fine for interactive development. Eh. That's not what I saw written elsewhere. Or is it just protocols? Though usually those are used hand-in-hand with records. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: complex number performance enhancement...
Sunil S Nandihalli sunil.nandiha...@gmail.com writes: thanks Alex for your response . I tried it ... It compiled fine .. but the double dispatch does not seem to work correctly .. It some how reverses the arguments and then dispatches to the correct function for the reversed arguments and the function works properly .. i.e. when I do (- (Complex. 1 3) 3) .. I would expect (Complex. -2 3) but I get (Complex. 2 -3) which is what I would expect to get when I do (- 3 (Complex. 1 3)) . I am trying to make it work right .. but I thought some of you may better able to fix it. Oh right. Just swap type1 and type2 in extend-double. Looks like the implementation of (subtract Number Complex) had a bug too, it didn't negate the imaginary component. Updated the gist: https://gist.github.com/755758 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
Ken Wesson kwess...@gmail.com writes: Actually you don't need to AOT compile records or types. They work fine for interactive development. Eh. That's not what I saw written elsewhere. Or is it just protocols? Though usually those are used hand-in-hand with records. Perhaps you're thinking of gen-class? Protocols are also fine for interactive development. http://clojure.org/Protocols says: defprotocol is dynamic, and does not require AOT compilation http://clojure.org/datatypes says: [Types and records] are suitable for dynamic and interactive development, need not be AOT compiled, and can be re-evaluated in the course of a single session. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Knuth's literate programming tangle function in Clojure
Tim, This approach is very interesting. My choice of mode for LP has always been noweb-mode but it doesn't seem to work with my version of emacs anymore. My current approach is to embed prose and clojure code in a latex document and generate a .tex file with formatted clojure code and .clj containing only clojure code. Needless to say, it is a hack and I would like to see if I can adopt your approach. However, I have a question on mapping of line numbers in clojure stacktrace to its source. AFAIK, there is no support in clojure compiler for #LINE directive. In my case, a code is always in one location and I just replace latex lines with empty lines. How do you address this issue? Thanks, Praki On Sat, Dec 25, 2010 at 10:01 PM, Tim Daly d...@axiom-developer.org wrote: ; 0 AUTHOR and LICENSE ; 1 ABSTRACT and USE CASES ; 2 THE LATEX SUPPORT CODE ; 3 IMPORTS ; 4 THE TANGLE COMMAND ; 5 SAY ; 6 READ-FILE ; 7 ISCHUNK ; 8 HASHCHUNKS ; 9 EXPAND ; 10 TANGLE -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
On Sun, Dec 26, 2010 at 9:25 PM, Alex Osborne a...@meshy.org wrote: Ken Wesson kwess...@gmail.com writes: Actually you don't need to AOT compile records or types. They work fine for interactive development. Eh. That's not what I saw written elsewhere. Or is it just protocols? Though usually those are used hand-in-hand with records. Perhaps you're thinking of gen-class? No. Protocols are also fine for interactive development. Someone here definitely said, recently and specifically, that at least one of the feature-complex around deftype/defprotocol/defrecord required AOT compilation. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
On Sun, Dec 26, 2010 at 10:00 PM, Ken Wesson kwess...@gmail.com wrote: On Sun, Dec 26, 2010 at 9:25 PM, Alex Osborne a...@meshy.org wrote: Ken Wesson kwess...@gmail.com writes: Actually you don't need to AOT compile records or types. They work fine for interactive development. Eh. That's not what I saw written elsewhere. Or is it just protocols? Though usually those are used hand-in-hand with records. Perhaps you're thinking of gen-class? No. Protocols are also fine for interactive development. Someone here definitely said, recently and specifically, that at least one of the feature-complex around deftype/defprotocol/defrecord required AOT compilation. Oddly, I'm now having trouble finding it. A simple search turns up this: It's because of protocols. Code that uses protocols behaves differently when it's AOT-compiled--the reference to the compiled version of the protocol is hard-coded into the AOT output. which makes it seem that IF you AOT-compile code with protocols, you then get some stuff frozen at the AOT-compiled version until you remove the class files or similar, impeding REPL development (and potentially causing other problems), but there was some other more direct reference to use of some related feature making REPL development difficult and I can't find it. My search was on AOT, so perhaps that was alluded to without being referenced by that name in the thread in question. Can anyone remember what it was? I'm pretty sure it had activity in the last week or two -- which makes it all the stranger that it's now difficult to find. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about when to use protocol+record and compilation warnings
On Sun, Dec 26, 2010 at 9:00 PM, Ken Wesson kwess...@gmail.com wrote: On Sun, Dec 26, 2010 at 9:25 PM, Alex Osborne a...@meshy.org wrote: Ken Wesson kwess...@gmail.com writes: Actually you don't need to AOT compile records or types. They work fine for interactive development. Eh. That's not what I saw written elsewhere. Or is it just protocols? Though usually those are used hand-in-hand with records. Perhaps you're thinking of gen-class? No. Protocols are also fine for interactive development. Someone here definitely said, recently and specifically, that at least one of the feature-complex around deftype/defprotocol/defrecord required AOT compilation. definterface/deftype/defprotocol/et al do not require AOT. structmaps are a legacy feature. defrecord is the way to go now. I've encountered some odd behavior at the SLIME REPL on occasion, but I haven't yet pinpointed a specific flow to recreate. It wasn't serious enough to impede interactive development. 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: Knuth's literate programming tangle function in Clojure
On 12/26/2010 9:56 PM, Praki Prakash wrote: Tim, This approach is very interesting. My choice of mode for LP has always been noweb-mode but it doesn't seem to work with my version of emacs anymore. My current approach is to embed prose and clojure code in a latex document and generate a .tex file with formatted clojure code and .clj containing only clojure code. Needless to say, it is a hack and I would like to see if I can adopt your approach. Well, I'm something of a primitivist so I don't use modes in Emacs. I know there is a noweb mode and a clojure mode and a latex mode but I've never used any of them so I can't comment. In the Knuth web approach (ala noweb) the chunk markup is not valid latex. Therefore you need to run weave to extract valid latex. I found this pointless so I wrote the latex environment macros to wrap the code chunks. This means that the document you are writing is always pure latex. So you might find it useful to use the chunk environment and skip the generate .tex file step. All that is left is to extract the clojure code. While writing the code I have a REPL open so I can kill/yank changes directly. The full build/test cycle uses the attached code to extract from the literate document (which I call a pamphlet). However, I have a question on mapping of line numbers in clojure stacktrace to its source. AFAIK, there is no support in clojure compiler for #LINE directive. In my case, a code is always in one location and I just replace latex lines with empty lines. How do you address this issue? I don't use the #LINE directive. I usually use a split screen with lisp or clojure in a shell buffer (not a slime setup) and my code in the other buffer. I've hand-checked the code in the REPL before adding to or changing the document. After each change I do a complete system rebuild/test cycle. Thus, if it fails I know exactly what I broke and where I broke it. It is broken at the last change, which is likely still in a buffer. When it works, the code is already documented in latex and pdf (since the build/test automatically regenerates the pdf). I would like to see Clojure move toward literate programming and have direct support for reading and compiling latex documents. It is surprisingly efficient and effective. In my last 3 year project I implemented over 60k lines of lisp and 6k pages of documentation (with the embedded lisp code in literate form, of course). When the program was done, the documentation was done. In fact, that was true from the first day of the project and was an invariant throughout. I highly recommend it. Tim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Knuth's literate programming tangle function in Clojure
On 12/26/2010 8:33 PM, Robert McIntyre wrote: That's really cool. I was _just reading_ your comments from 2006 at http://www.mail-archive.com/gardeners@lispniks.com/msg01006.html and wondering about how hard something like this would be to write. If possible, could you expand on how one might use this in a development work-flow with emacs or texmacs? Is there some sort of lisp-pamphlet mode that could be extended to clojure? I'm assuming you've already solved all these problems and more while working with Axiom. I'd appreciate any pointers or best practices you might have found. Wow. That's an old reference. Most of those links are dead. Try http://en.wikipedia.org/wiki/Axiom_computer_algebra_system or http://axiom-developer.org As I mentioned in my other email on this subject I don't use Emacs modes. I don't want the computer editing my text. I just want it to do exactly what I told it to do. But I'm a curmudgeon :-) My style of programming is to change one thing and then do a complete system rebuild and test, which takes about 1 hour on my fastest machine, 5 on my slowest. I work a pipeline of changes so the build/test time is overlapped with changes. I can have up to 5 machines doing build/test while I'm working on the 6th change. (Git helps a LOT here. I strongly recommend git also.) I usually use a split screen with the literate latex document (I call it a pamphlet) in one buffer (not a slime setup) and the REPL in the other buffer. I use the REPL to hand-check the code before modifying the pamphlet. Thus, if (when :-)) it fails I know what I broke and where I broke it. When it works, the code is already documented in latex and pdf. The build/test automatically regenerates the pdf. The goal is to make the smallest change possible and concentrate on getting it right. It might require writing or updating test cases which are also in the same literate document under a test chunk name. The automated build extracts and runs all test chunks. So the essential loop is: edit the pamphlet in a split buffer define the functions in the REPL buffer change the function hand-test the change in the REPL update the pamphlet with the changed function write/update the test code save the pamphlet do a full system build and test check that the test pass check the pdf documentation The second step would be a lot easier if Clojure knew how to load a latex file. I'm thinking of writing a load-pamphlet function to do this. It could specify a chunk name to extract as in: (defn (load-pamphlet [file] (load-pamphlet file *)) (load-pamphlet [file chunk] (tangle file chunk))) Thus, to do step 2 above I just need to (load-pamphlet...) the file. I could run the tests with (load-pamphlet file test) \begin{rant}{ \tl;dr{Let's move programming out of the dark ages.} We of the Clojure community are trying hard to move Lisp out of the 60s programming model. We can also move programming out of the 60s code-then-maybe-document model. The Knuth technology is 30+ years old. When I started 40 years ago (http://www.dilbert.com/fast/2010-12-23/) we had limits like 8k of memory so no file was bigger than 4k. Thus, C programs were tiny piles of sand with include/overlay linkers/etc. Few of you have ever worked on a fully loaded PDP 11/40. Why do you program like you only have 4k? Now we can have a machine with 128Gig of memory. Its about time for programmers to lose the one function-one file idea based on keeping the machine happy. We need to think about one-program-one-document to keep the humans happy. For a perfect example, see the book: Lisp In Small Pieces by Christian Queinnec [1] Queinnec's book is my ultimate example. He MOTIVATES every piece of code that gets introduced and he talks about everything. The code contains a complete lisp system including the interpreter, compiler, and garbage collector. If you want to know lisp, read this book. If you want to learn literate programming, study this book. I want Clojure In Small Pieces, a literate form of Clojure that I can execute from the book. Then I can open to the chapter on PersistentHashMap and read all about log32 tries, why they matter, and how Clojure implements them, with literature references and a good index. Oh, yeah, and the ACTUAL code that gets executed. Forget the jar file. Send me the pamphlet containing Clojure. Programming will come out of the dark ages when we employ English majors as project leads with the title Editor in Chief. If you can explain it to an English major in text, you probably understand the problem :-) Let's move programming out of the dark ages. \end{rant} Tim Daly [1] http://www.amazon.com/Lisp-Small-Pieces-Christian-Queinnec/dp/0521545668 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe
Re: printf output from threads
justinhj justi...@gmail.com writes: I tried passing *out* to my thread function and then binding it to *out* in the thread, and this works but then makes the threads execute one at a time, and I'm presuming that is because my use of *out* in the binding block is blocking for the other threads which use it. That doesn't sound right: binding itself never blocks. Can you post some example code where you see this behaviour? As I understand it binding conveyance should happen automatically in the upcoming 1.3 release (for futures and agents) but in 1.2 you can use bound-fn, or for better performance use binding explicitly as you suggested. (future-call (bound-fn [] (println log...))) (send some-agent (bound-fn [x] (println log...) (inc x))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en