FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful
I was using defrecord for the first time, to create a type that I wanted to throw+ via slingshot to signal errors from a library. I'd seen an example of this in another library, and I pretty much just cut and pasted it into my project. I understood that I need to explicitly import the resulting class into clients that use my library, and attempted to do so. When loading the client library that uses and imports, I got this: foo-bar.core.foo-bar-error [Thrown class java.lang.ClassNotFoundException] Restarts: 0: [QUIT] Quit to the SLIME top level Backtrace: 0: java.net.URLClassLoader$1.run(URLClassLoader.java:202) 1: java.security.AccessController.doPrivileged(Native Method) 2: java.net.URLClassLoader.findClass(URLClassLoader.java:190) 3: clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61) 4: java.lang.ClassLoader.loadClass(ClassLoader.java:306) 5: java.lang.ClassLoader.loadClass(ClassLoader.java:247) 6: java.lang.Class.forName0(Native Method) 7: java.lang.Class.forName(Class.java:169) 8: factmigrate.core$eval1645$loading__4414__auto1646.invoke(core.clj:1) 9: factmigrate.core$eval1645.invoke(core.clj:1) --more-- After a LOT of time and experimentation, I finally realized that in my import statement, I need to replace the hyphen character in my namespace (let's call my namespace foo-bar.core) to an underscore. So in a client of my library, it needs to do something like this (ns foobarclient.core (:use foo-bar.core) (:import foo_bar.core foo-bar-error)) Assuming that somewhere in the foo-bar.core namespace I had done something like this: (defrecord foo-bar-error [blah1 blah2]) I am still recovering from this debugging session, but my current thought is that this was all my fault, and I just need to be smarter about Java interop and naming issues. The hyphen/underscore issue is mentioned here: http://clojure.org/libs Lib Conventions Clojure defines conventions for naming and structuring libs: A lib name is a symbol that will typically contain two or more parts separated by periods. A lib's container is a Java resource whose classpath-relative path is derived from the lib name: The path is a string Periods in the lib name are replaced by slashes in the path Hyphens in the lib name are replaced by underscores in the path But I did not find this right away, and even after I did find it, it was not immediately obvious to me what the implication was in an import statement. So, I simply wanted to document this for the mailing list, in the hope of preventing others from stumbling into this, and maybe if they do, they will find this explanation in their searches… Don -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: stack overflow vs scheme
Hi, the Scheme version of quicksort is not tail-recursive since append is called on the return value of the recursive calls. Thus, also in Scheme this eats up your stack. That your Scheme code can sort larger sequences simple means that your Scheme implementation has a larger stack than the JVM with standard settings. Basically, the only difference between Scheme and Clojure with respect to tail-recursion is that Scheme automatically optimizes the recursive call when it appears in a tail-call position whereas in Clojure you have to explicitly call recur (or trampoline for mutual recursion) if you want tail-call optimization. Since quicksort requires two recursive calls which then have to be combined it is not completely trivial to implement it in a tail- recursive, i.e. iterative, fashion. There is a general method which can be applied, namely continuation passing style (CPS), but it might look a little odd if you haven't seen it before. Basically, you use a variable holding a chain of closures which resemble the stack. I found a rather nice exposition in this blog post: http://www.enrico-franchi.org/2011/09/clojure-quicksort-in-continuation.html Cheers, Nils On Dec 1, 6:09 pm, john.holland jbholl...@gmail.com wrote: I was studying clojure for a while, and took a break to work on SICP in scheme. I found that they do numerous things that are against advice in Clojure having to do with the tail recursion. I got to thinking about that Clojure recur/loop stuff and wondered how you would do a quicksort with it. So I went to rosetta code and looked at what they had for scheme and for clojure. In scheme I can do a quicksort which makes two calls to itself and it can scale pretty high before running out of RAM. I went up to 1 sorting from worst (reversed) order to forward order. I do get stack overflows beyond that though. In clojure, the same algorithm produces the dreaded StackOverflow after 1000 values. I tried giving the JVM a gig of RAM, no help. Below are the (trvial) procedures. I understand that the advice in clojure is to use loop/recur etc, however, a big part of the charm for me of something like scheme is that I can write code that is a straightforward statement of a mathematical approach to the problem. Although quicksort is really simple, the idea of doing it with loop/recur baffles me. After a while with the scheme stuff clojure seems very complex and this, which seems like a fundamental issue, is not going well for it. Can anyone post a quicksort that doesn't give stack overflows in clojure? John scheme quicksort (define (quicksort l) (if (null? l) '() (append (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) ) (list (car l)) (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) =scheme utility to make data sets (define (nums x) (if ( x 0) '() (cons x (nums (- x 1) ==scheme call= (quicksort (nums 1)) ===clojure quicksort (defn qsort [[pivot xs]] (when pivot (let [smaller #( % pivot)] (lazy-cat (qsort (filter smaller xs)) [pivot] (qsort (remove smaller xs)) =clojure utility to make data sets (def nums (fn [lim] (loop [limx lim acc []] (if ( limx 0) acc (recur (- limx 1) (cons limx acc)) clojure call== (quicksort (nums 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
[ANN] slacker 0.1.0: RPC by clojure and for clojure
Glad to announse the first release of slacker. Slacker is an RPC framework for clojure. It provides a set of non-invasive, transparent APIs for both server and client. You can switch between remote invocation and local invocation effectivly. Different from remote eval approach, slacker is faster and securer because you only expose what you like to (all public functions under a namespace). Currently, slacker runs on aleph(transport) and carbonite(serialization). The 0.1.0 has been pushed to clojars. [info.sunng/slacker 0.1.0] You can find the project on github. There are some examples. https://github.com/sunng87/slacker If you have any suggestion about this project, feel free to get connected with github or from this mailing list. Enjoy. -- Sun Ning Software developer Nanjing, China (N32°3'42'' E118°46'40'') http://about.me/sunng/bio -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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
On Fri, Dec 2, 2011 at 12:33 AM, Glen Stampoultzis gst...@gmail.com wrote: I noticed that when I create a reference (zk-ref) I need to provide an initial value. For each VM I do this for - it ends up clobbering the previous value. Is there anyway to create a reference without necessarily clobbering existing data? You don't need to supply an initial value. I had to look at the source to figure that out, though. Leaving off the value will just create a reference to an already existing ref. See the second set of arguments here: https://github.com/liebke/avout/blob/master/src/avout/core.clj#L59 Chris -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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
Hi Glen, The init-stm step is still referenced in the documentation as being required BTW. Thanks, I'll remove the reference. I had a couple of questions. I noticed that when I create a reference (zk-ref) I need to provide an initial value. For each VM I do this for - it ends up clobbering the previous value. Is there anyway to create a reference without necessarily clobbering existing data? Yep, like Chris said, you can just leave off the initial value when creating a Ref or Atom, just like with the in-memory versions. My second question is to do with derefs. The documentation says that Avout caches multiple derefs and that it will invalidate the cache when the ref is locally or remotely updated. My own testing seems to indicate that the deref still see the old values after a remote change is made. If I wrap the deref in a dosync!! however that seems to trigger the invalidation and I see the correct value. Am I missing something? I can't reproduce this behavior, can you provide a code snippet where the cache isn't getting invalidated and maybe some additional details on your setup? 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: Implementing a clojure-only periodic timer...
On Dec 1, 2011, at 11:02 PM, Benny Tsai wrote: Overtone's 'at-at' library is a thin Clojure wrapper over ScheduledThreadPoolExecutor with a nice interface. I think you should be able to build a timer on top of it pretty easily. https://github.com/overtone/at-at Thanks Benny; I went with the approach that gaz suggested as it's exactly what I needed -- however any excuse to play with anything related to overtone is +1 :-) bill -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: ClojureCLR PInvoke and DLLImport attribute
If you could give me a small example of how you would like to use this, I can take a look. I suggest you read Miguel de Icaza's blog entry here about using dynamic and pinvoke. The concept is quite simple. Basically you have to generate a method on-the-fly and tag it with the correct attributes, then simply use that method to call the pinvoke routines. http://tirania.org/blog/archive/2009/Aug-11.html The one thing to note though, is the above blog uses the CallingConventions enum value for Linux. Windows has standardized on a different calling convention, so you may have to dynamically switch to the correct enum value depending on the platform. From there it should be possible to setup something like this (Pinvoke info taken from http://pinvoke.net/default.aspx/user32.MessageBox): (defdllimport user32 user32.dll :char-set-auto) (def message-box (extern user32 ^Integer MessageBox [^Integer hWind ^String text ^String caption ^Integer options])) Anyway, just some ideas. Timothy -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Errors w/ dynamic symbols in macro-utils or monads?
Does this still happen for you? It appears to still be the case in my environment. Dropping back to Clojure *1.2.1* seems to work but in addition to trying out monads, I need to use a library (clj-webdriver) that relies on Clojure *1.3.0* What to do? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Errors w/ dynamic symbols in macro-utils or monads?
ah: http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go clojure.contrib.monads - Migrated to clojure.algo.monads - lead Konrad Hinsenhttp://dev.clojure.org/jira/secure/ViewProfile.jspa?name=khinsen . - Status: latest build statushttp://build.clojure.org/job/algo.monads-test-matrix/, latest release on Mavenhttp://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22algo.monads%22, report bugs http://dev.clojure.org/jira/browse/ALGOM. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
ANN: Clarity 0.5.1 - New GUI library
Hello everyone, I would like to announce the first release of Clarity (v0.5.1), a Swing-based GUI library. It's available on github and through clojars: https://github.com/stathissideris/clarity [clarity 0.5.1] Also, here's an introductory talk (will only play as embedded unfortunately): http://skillsmatter.com/podcast/scala/lightening-talk-clarity-a-wrapper-for-swing Finally, a couple of tutorial-style pages from the wiki: https://github.com/stathissideris/clarity/wiki/Component https://github.com/stathissideris/clarity/wiki/Forms This is a new library and I coule really use some feedback on the syntax, the features, and maybe even the code. Thanks, Stathis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
[ANN] Nimrod 0.3: log-based metrics server
Nimrod is a lightweight, not invasive, metrics server written in Clojure and based on log processing: version 0.3 provides several new features and enhancements, the most important one being a brand new metrics store which can be either volatile, for short-living metrics, or persistent, for nearly unlimited metrics and back-in-time history. Other relevant enhancements are custom log identifiers, allowing users to manually assign a custom name to processed logs, and an improved REST interface. Read about it and download at: https://github.com/sbtourist/nimrod Provide your feedback at: http://groups.google.com/group/nimrod-user Sergio B. -- Sergio Bossa http://www.linkedin.com/in/sergiob -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful
Given that this seems to bite quite a few people who try to use defrecord / import (even if it only bites them once), perhaps it would be a nice enhancement for import to allow hyphen and automatically translate it to underscore in the package / namespace? It seems very inconsistent given that the record name _can_ have hyphens, according to Don's tests... (I haven't run into this, having not used defrecord, so I'm making this suggestion based purely on observing people complain about this sort of thing...) Sean On Fri, Dec 2, 2011 at 1:44 AM, Don Jackson cloj...@clark-communications.com wrote: I was using defrecord for the first time, to create a type that I wanted to throw+ via slingshot to signal errors from a library. I'd seen an example of this in another library, and I pretty much just cut and pasted it into my project. I understood that I need to explicitly import the resulting class into clients that use my library, and attempted to do so. When loading the client library that uses and imports, I got this: foo-bar.core.foo-bar-error [Thrown class java.lang.ClassNotFoundException] Restarts: 0: [QUIT] Quit to the SLIME top level Backtrace: 0: java.net.URLClassLoader$1.run(URLClassLoader.java:202) 1: java.security.AccessController.doPrivileged(Native Method) 2: java.net.URLClassLoader.findClass(URLClassLoader.java:190) 3: clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61) 4: java.lang.ClassLoader.loadClass(ClassLoader.java:306) 5: java.lang.ClassLoader.loadClass(ClassLoader.java:247) 6: java.lang.Class.forName0(Native Method) 7: java.lang.Class.forName(Class.java:169) 8: factmigrate.core$eval1645$loading__4414__auto1646.invoke(core.clj:1) 9: factmigrate.core$eval1645.invoke(core.clj:1) --more-- After a LOT of time and experimentation, I finally realized that in my import statement, I need to replace the hyphen character in my namespace (let's call my namespace foo-bar.core) to an underscore. So in a client of my library, it needs to do something like this (ns foobarclient.core (:use foo-bar.core) (:import foo_bar.core foo-bar-error)) Assuming that somewhere in the foo-bar.core namespace I had done something like this: (defrecord foo-bar-error [blah1 blah2]) I am still recovering from this debugging session, but my current thought is that this was all my fault, and I just need to be smarter about Java interop and naming issues. The hyphen/underscore issue is mentioned here: http://clojure.org/libs Lib Conventions Clojure defines conventions for naming and structuring libs: A lib name is a symbol that will typically contain two or more parts separated by periods. A lib's container is a Java resource whose classpath-relative path is derived from the lib name: The path is a string Periods in the lib name are replaced by slashes in the path Hyphens in the lib name are replaced by underscores in the path But I did not find this right away, and even after I did find it, it was not immediately obvious to me what the implication was in an import statement. So, I simply wanted to document this for the mailing list, in the hope of preventing others from stumbling into this, and maybe if they do, they will find this explanation in their searches… Don -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: Clarity 0.5.1 - New GUI library
Hi Stathis, Nice presentation and the library looks interesting. One question, when do you think it will be ported to 1.3? Regards, Doug On Fri, Dec 2, 2011 at 12:55 PM, Stathis Sideris side...@gmail.com wrote: Hello everyone, I would like to announce the first release of Clarity (v0.5.1), a Swing-based GUI library. It's available on github and through clojars: https://github.com/stathissideris/clarity [clarity 0.5.1] Also, here's an introductory talk (will only play as embedded unfortunately): http://skillsmatter.com/podcast/scala/lightening-talk-clarity-a-wrapper-for-swing Finally, a couple of tutorial-style pages from the wiki: https://github.com/stathissideris/clarity/wiki/Component https://github.com/stathissideris/clarity/wiki/Forms This is a new library and I coule really use some feedback on the syntax, the features, and maybe even the code. Thanks, Stathis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: ANN: Clarity 0.5.1 - New GUI library
Well, there isn't much preventing it from being 1.3. It used to be blocked by the dependency to clojure.contrib.miglayout, but then Stephen Gilardi released artem (https://github.com/scgilardi/artem) which provided a way out. I think it's probably a matter of days before I get a version that's compatible with Clojure 1.3, although I'm investigating how it would be possible to have 1.2 and 1.3 compatibility from one codebase. Thanks, Stathis On Dec 2, 7:21 pm, Doug South doug.so...@gmail.com wrote: Hi Stathis, Nice presentation and the library looks interesting. One question, when do you think it will be ported to 1.3? Regards, Doug On Fri, Dec 2, 2011 at 12:55 PM, Stathis Sideris side...@gmail.com wrote: Hello everyone, I would like to announce the first release of Clarity (v0.5.1), a Swing-based GUI library. It's available on github and through clojars: https://github.com/stathissideris/clarity [clarity 0.5.1] Also, here's an introductory talk (will only play as embedded unfortunately): http://skillsmatter.com/podcast/scala/lightening-talk-clarity-a-wrapp... Finally, a couple of tutorial-style pages from the wiki: https://github.com/stathissideris/clarity/wiki/Component https://github.com/stathissideris/clarity/wiki/Forms This is a new library and I coule really use some feedback on the syntax, the features, and maybe even the code. Thanks, Stathis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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
RFC, data manipulation program
Hi All, We are working on a data manipulation application. The idea is that a user should be able to set up a pipeline with one or more input files (eg. a database, csv, spreadsheet, json/XML, etc), one or more transformations of data (eg. merging, renaming, aggregating, search/replace, etc), and finally output to one or more files (eg. database, csv, spreadsheet, json/XML, etc) - basically a program that can do most of the stuff that Talend Open Studio can do, but less bloated. A quick, simple use case: A user has a spreadsheet with name and addresses. He wants to separate addresses different entities (ZIP, Street name, country) and output this into different tables of a MySQL database. We are attempting to build this in clojure (the backend that is - then at some point in the future build a nice GUI for it) We have a basic program and data structure with a few examples github: https://github.com/kij/grotesql We are writing to this list hoping to get some constructive criticism and comments on stuff like: * Does our data representation make sense? * Does our partial-function-pipeline scheme make sense? * Have we overlooked something obvious that means our current approach is terrible and useless? * Comments, ideas, recommendations, thoughts, etc. I believe our code is fairly straight forward, when looked at along with the examples in the doc/ folder.. but just a few words about the structure of the program: * Data is represented as a list of maps, eg: '( { :name Peter, :age 30 } { :name Jones, age: 50 } ...) * Data manipulation is done by using small concise functions (simple stuff like: join column X Y values, rename column X, search/replace column X) - these functions are then used as 'building blocks' to achieve more complex transformations. All functions take one or more parameters with the last parameter being input data. Functions returns the manipulated data as output. * A program is built by creating a list (pipeline) with the following structure: first entry is an input node (a function that fetches data from external source and returns the data), the last entry is an output node (a function that takes data as only input, and has no return value), and everything in between are data manipulation nodes (functions that takes a single input - the data, and spits out the manipulated data). * The list is built by adding curryed functions - so for example, if we have a data manipulating function: rename-column [ oldname newname data ] (...), the function specific parameters are filled out before adding it to the list: (partial rename-column :someoldname :somenewname) - which leaves a function that takes data as a single input, and gives manipulated data as it's output - the requirements for a data manipulation functions in the list. * When one has the pipeline, say '(input manip-a manip-b manip-c output) ready it will be run like: (output (manip-c (manip-b (manip-a (input). As desired, this will pass the data from input, through each of the manipulatiing functions, and finally to the output function. We have only just started the development, so what's in the repository is mostly proof of concept stuff, but it's working and should be enough to give an idea. We are both new to both functional programming and clojure, so any thoughts about the questions above or any pointers in general would be highly appreciated. Thanks, Kasper and Kevin -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Agents vs. Actors
Hi, how do Clojure agents relate to Erlang actors? To gain some insights, I tried to implement Erlang style message passing between agents. The first version is just a very incomplete sketch (no mailbox, case instead of pattern matching ...), but already shows that it is quite easily doable: https://github.com/bertschi/clojure-stuff/blob/master/src/stuff/actors.clj The idea is that the agent holds a dispatch function which is then called by ! (send) with the message to be send. Somehow it resembles the way closures can be used to implement an object system. Thus, agents seem to be the functional analog of agents: Functional programming Object-oriented programming sequential closure object concurrent agent actors Another great design from Rich Hickey! Clojure is fun and gets better every day ... Thanks, Nils -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can't get the debugger cdt run
The namespace have been restructured so 'com.georgesjahad.cdt doesn't exist anymore. The easiest way to use cdt is from emacs, as described here: http://georgejahad.com/clojure/swank-cdt.html Hugo Duncan also has a separate emacs based clojure debugger called Ritz, described here: https://github.com/pallet/ritz On Nov 29, 2:29 pm, svenali sven...@gmx.de wrote: Hello all, I try to get the cdt debugger running and fail. I've build the cdt with leiningen and have this jar file in my classpath. A simple (use 'cdt.break) work. But if I want to use com.georgesjahad.cdt I get the following error message: = (use 'com.georgesjahad.cdt) #FileNotFoundException java.io.FileNotFoundException: Could not locate com/georgesjahad/cdt__init.class or com/georgesjahad/cdt.clj on classpath: But a = (use 'cdt.ui) nil work. Where is my problem? regards, Sven -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Rebinding a recursive function
2011/12/1 Stuart Sierra the.stuart.sie...@gmail.com Do I understand correct that the only way to hook a recursive function without affecting other threads is to annotate the function with ^{:dynamic true} and call it via #'fact? If you want to you dynamic rebinding, yes. There are other possibilities, however. Maybe you could pass the function in as an argument. Maybe you could use 'trampoline' and *return* the recursive function. The point is, if you want to be able to alter something at runtime, see if you can do it through ordinary means before going to dynamic Vars. It will be faster and possibly easier to understand. Thanks, Stuart. That's a good advice. Roman. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: stack overflow vs scheme
Thanks for all the replies. It seems to me that as general solutions to stack overflow, trampoline and recur are very valuable. I had gotten the mistaken idea that Scheme was somehow immune to the problem. My experiments in Scheme seemed to get to higher amounts of recursion before blowing up than my Clojure did, but they are both susceptible to it. Are there things like trampoline and recur in Scheme? In Lisp? John Holland -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Agents vs. Actors
how do Clojure agents relate to Erlang actors? There are several important differences: 1. Agents are designed for in-process communication only. 2. Observing the state of an Agent does not require sending it a message. 3. Agents accept arbitrary functions instead of a predefined set of messages. -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
Re: FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful
Clojure 1.3 mitigates this problem somewhat by defining public constructor functions for record types, so you can use/require the namespace and call the constructor functions. Then the class names are only needed for interop or type hints. Clojure 1.2.0 had a bug (CLJ-432) whereby hyphens in record names did NOT get converted into underscores. This was fixed in 1.2.1. -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
Re: FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful
On Fri, Dec 2, 2011 at 1:44 AM, Don Jackson cloj...@clark-communications.com wrote: I was using defrecord for the first time, to create a type that I wanted to throw+ via slingshot to signal errors from a library. For what it's worth, the main point of slingshot is removing the necessity of creating custom classes for exceptions, so this shouldn't be necessary in the first place. -Phil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Agents vs. Actors
Hi Stuart, thanks for the info. I did not really think about some of these differences. Basically, it was just a fun exercise ... not (yet) useful for anything serious. On Dec 2, 10:14 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: how do Clojure agents relate to Erlang actors? There are several important differences: 1. Agents are designed for in-process communication only. Right, whereas Erlang actors are distributed. This was not so important for me at the moment. 2. Observing the state of an Agent does not require sending it a message. Good point, I must have forgotten that ... maybe this makes agents actually more general than actors? 3. Agents accept arbitrary functions instead of a predefined set of messages. That is true, but I was wondering whether it is possible to simulate Erlang style messages with this. In my sketch the state of an agent is a handler function which only accepts a limited set of messages. Seems to be a close fake of Erlang actors (and reading the state without sending a message as in 2. is not very useful since it only returns the handler function ... calling this function then acts as a send). -S Best, Nils -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: stack overflow vs scheme
On Dec 2, 8:13 pm, john.holland jbholl...@gmail.com wrote: Thanks for all the replies. It seems to me that as general solutions to stack overflow, trampoline and recur are very valuable. I had gotten the mistaken idea that Scheme was somehow immune to the problem. My experiments in Scheme seemed to get to higher amounts of recursion before blowing up than my Clojure did, but they are both susceptible to it. Are there things like trampoline and recur in Scheme? In Lisp? Well yes, but they are not explicitly specified since Scheme automatically optimizes tail calls. Consider this example: (define (fact n) (if ( n 2) 1 (* n (fact (- n 1) This is not tail recursive and eventually blows the stack ... in Scheme and in Clojure. (define (fact-accu n res) (if ( n 2) res (fact-accu (- n 1) (* n res Here, the recursive call is in tail position and gets optimized by the Scheme compiler. In Clojure you would have to call recur instead, otherwise your stack grows. In Scheme this is not necessary since the optimization is always done if possible. Thus, there is no special syntactic marker, i.e. reserved word, for this. (Same holds for mutual recursion - trampoline). In Common Lisp the situation is somewhat unfortunate, since tail call optimization is implementation dependent. So, you cannot rely on it and therefore loop/tagbody etc are your friends there. Hope this helps, Nils John Holland -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: ClojureCLR PInvoke and DLLImport attribute
Fiel's problem was a little simpler -- his dllimport method was out in C# class that was imported. The problem appears to be that reflection is not finding the method. That is likely either a signature-matching problem (declared args vs supplied params) or even just having the flags set a little wrong on the Type.GetMethods in the reflection code so that the dllimport method is excluded. Should be an easy fix. Doing it all in Clojure as you suggest -- I'll work on it. Actually, the de Icaza blog entry is priceless. It has actual DLR code that can be, er, um, mined for ideas. Thanks for the link. -David On Dec 2, 9:59 am, Timothy Baldridge tbaldri...@gmail.com wrote: If you could give me a small example of how you would like to use this, I can take a look. I suggest you read Miguel de Icaza's blog entry here about using dynamic and pinvoke. The concept is quite simple. Basically you have to generate a method on-the-fly and tag it with the correct attributes, then simply use that method to call the pinvoke routines. http://tirania.org/blog/archive/2009/Aug-11.html The one thing to note though, is the above blog uses the CallingConventions enum value for Linux. Windows has standardized on a different calling convention, so you may have to dynamically switch to the correct enum value depending on the platform. From there it should be possible to setup something like this (Pinvoke info taken fromhttp://pinvoke.net/default.aspx/user32.MessageBox): (defdllimport user32 user32.dll :char-set-auto) (def message-box (extern user32 ^Integer MessageBox [^Integer hWind ^String text ^String caption ^Integer options])) Anyway, just some ideas. Timothy -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
delayed recursive macro expansion?
Is there a way for a macro m to expand into code that includes another delayed use of m such that this second use of m is only expanded if needed (and thus avoiding a stack overflow)? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: delayed recursive macro expansion?
Andrew ache...@gmail.com writes: Is there a way for a macro m to expand into code that includes another delayed use of m such that this second use of m is only expanded if needed (and thus avoiding a stack overflow)? What exactly are you trying to do? Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: delayed recursive macro expansion?
(defmacro interactive-try If expr results in an exception, prompt the user to retry or give up. The user can execute arbitrary code somewhere else or fiddle with a DB before retrying. Returns nil if the user gives up. [expr] `(try ~expr (catch Exception e# (- (ui/dialog :option-type :yes-no :resizable? false :content (str An exception occurred:\n e# \n\nRetry this step?\n '~expr) :title Retry? :success-fn (fn [_#] *(interactive-try ~expr)*) :no-fn (fn [_#] nil)) ui/pack! ui/show! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 few enhancements
On Thursday, December 1, 2011 8:23:33 PM UTC+1, Alan Malloy wrote: 1) I agree this seems silly but I don't think it's ever bitten me Ain't this the difference between a language, that's been around for QAW (Quite A While, maybe even long enough to become a standard, e.g. ANSI) and a newcomer which will find all the rough edges when being used by more people? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful
Hi, to be honest I'd rather not see any magic behavior of the importing mechanism. Better to fail early, but with a suitable error message, no? Cheers, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 is the different between = and identical ?
On Friday, December 2, 2011 8:44:07 AM UTC+1, Tassilo Horn wrote JVM does some sort of pooling. It seems there's exactly one Long for any long value in the range [-128...127], but you shouldn't rely on that. And I always thought it was 1024, but user= (identical? 127 127) true user= (identical? 128 128) false user= *clojure-version* {:major 1, :minor 2, :incremental 1, :qualifier } :-) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: delayed recursive macro expansion?
Well, I found a way to dodge that need. But still interested in whether it's possible. Here's my dodge. Ugly and proud. (defmacro itry If expr results in an exception, prompt the user to retry or give up. The user can execute arbitrary code somewhere else or fiddle with a DB before retrying. Returns nil if the user gives up. [expr] `(loop [result# :success] (case result# :no nil :success (recur (try ~expr (catch Exception e# (- (ui/dialog :option-type :yes-no :content (str An exception occurred:\n e# \n\nRetry this step?\n '~expr) :title Retry?) ui/pack! ui/show! result#))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 to deal with parameters unused by intermediate functions?
Hi, I have a public function foo that uses two private functions bar and baz. So foo calls bar which calls baz. Two of the parameters passed to foo aren't used by bar, only baz. Though the segregation of behavior across foo, bar, and baz makes sense for my program, I feel dirty making the params required by baz a part of bar's signature. Should I just get over it or is there a better way? Thanks, 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
Clojure + Java Interop + Gnome Interop -- KeyPressEvent fails
So, I've been dipping my toe in the waters of Clojure UI development using Gnome, and I immediately ran in into a problem making me regret my years of Java apathy. I'm trying to write a toy program to processes generic key presses made to the Gnome window and I'm stuck as to how to translate the straight forward Java + Gnome interop into Clojure + Gnome Interop. Here are the relevant pieces: w = new Window(); l = new Label(bStart Typing!/b\n + Start typing and details about\n + your KeyEvents will\n + appear on the console.); l.setUseMarkup(true); w.add(l); w.connect(new Widget.KeyPressEvent() { public boolean onKeyPressEvent(Widget source, EventKey event) { final Keyval key; final ModifierType mod; key = event.getKeyval(); mod = event.getState(); System.out.print(Pressed: + key.toString() + , ); System.out.print(Modifier: + mod.toString() + ); if (mod == ModifierType.SHIFT_MASK) { System.out.print(That's Shifty!); } if (mod.contains(ModifierType.ALT_MASK)) { System.out.print(Hooray for Alt!); } if (mod.contains(ModifierType.SUPER_MASK)) { System.out.print(You're Super!); } System.out.println(); return false; } }); And in Clojure: ... (let [w (Window.) ... (.connect w (proxy [Widget$KeyPressEvent] [] (onKeyPressEvent [source event] (println (str I was clicked: (.getLabel b))) )) (proxy [Window$DeleteEvent] [] (onDeleteEvent [source event] (Gtk/mainQuit) false) (onDeleteEvents [source event] (Gtk/mainQuit) false) )) ... And here's what I'm trying to do with it: (defn pushme [] (let [w (Window.) v (VBox. false 3) l (Label. Go ahead:\nMake my day) b (Button. Press me!)] (.connect b (proxy [Button$Clicked] [] (onClicked [source] (println (str I was clicked: (.getLabel b))) (println (str I was clicked: source)) ))) (.connect w (proxy [Widget$KeyPressEvent] [] (onKeyPressEvent [source event] (println (str I was clicked: (.getLabel b))) )) (proxy [Window$DeleteEvent] [] (onDeleteEvent [source event] (Gtk/mainQuit) false) (onDeleteEvents [source event] (Gtk/mainQuit) false) )) (.add v l) (.add v b) (.add w v) (.setDefaultSize w 200 100) (.setTitle w Push Me) (.showAll w) (Gtk/main) ) ) Results in: Exception in thread main java.lang.RuntimeException: java.lang.ClassNotFoundException: org.gnome.gtk.Window$KeyPressEvents at clojure.lang.Util.runtimeException(Util.java:153) at clojure.lang.Compiler.eval(Compiler.java:6417) at clojure.lang.Compiler.eval(Compiler.java:6396) at clojure.lang.Compiler.load(Compiler.java:6843) at clojure.lang.Compiler.loadFile(Compiler.java:6804) at clojure.main$load_script.invoke(main.clj:282) at clojure.main$script_opt.invoke(main.clj:342) at clojure.main$main.doInvoke(main.clj:426) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.lang.Var.invoke(Var.java:401) at clojure.lang.AFn.applyToHelper(AFn.java:161) at clojure.lang.Var.applyTo(Var.java:518) at clojure.main.main(main.java:37) Caused by: java.lang.ClassNotFoundException: org.gnome.gtk.Window$KeyPressEvents at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:186) at user$eval21.invoke(main.clj:8) at clojure.lang.Compiler.eval(Compiler.java:6406) Any thoughts or suggestions would be appreciated. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: stack overflow vs scheme
Quoth john.holland on Sweetmorn, the 44th of The Aftermath: It seems to me that as general solutions to stack overflow, trampoline and recur are very valuable. I had gotten the mistaken idea that Scheme was somehow immune to the problem. Trampoline and recur are a poor man's tail-call-optimization; and, if by the problem, you mean that a call-stack grows linearly with its recursive depth: yeah, even Scheme is susceptible to stack-growth if your calls aren't properly tail-recursive. See R5RS s. 3.5 [1], Proper tail recursion: A tail call is a procedure call that occurs in a tail context; e.g. the last expression within the body of a lambda expression. William Clinger wrote a paper that formalizes proper tail recursion in more depth [2]. Suffice to say, the naïve recursive implementation of quick sort contains at least one non-tail-call; and, just for kicks, here's an implementation of quicksort in Joy (a so-called concatenative language): [small] [] [uncons [] split] [swapd cons concat] binrec Joy, too, implements recursion (through `binrec') without growing the call-stack. Footnotes: [1] http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-6.html#%_sec_3.5 [2] ftp://ftp.ccs.neu.edu/pub/people/will/tail.pdf -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Odd error evaling
Hi Clojurians, I hit the following error today. My environment is Clojure 1.3 (eval (read-string (clojure.repl/source-fn 'keep-indexed))) #CompilerException java.lang.ClassCastException: clojure.lang.Compiler $InvokeExpr cannot be cast to clojure.lang.Compiler$ObjExpr, compiling: (NO_SOURCE_PATH:1) Do other people get the same exception? If so what am I doing wrong? Regards Nathan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can't get the debugger cdt run
On Fri, Dec 2, 2011 at 12:37 PM, George Jahad cloj...@blackbirdsystems.net wrote: The easiest way to use cdt is from emacs, as described here: http://georgejahad.com/clojure/swank-cdt.html Could you add a note to clarify that connecting as usual to a swank server is via the Emacs slime-connect command since I had to ask on IRC? This is the first time I've tried CDT and I have to say, I'm very impressed with how easy it is to use! Thank you!! -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
running foo.clj no main?? install clojure
i coded the foo.clj program = (ns foo) (defn hello [x] (println Hello, x)) (if *command-line-args* (hello command line) (hello REPL)) = I run this line java -cp c:/opt/jars/clojure.jar:. clojure.main foo.clj I get it can't find clojure.main = I created the c:/opt/jars folders and put clojure.jar and clojure.contrib.jar in it. . What is the best way to install clojure??? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en