Re: 1.2 contrib shuffles
I downloaded Clojure Contrib Stable 1.2 from http://github.com/downloads/clojure/clojure-contrib/clojure-contrib-1.2.0.zip And builded with mvn package. The results are: Testing clojure.contrib.test-io FAIL in (test-as-url) (test_io.clj:21) expected: (= (URL. file:/foo) (as-url (File. /foo))) actual: (not (= #URL file:/foo #URL file:/C:/foo)) FAIL in (test-relative-path-string) (test_io.clj:40) absolute path strings are forbidden expected: (thrown? IllegalArgumentException (relative-path-string (str File/sepa rator baz))) actual: nil FAIL in (test-relative-path-string) (test_io.clj:44) absolute File paths are forbidden expected: (thrown? IllegalArgumentException (relative-path-string (File. (str Fi le/separator quux actual: nil Testing clojure.contrib.test-profile FAIL in (test-print-summary) (test_profile.clj:7) doesn't blow up with no data (assembla #31) expected: (= Name mean min max count sum\n (with-ou t-str (print-summary {}))) actual: (not (= Name mean min max count sum\n Na me mean min max count sum\r\n)) Ran 365 tests containing 1300 assertions. 4 failures, 0 errors. [INFO] [ERROR] BUILD ERROR [INFO] [INFO] Clojure failed. [INFO] [INFO] For more information, run Maven with the -e switch [INFO] [INFO] Total time: 26 seconds [INFO] Finished at: Mon Aug 30 11:01:35 CEST 2010 [INFO] Final Memory: 13M/31M [INFO] On 27 August 2010 16:02, B Smith-Mannschott bsmith.o...@gmail.com wrote: What test failures are you seeing? I'm not seeing any building github.com/clojure/clojure-contrib 1.2.0-RC3 (e4ea06c9ff93df3b3f667ab5768618ece5a98b6e). Ran 365 tests containing 1298 assertions. 0 failures, 0 errors. [INFO] [INFO] BUILD SUCCESSFUL // Ben On Fri, Aug 27, 2010 at 15:25, Michael Jaaka michael.ja...@googlemail.com wrote: Agree with Daniel Janus. There are some conflicts without any reason. This should be cleaned up for 1.2.1 version. More over when I build clojure-contrib-1.2.jar I get 4 failures on tests due to. It shouldn't appear in a final versions. All contributors and Rick do a great job but you should think about some QA. On 27 Sie, 15:20, B Smith-Mannschott bsmith.o...@gmail.com wrote: On Fri, Aug 27, 2010 at 13:54, Daniel Janus nath...@gmail.com wrote: Hi, so I finally got around to port my app to Clojure 1.2 and got confused about the contrib shuffles. There's clojure.java.io and clojure.contrib.io. The docs on the latter says that most of the functions defined in there are deprecated, and one should use clojure.java.io instead. But clojure.java.io lacks some of the very useful macros and function I'm using, like with-in-reader, with-out-writer, slurp*, to name but a few; clojure.contrib.io does have them, but it relies on its own primitives, instead of building on clojure.java.io. So in a way I'm committed to using (if indirectly) code that is already deprecated. What are the plans for contrib development in this case? with-out-writer and with-in-reader do indeed seem to be missing. By hand, this would be e.g. (with-open [r (io/reader x)] (binding [*in* r] (read))) But that seems like the kind of boiler-plate a macro or function should be provided for... On a side note: shouldn't slurp* and slurp be unified somehow in a future release? The slurp in clojure 1.2 corehttp:// clojure.github.com/clojure/clojure.core-api.html#clojure.core/... now properly supports encoding by passing :encoding. For example: (slurp path :encoding UTF-8) Also, contrib 1.2's str-utils contains the following confusing comment at the very top: ;; DEPRECATED in 1.2: Promoted to clojure.java.string. Note that ;; many function names and semantics have changed I believe clojure.string (in Clojure 1.2.0) is what was meant. whereas there's no such thing as clojure.java.string. Daniel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com clojure%2bunsubscr...@googlegroups.comclojure%252bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You
Re: 1.2 contrib shuffles
On 28 Sie, 07:00, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Aug 27, 3:42 pm, B Smith-Mannschott bsmith.o...@gmail.com wrote: This thread got me thinking that when a namespace is partially promoted to Clojure proper, it might be good to provide a reduced version of the old namespace, providing just the functionality that was not promoted as an alternative to complete removal. Speaking as their author, c.c.io and c.c.str* should be removed completely. If a function or macro didn't get promoted to Clojure proper, it is because it was poorly written or redundant. Could you elaborate? What is redundant or poor about with-out-writer and with-in-reader? Daniel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Problem reloading source file with imports
Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit the source file and remove the (:use ...) clause and then try to load the file again. Anyone have any idea what is going on? I didn't see this behaviour in Clojure 1.1 and it would be nice if I could find a way to reload files that I'm working on. Cheers, 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: NullPointerExecption after Java class import
Indeed if exception is thrown in static initializer block then clojure import throws exception as well. The following class will cause this: package aaa; public class Test { static{ Object o = null; o.toString(); } } Then in clojure: (ns x (:import (aaa Test)) Results in: Exception in thread main java.lang.ExceptionInInitializerError (core.clj:1) Why does this happen in clojure? If you do the same in java, import aaa.Test, then nothing happens. NLP will be thrown when you actualy try to initialize the class. On Aug 30, 6:12 am, Stuart Campbell stu...@harto.org wrote: Hello, I don't know this library specifically, but the NPE is probably occurring in a static initialisation block. I believe static initialisation occurs when the class is first loaded. Regards, Stuart On 30 August 2010 06:42, zm zygiman...@medelis.lt wrote: I am using GATE java libs in my clojure code and behaviour of the application changes after Java class import. I don't even have to initialize it. This runs fine (a bit shorter version than it is): (ns gate (:import (gate Gate) (java.io File))) (defn gate-init [gate-home] (Gate/setGateHome (File. gate-home)) (Gate/init))) Now if I import gate.Factory class, like this (gate Gate Factory), I get the exception: Caused by: java.lang.NullPointerException at gate.Factory.createResource(Factory.java:154) How can import of a class cause this? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that 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: Problem reloading source file with imports
Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. If you accidently get this warning and don't want to restart the repl you can do (ns-unmap 'your-namespace 'offending-function), fix the naked import, and reload. --Robert McIntyre On Mon, Aug 30, 2010 at 5:54 AM, Chris Jenkins cdpjenk...@gmail.com wrote: Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit the source file and remove the (:use ...) clause and then try to load the file again. Anyone have any idea what is going on? I didn't see this behaviour in Clojure 1.1 and it would be nice if I could find a way to reload files that I'm working on. Cheers, 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 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Is it possible in theory to write/modify a Clojure compiler that doesn't
All~ There was a presentation at the JVM language summit about this exact topic. http://wiki.jvmlangsummit.com/Mixed_language_project_compilation_in_Eclipse:_Java_and_Groovy http://wiki.jvmlangsummit.com/Mixed_language_project_compilation_in_Eclipse:_Java_and_GroovyIn fact, the person was looking for more people to help contribute implementations for other languages to work together on this. Matt On Sun, Aug 29, 2010 at 5:44 PM, Robert McIntyre r...@mit.edu wrote: I don't think two pases is enough. What if a clojure file uses reflection (with macros of course) on a compiled java file to generate classes, sort of like how lancet works but generating classes instead of functions? And then those classes are used from other clojure and java files. Oh, and then another clojure file does the same reflection based junk to make more classes, from the classes that were generated from the first clojure file. These classes are, of course, used by other java and clojure files. In this case the only way I can think to compile everything (and sadly I'm doing something like this on my current project in lieu of a better way) is to: try to compile all the java files first (fail at some), try to compile all the clojure files (fail at some), try to compile all the java files (fail at some, but a little bit less than the first time), repeat until bytecode-level quiescence. The clojure compiler and java compiler will at most have to be invoked something like n times where n is the total number of source files in the project in certain pathological conditions as above. However, no matter what crazy stuff they're doing, as long as there no circular dependencies I think I can prove that this process will always make progress and converge to a steady state. I can make a concrete example of this condition if anyone's interested (at least I think I can!) As wasteful as it sounds is it really that bad? If the compilers only tried files that weren't already compiled and had minimal startup time then this sort of oscillation can be continued until quiescence is reached and will only take around the same time as single pass over all files. I've screwed around with this a lot and think that it would be a triumph if clojure and java could be intermixed freely. Then, there are no barriers to rewriting just one piece of a tightly interconnected java program in clojure for greater clarity/efficiency. You can just replace one java file with one clojure file, and use a java-clojure aware compiler instead of pure javac. I dream of the day where you could do this in a streamlined way in eclipse, so that everyone else on the project can focus on the concepts behind the program, not trivial minutiae like compile order. --Robert McIntyre On Sun, Aug 29, 2010 at 4:46 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 28.08.2010 um 19:09 schrieb Michał Marczyk: I'm sure I'm missing lots of things, but I'd love to know which, so -- please let me know. :-) In fact, your two-pass scenario is probably the best you can get, since you can define arbitrary classes in arbitrary namespaces. (Whether this is advisable is a different question!) So any compiler trying to translate a classname to a defining namespace must fail in general. This could only be remedied by following a convention of one class per namespace which is quite a restriction. Just scanning the source files will also fail, because classes might be generated by macros. And macros might to depend on arbitrary functions defined in the file. So they can only be expanded by loading the file and executing the functions. Hence you cannot discover class generation in general. So I would suspect that your two pass scenario is a strict limit. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your
clojure and jogl and jReality
Hello everybody, I am trying to get a simple java code (about 10 lines in clojure ) which uses jReality ported to clojure. This is my attempt has been kind of half way successfull. The corresponding github-repo link is git://github.com/sunilnandihalli/jRealityTutorial.git The project is nicely set up to work with leiningen .. so simple lein deps lein native-deps should get it started. after that I just execute the sexp in the emacs editor. When the code runs, it opens the ui and shows what is intended in a rather unpleasing way with the flickers and all. when I look at the terminal output it tells me that jogl.jar may not be in the class path.. I have however added it to the :native-dependencies and it does download and extract it . I do see the corresponding shared object files .. but I don't understand why it still says it is not finding the jogl.jar .. can anybody help me? Thanks in advance. 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
defrecord issue in unit tests
I am getting the following error when I switched from defstruct to defrecord **Unable to resolve classname: Rule-record (RecordInitTest.clj:8)** I only have this problem when definition usage is split between two files, i.e. let first file contain: (ns RecordInitQuest) (defrecord Rule-record [ rname rule-seq ]) and second file that gives the error above when using unit tests (ns RecordInitTest) (use 'clojure.test) (use 'RecordInitQuest) (deftest ruleform-def-test (def rule1 (Rule-record. rule-name more text))) --if I am just in the REPL and enter this, there is no problem, but in my real files real unit test file, it gives the error mesage above. Mostly I have been using Eclipse, but if I try a similar setup in eMacs, then I get a similar error: Unknown location: error: java.io.FileNotFoundException: Could not locate RuleForm2__init.class or RuleForm2.clj on classpath: --which is strange because it is all in the same directory -thanks in advance for any insights -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 and jogl and jReality
Hello everybody, I am trying to get a simple java code (about 10 lines in clojure ) which uses jReality ported to clojure. This is my attempt has been kind of half way successfull. The corresponding github-repo link is git://github.com/sunilnandihalli/jRealityTutorial.git The project is nicely set up to work with leiningen .. so simple lein deps lein native-deps should get it started. after that I just execute the sexp in the emacs editor. When the code runs, it opens the ui and shows what is intended in a rather unpleasing way with the flickers and all. when I look at the terminal output it tells me that jogl.jar may not be in the class path.. I have however added it to the :native-dependencies and it does download and extract it . I do see the corresponding shared object files .. but I don't understand why it still says it is not finding the jogl.jar .. can anybody help me? Thanks in advance. 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
trouble with NetBeans install
A student in the upcoming Clojure Studio is reporting the following problem getting started with NetBeans. Any suggestions? Some plugins require plugin Common Scripting Language API (new) to be installed. The plugin Common Scripting Language API (new) is requested in version = 1.9.1.1.1.1.1 (release version 1) but only 2.5.1.2.1.1.4 (of release version different from 1) was found. The following plugin is affected: Clojure Plugin Some plugins require plugin Editor Library to be installed. The plugin Editor Library is requested in version = 1.38.1.9.2 (release version 1) but only 2.10.2.10.2 (of release version different from 1) was found. The following plugin is affected: Clojure Plugin Some plugins require plugin org.netbeans.modules.templates to be installed. The plugin org.netbeans.modules.templates is requested in version 1.4.1. The following plugin is affected: Clojure Plugin Some plugins not installed to avoid potential installation problems. Thanks, Stu -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 reason Lisp code is not written with closing parenthesis on new lines?
Being the one who asked the question and satisfied with the answers, I agree. I never expected a question like this, about one of the oldest programming languages, to generate so many responses and discussions. Funny... On Aug 29, 9:46 pm, lprefonta...@softaddicts.ca wrote: My rough estimate is that more than 40 replies to that thread heave been generated up to now (I deleted the 28 ones without reading them after reading a couple of replies to the original post). Hmmm,,, I am about to think that we could have powered a small town with all that electrical nerve impulse that has been spent on this subject not withstanding the electricity spent in wires and servers to spread this thread every where around the planet. And yet no consensus has been reached... maybe we should drop the subject for now ? Luc P. Tim Daly d...@axiom-developer.org wrote .. You could do what one of my modern language (python) students did. Put the open parens at the end of the line and it looks like python! ( defun foo ( arg1 arg2 arg3 ) ( let ( tmp1 tmp2 ) ( firstFunction arg1 ) ( secondFunction arg2 ) ( thirdFunction arg3 ))) auggghhh! my eyes! my eyes :-) Back in the pre-history while I worked in the machine room a student came to me with FORTRAN code. He discovered that FORTRAN ignored spaces so he has a solid block of code from column 8 to column 71 that went on for pages. There is no disputing taste. Fortunately, lisp doesn't care. Since it is still in the early days of Clojure it might be a good idea to follow the style set in clojure core.clj. You never know when your code might become a candidate for inclusion and the last thing you want is to be rejected for style. Tim Daly kyle smith wrote: On Aug 19, 12:08 pm, Brian Goslinga quickbasicg...@gmail.com wrote: Here is another trick that works for me in Emacs: delete most of the stack of closing parens, and then spam the ) key until the Emacs matches it to the desired opening paren. this. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: clojure and jogl and jReality
On Mon, Aug 30, 2010 at 5:42 AM, Sunil Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, I am trying to get a simple java code (about 10 lines in clojure ) which uses jReality ported to clojure. This is my attempt has been kind of half way successfull. The corresponding github-repo link is git://github.com/sunilnandihalli/jRealityTutorial.git The project is nicely set up to work with leiningen .. so simple lein deps lein native-deps should get it started. after that I just execute the sexp in the emacs editor. When the code runs, it opens the ui and shows what is intended in a rather unpleasing way with the flickers and all. when I look at the terminal output it tells me that jogl.jar may not be in the class path.. I have however added it to the :native-dependencies and it does download and extract it . I do see the corresponding shared object files .. but I don't understand why it still says it is not finding the jogl.jar .. can anybody help me? Thanks in advance. Sunil. Where is jogl.jar located in your project's directory? 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: Is it possible in theory to write/modify a Clojure compiler that doesn't
Robert, The only problem with this approach is that there ARE practically guaranteed to be circular references. If the goal is to compile Clojure as if it were Java, circular references must be accounted for. But dependencies on classes generated based on parsing bytecode... that seems a pretty extreme edge case. Not to say that it won't ever happen, but I think it would be reasonable to say that anyone doing that should roll their own build process, and not expect a standard one to work by default. I know most Java compilers would choke if I pulled this sort of shennanigans. This actually sounds a lot like generating classes via Java annotations... but even there, you wouldn't hardcode a direct reference to a generated class. You reference an interface which is defined in the normal way, and then have some sort of dependency injection to look up and inject an instance of the generated class. On Aug 29, 5:44 pm, Robert McIntyre r...@mit.edu wrote: I don't think two pases is enough. What if a clojure file uses reflection (with macros of course) on a compiled java file to generate classes, sort of like how lancet works but generating classes instead of functions? And then those classes are used from other clojure and java files. Oh, and then another clojure file does the same reflection based junk to make more classes, from the classes that were generated from the first clojure file. These classes are, of course, used by other java and clojure files. In this case the only way I can think to compile everything (and sadly I'm doing something like this on my current project in lieu of a better way) is to: try to compile all the java files first (fail at some), try to compile all the clojure files (fail at some), try to compile all the java files (fail at some, but a little bit less than the first time), repeat until bytecode-level quiescence. The clojure compiler and java compiler will at most have to be invoked something like n times where n is the total number of source files in the project in certain pathological conditions as above. However, no matter what crazy stuff they're doing, as long as there no circular dependencies I think I can prove that this process will always make progress and converge to a steady state. I can make a concrete example of this condition if anyone's interested (at least I think I can!) As wasteful as it sounds is it really that bad? If the compilers only tried files that weren't already compiled and had minimal startup time then this sort of oscillation can be continued until quiescence is reached and will only take around the same time as single pass over all files. I've screwed around with this a lot and think that it would be a triumph if clojure and java could be intermixed freely. Then, there are no barriers to rewriting just one piece of a tightly interconnected java program in clojure for greater clarity/efficiency. You can just replace one java file with one clojure file, and use a java-clojure aware compiler instead of pure javac. I dream of the day where you could do this in a streamlined way in eclipse, so that everyone else on the project can focus on the concepts behind the program, not trivial minutiae like compile order. --Robert McIntyre On Sun, Aug 29, 2010 at 4:46 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 28.08.2010 um 19:09 schrieb Michał Marczyk: I'm sure I'm missing lots of things, but I'd love to know which, so -- please let me know. :-) In fact, your two-pass scenario is probably the best you can get, since you can define arbitrary classes in arbitrary namespaces. (Whether this is advisable is a different question!) So any compiler trying to translate a classname to a defining namespace must fail in general. This could only be remedied by following a convention of one class per namespace which is quite a restriction. Just scanning the source files will also fail, because classes might be generated by macros. And macros might to depend on arbitrary functions defined in the file. So they can only be expanded by loading the file and executing the functions. Hence you cannot discover class generation in general. So I would suspect that your two pass scenario is a strict limit. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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
Re: NullPointerExecption after Java class import
Initialization exception can be avoided if Factory class is initialized indirectly: (let [factory (.newInstance (Class/forName gate.Factory))] ...) The problem is that Factory can only be initialized (its static fields) after Gate.init was called. But clojure reader (or what it is) initializes all the classes mentioned in the namespace. Thus Factory gets created before cojure function calls which do Gate/init. Is this workaround ok? Or are there better ways to solve it? On Aug 30, 2:39 pm, zm zygiman...@medelis.lt wrote: Indeed if exception is thrown in static initializer block then clojure import throws exception as well. The following class will cause this: package aaa; public class Test { static{ Object o = null; o.toString(); } } Then in clojure: (ns x (:import (aaa Test)) Results in: Exception in thread main java.lang.ExceptionInInitializerError (core.clj:1) Why does this happen in clojure? If you do the same in java, import aaa.Test, then nothing happens. NLP will be thrown when you actualy try to initialize the class. On Aug 30, 6:12 am, Stuart Campbell stu...@harto.org wrote: Hello, I don't know this library specifically, but the NPE is probably occurring in a static initialisation block. I believe static initialisation occurs when the class is first loaded. Regards, Stuart On 30 August 2010 06:42, zm zygiman...@medelis.lt wrote: I am using GATE java libs in my clojure code and behaviour of the application changes after Java class import. I don't even have to initialize it. This runs fine (a bit shorter version than it is): (ns gate (:import (gate Gate) (java.io File))) (defn gate-init [gate-home] (Gate/setGateHome (File. gate-home)) (Gate/init))) Now if I import gate.Factory class, like this (gate Gate Factory), I get the exception: Caused by: java.lang.NullPointerException at gate.Factory.createResource(Factory.java:154) How can import of a class cause this? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that 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: Problem reloading source file with imports
How would using the :only keyword help here? Just to be clear, the problem here is that attempting to load my source file the second time fails (loading the first time having succeeded, albeit with a few warnings about replacing symbols from clojure.core), which makes it very difficult for me to use swank-clojure, for example, because I can't hit C-c C-k twice on the same file. Here is the failure when I try to load the file for the second time: java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) So here's my main question: If I'm working in the REPL and I edit a file that I've previously loaded, how can I cause the file to be reloaded without hitting that error? If my .clj file doesn't :use any other clojure modules then reloading works fine but, if it imports anything, then the second (load-file...) fails. On 30 August 2010 11:05, Robert McIntyre r...@mit.edu wrote: Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. If you accidently get this warning and don't want to restart the repl you can do (ns-unmap 'your-namespace 'offending-function), fix the naked import, and reload. --Robert McIntyre On Mon, Aug 30, 2010 at 5:54 AM, Chris Jenkins cdpjenk...@gmail.com wrote: Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit the source file and remove the (:use ...) clause and then try to load the file again. Anyone have any idea what is going on? I didn't see this behaviour in Clojure 1.1 and it would be nice if I could find a way to reload files that I'm working on. Cheers, 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts
Re: Problem reloading source file with imports
Hi, Am 30.08.2010 um 20:43 schrieb Chris Jenkins: How would using the :only keyword help here? Just to be clear, the problem here is that attempting to load my source file the second time fails (loading the first time having succeeded, albeit with a few warnings about replacing symbols from clojure.core), which makes it very difficult for me to use swank-clojure, for example, because I can't hit C-c C-k twice on the same file. Here is the failure when I try to load the file for the second time: java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) So here's my main question: If I'm working in the REPL and I edit a file that I've previously loaded, how can I cause the file to be reloaded without hitting that error? If my .clj file doesn't :use any other clojure modules then reloading works fine but, if it imports anything, then the second (load-file...) fails. :only helps insofar, that you can say (:use [clojure.contrib.seq-utils :only (some thing-else)]). This will prevent partition-by from being loaded form seq-utils in the first place. Nothing bad happens. Similar you can say (:refer-clojure :exclude (partition-by)]). This will prevent partition-by being loaded from core. Both solutions will work. However you will probably want to switch your code to use the core version of partition-by. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Problem reloading source file with imports
On Mon, Aug 30, 2010 at 3:05 AM, Robert McIntyre r...@mit.edu wrote: Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. Actually this namespace was only kept around for backwards-compatibility. If you use the new clojure.contrib.seq namespace it won't have these issues. Unfortunately while Clojure itself had a nice set of release notes documenting these changes, I couldn't find one for contrib. -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
Help speed up an inner loop?
Just to try to see if clojure is a practical language for doing byte-level work (parsing files, network streams, etc), I wrote a trivial function to iterate through a buffer of bytes and count all the newlines that it sees. For my testing, I've written a C version, a Java version, and a Clojure version. I'm running each routine 10 times over a 16MB buffer read from /dev/urandom (the buffer is refreshed between each call to the newline counting function). With gcc -O0, I get about 80ms per 16MB buffer. With gcc -O3, I get ~14ms per buffer. With javac (and java -server) I get 20ms per 16MB buffer. With clojure, I get 105ms per buffer (after the jvm warms up). I'm guessing that the huge boost that java and gcc -O3 get is from converting per-byte operations to per-int ops; at least that ~4x boost looks like it would come from something like that. Is that an optimization that is unavailable to clojure? The java_interop doc makes it sound like java and clojure get the exact same bytecode when using areduce correctly, so maybe there's something I could be doing better. Here are my small programs; if somebody could suggest improvements, I'd appreciate them. iterate.clj: (set! *warn-on-reflection* true) (import java.io.FileInputStream) (def *numbytes* (* 16 1024 1024)) (defn countnl [#^bytes buf] (let [nl (byte 10)] (areduce buf idx count 0 (if (= (aget buf idx) nl) (inc count) count (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls) Iterate.java: import java.io.FileInputStream; class Iterate { static final int NUMBYTES = 16*1024*1024; static int countnl(byte[] buf) { int count = 0; for(int i = 0; i buf.length; i++) { if(buf[i] == '\n') { count++; } } return count; } public static final void main(String[] args) throws Throwable { FileInputStream input = new FileInputStream(/dev/urandom); byte[] buf = new byte[NUMBYTES]; int sz; long start, end; for(int i = 0; i 10; i++) { sz = input.read(buf); System.out.println(Wanted + NUMBYTES + got + sz + bytes); start = System.currentTimeMillis(); int count = countnl(buf); end = System.currentTimeMillis(); System.out.println(counted + count + nls in + (end-start) + msec); } input.close(); } } iterate.c: #includesys/types.h #includesys/stat.h #includesys/time.h #includestdlib.h #includeunistd.h #includestdio.h #includefcntl.h int countnl(char *buf, int sz) { int i; int count = 0; for(i = 0; i sz; i++) { if(buf[i] == '\n') { count++; } } return count; } int main() { int fd = open(/dev/urandom, O_RDONLY); const int NUMBYTES = 16*1024*1024; char *buf = (char*)malloc(NUMBYTES); int sz; struct timeval start, end; int i; for(i = 0; i 10; i++) { sz = read(fd, buf, NUMBYTES); printf(Wanted %d bytes, got %d bytes\n, NUMBYTES, sz); gettimeofday(start, 0); int count = countnl(buf, sz); gettimeofday(end, 0); printf(counted %d nls in %f msec\n, count, (float)(end.tv_sec-start.tv_sec)*1e3 + (end.tv_usec-start.tv_usec)/1e3); } free(buf); close(fd); return 0; } -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Problem reloading source file with imports
Thanks for the pointers you guys. I changed my code to this: (ns test.core (:use [clojure.contrib.seq :only (indexed)])) ... (indexed being the function that I was interested in) and it now works ok. I can reload the file as many times as I like. I must confess that I am rather confused by all this. When I was loading in the whole of clojure.contrib.seq-utils, it was perfectly possible to load partition-by once (albeit with a warning) but trying to reload the source file, causing partition-by to be loaded a second time, failed. Does that sound right? Cheers, Chris On 30 August 2010 20:31, Phil Hagelberg p...@hagelb.org wrote: On Mon, Aug 30, 2010 at 3:05 AM, Robert McIntyre r...@mit.edu wrote: Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. Actually this namespace was only kept around for backwards-compatibility. If you use the new clojure.contrib.seq namespace it won't have these issues. Unfortunately while Clojure itself had a nice set of release notes documenting these changes, I couldn't find one for contrib. -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.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
Somnium.congomongo missing contribs json
I have problems loading somnium.congomongo. My Leiningen project.clj looks like this: (defproject system1 0.1.0 :description System1 :dependencies [ [org.clojure/clojure 1.2.0-master-SNAPSHOT] [org.clojure/clojure-contrib 1.2.0-SNAPSHOT] [org.clojars.kjw/mysql-connector 5.1.11] [org.clojars.liebke/congomongo 1.0.0] ] :dev-dependencies [[swank-clojure 1.2.1]]) and I'm trying to load the congomongo by (ns system1.mongo (:require [somnium.congomongo :as mongo])) which does not work. When trying it in the REPL by (ns system1.mongo) and then (use 'somnium.congomongo) I get the following error: Could not locate clojure/contrib/json/read__init.class or clojure/contrib/json/read.clj on classpath: [Thrown class java.io.FileNotFoundException] When do a (use 'clojure.contrib.json) I do however only get a nil, which, afaik is an indication that clojure finds that package. Any pointer or hints would be of much help! /Linus -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Is nil a compile-time literal?
I was surprised today when using nil as the test value for one of the clauses of the new 1.2 case statement that it results in an NPE. Is this a bug, or intended behavior? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Somnium.congomongo missing contribs json
Try using [congomongo 0.1.3-SNAPSHOT] in project.clj. Works for me with 1.2. On Aug 30, 1:37 pm, Linus Ericsson oscarlinuserics...@gmail.com wrote: I have problems loading somnium.congomongo. My Leiningen project.clj looks like this: (defproject system1 0.1.0 :description System1 :dependencies [ [org.clojure/clojure 1.2.0-master-SNAPSHOT] [org.clojure/clojure-contrib 1.2.0-SNAPSHOT] [org.clojars.kjw/mysql-connector 5.1.11] [org.clojars.liebke/congomongo 1.0.0] ] :dev-dependencies [[swank-clojure 1.2.1]]) and I'm trying to load the congomongo by (ns system1.mongo (:require [somnium.congomongo :as mongo])) which does not work. When trying it in the REPL by (ns system1.mongo) and then (use 'somnium.congomongo) I get the following error: Could not locate clojure/contrib/json/read__init.class or clojure/contrib/json/read.clj on classpath: [Thrown class java.io.FileNotFoundException] When do a (use 'clojure.contrib.json) I do however only get a nil, which, afaik is an indication that clojure finds that package. Any pointer or hints would be of much help! /Linus -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: trouble with NetBeans install
This may or may not be related, but I had similar problems when I tried to install from the downloadable .nbm file for enclojure. I solved it by poking around the enclojure.org site -- there's instructions for updating the plugins setup screen so that you can install/update enclojure using the built-in automatic install/upgrade interface. I can give you more information if that's close but not quite enough. Mark On Mon, Aug 30, 2010 at 9:04 AM, Stuart Halloway stuart.hallo...@gmail.com wrote: A student in the upcoming Clojure Studio is reporting the following problem getting started with NetBeans. Any suggestions? Some plugins require plugin Common Scripting Language API (new) to be installed. The plugin Common Scripting Language API (new) is requested in version = 1.9.1.1.1.1.1 (release version 1) but only 2.5.1.2.1.1.4 (of release version different from 1) was found. The following plugin is affected: Clojure Plugin Some plugins require plugin Editor Library to be installed. The plugin Editor Library is requested in version = 1.38.1.9.2 (release version 1) but only 2.10.2.10.2 (of release version different from 1) was found. The following plugin is affected: Clojure Plugin Some plugins require plugin org.netbeans.modules.templates to be installed. The plugin org.netbeans.modules.templates is requested in version 1.4.1. The following plugin is affected: Clojure Plugin Some plugins not installed to avoid potential installation problems. Thanks, Stu -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: trouble with NetBeans install
On Mon, Aug 30, 2010 at 3:57 PM, Mark Nutter manutte...@gmail.com wrote: This may or may not be related, but I had similar problems when I tried to install from the downloadable .nbm file for enclojure. I solved it by poking around the enclojure.org site -- there's instructions for updating the plugins setup screen so that you can install/update enclojure using the built-in automatic install/upgrade interface. I can give you more information if that's close but not quite enough. just be reminded that the auto install/upgrade package url only supports 6.9 and would result in similar dependency error when used under 6.8 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Extending Clojure's STM with external transactions
I'm not aware of any, but +1 for seeing persistence handled as part of the language. A big project and a long-term one, to be sure, but could it not be considered a goal? In my student days, I was talking to a well-known Lisper (name suppressed for fear of Google indexing) about some data structures in MIT Scheme. When I asked about saving them to disk, he said in effect, You're on your ownthat's something that \should be handled, but never is. I think people are so used to this state of affairs they forget how ugly it really is. Programming languages are like Moses without Joshua: they lead your data in the wilderness, but when it comes to finding it a permanent home, you have to talk to someone else. And these someone elses (who seem to be as numberless as the sons of Abraham) each have their own habits and ways of talking. Persistence libraries always end up warping the entire codebase; I've never succeeded in keeping them at bay. Using data with Incanter is different from ClojureQL, which is different from just using contrib.sql, and all of it is different from dealing with just Clojure. (I've never even tried Clojure + Hibernate.) You might as well rewrite the program from scratch depending on what you use. Maybe other people have had better luck; but whatever luck they have, I'm sure it is a fight to keep programs abstracted from persistence. I'd like to be able to work with mere Clojure until my program is complete, and then work in a completely separate manner on how to read and write data. Or maybe there would be off-the-shelf solutions I could plug in for different needs: low latency, high read, high write, large stores, etc. On the Clojure side, you would simply call something like persist namespace, which would save the state of your current or given namespace (unless you pass it the names of variables as well, in which case it only saves those). And to read data, you would simply require or use it into your namespace: you could choose what granularity to give first-class status: just tables, or columns as well, etc. And you could do this equally well for XML, JSON, relational data, or a graph store; your choice. And the only difference between these and ordinary variables would beheaven forbid!a disk access might happen when you deal with them! To have such a system work well, you would need to enrich the way you query Clojure datastructures. I have some ideas on that, but I'd like to make sure I'm not shouting in the dark first. I'd like to see a day when programmers need to worry about persistence about as much as they worry about garbage collection now. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Help speed up an inner loop?
I don't know what the heck is going here, but ignore the time the program is reporting and just pay attention to how long it actually takes wall-clock style and you'll see that your clojure and java programs already take the same time. Here are my findings: I saved Iterate.java into my rlm package and ran: time java -server rlm.Iterate results: time java -server rlm.Iterate Wanted 16777216 got 16777216 bytes counted 65341 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 66026 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65473 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65679 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65739 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65810 nls in 18 msec Wanted 16777216 got 16777216 bytes counted 65531 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65418 nls in 21 msec real0m27.469s user0m0.472s sys 0m26.638s I wrapped the last bunch of commands in your clojure script into a (run) function: (defn run [] (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls)) and ran (time (run)) at the repl: (time (run)) Wanted 16777216 got 16777216 bytes Elapsed time: 183.081975 msecs Got 65894 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.001814 msecs Got 65949 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.061934 msecs Got 65603 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.031131 msecs Got 65563 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.122567 msecs Got 65696 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.968066 msecs Got 65546 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.058508 msecs Got 65468 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.932395 msecs Got 65872 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.074646 msecs Got 65498 nls Wanted 16777216 got 16777216 bytes Elapsed time: 187.733636 msecs Got 65434 nls Elapsed time: 28510.331507 msecs nil Total running time for both programs is around 28 seconds. The java program seems to be incorrectly reporting it's time. --Robert McIntyre On Mon, Aug 30, 2010 at 4:03 PM, tsuraan tsur...@gmail.com wrote: Just to try to see if clojure is a practical language for doing byte-level work (parsing files, network streams, etc), I wrote a trivial function to iterate through a buffer of bytes and count all the newlines that it sees. For my testing, I've written a C version, a Java version, and a Clojure version. I'm running each routine 10 times over a 16MB buffer read from /dev/urandom (the buffer is refreshed between each call to the newline counting function). With gcc -O0, I get about 80ms per 16MB buffer. With gcc -O3, I get ~14ms per buffer. With javac (and java -server) I get 20ms per 16MB buffer. With clojure, I get 105ms per buffer (after the jvm warms up). I'm guessing that the huge boost that java and gcc -O3 get is from converting per-byte operations to per-int ops; at least that ~4x boost looks like it would come from something like that. Is that an optimization that is unavailable to clojure? The java_interop doc makes it sound like java and clojure get the exact same bytecode when using areduce correctly, so maybe there's something I could be doing better. Here are my small programs; if somebody could suggest improvements, I'd appreciate them. iterate.clj: (set! *warn-on-reflection* true) (import java.io.FileInputStream) (def *numbytes* (* 16 1024 1024)) (defn countnl [#^bytes buf] (let [nl (byte 10)] (areduce buf idx count 0 (if (= (aget buf idx) nl) (inc count) count (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls) Iterate.java: import java.io.FileInputStream; class Iterate { static final int NUMBYTES = 16*1024*1024; static int countnl(byte[] buf) { int count = 0; for(int i = 0; i buf.length; i++) { if(buf[i] == '\n') { count++; } } return count; } public static final void main(String[] args) throws Throwable { FileInputStream input = new FileInputStream(/dev/urandom); byte[] buf = new byte[NUMBYTES]; int sz; long start, end; for(int i = 0; i 10; i++) { sz = input.read(buf); System.out.println(Wanted + NUMBYTES + got + sz + bytes); start = System.currentTimeMillis(); int count = countnl(buf);
Re: Problem reloading source file with imports
Sorry, I was tired and didn't explain very well. Right now you have a naked (:use clojure.contrib.seq-utils) somewhere. You want to use partition-by, but that's already in core, so you might just get rid of the :use altogether. But maybe there are some other functions in seq-utils that you do want to use --- in that case, do (:use [clojure.contrib [seq-utils :only [functions you want]]]) or (:use [clojure.contrib [seq-utils :only []]]) to avoid stepping on core and also to document what you actually use. If you really want the seq-utils version of partition-by, then you can do: (:use [clojure.contrib [seq-utils :as whatever]]) whatever/partition-by And if you really want to replace the core version with the seq version without any namespacing, do (:refer-clojure :exclude [partition-by]) (:use [clojure.contrib [seq-utils :only [partition-by]]]) does that help? --Robert McIntyre On Mon, Aug 30, 2010 at 2:43 PM, Chris Jenkins cdpjenk...@gmail.com wrote: How would using the :only keyword help here? Just to be clear, the problem here is that attempting to load my source file the second time fails (loading the first time having succeeded, albeit with a few warnings about replacing symbols from clojure.core), which makes it very difficult for me to use swank-clojure, for example, because I can't hit C-c C-k twice on the same file. Here is the failure when I try to load the file for the second time: java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) So here's my main question: If I'm working in the REPL and I edit a file that I've preu'vviously loaded, how can I cause the file to be reloaded without hitting that error? If my .clj file doesn't :use any other clojure modules then reloading works fine but, if it imports anything, then the second (load-file...) fails. On 30 August 2010 11:05, Robert McIntyre r...@mit.edu wrote: Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. If you accidently get this warning and don't want to restart the repl you can do (ns-unmap 'your-namespace 'offending-function), fix the naked import, and reload. --Robert McIntyre On Mon, Aug 30, 2010 at 5:54 AM, Chris Jenkins cdpjenk...@gmail.com wrote: Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit the source file and remove the (:use ...) clause and then try to load the file again. Anyone have any idea what is going on? I didn't see this behaviour in Clojure 1.1 and it would be nice if I could find a way to reload files that I'm working on. Cheers, Chris -- You received this message because you are subscribed to the Google Groups Clojure
Minor macroexpand issue
I accidentally noticed this: On clojure 1.2, macroexpanding with a function name which is a class, causes this ugly error: (macroexpand '(Object)) java.lang.Exception: Expecting var, but Object is mapped to class java.lang.Object (repl-1:2) when presumably it should just give '(Object). I have no clue for any actual use cases of naming your functions after classes, but: (let [Object (fn [] 3)] (Object)) is technically valid clojure code, so macroexpand shouldn't just die... -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Is nil a compile-time literal?
case does constant-time dispatch using the hash codes of the test values. Since nil is Java null, it doesn't have a hash code, so case can't handle it. I wouldn't call it a bug, but there is work to be done on extending case to edge cases like this. -S On Aug 30, 5:07 pm, Paul Mooser taron...@gmail.com wrote: I was surprised today when using nil as the test value for one of the clauses of the new 1.2 case statement that it results in an NPE. Is this a bug, or intended behavior? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Help speed up an inner loop?
I think this misses the point. Of course java, c, and clojure will all have roughly the same wall-clock time for this program, since it is dominated by the I/O. You can even see that in the output from $ time java Iterate: less than 0.5s was spent in user space, the rest was spent in system code - that is, mostly doing I/O. The java version is a second faster as counted by the wall clock, and this is unlikely to be a coincidence: tsuraan's timing data suggests that the clojure program takes 80ms longer in each loop, and loops 10 times. That comes out to 0.8 seconds, which is quite close to the differential you observed when timing from the command line. On Aug 30, 1:38 pm, Robert McIntyre r...@mit.edu wrote: I don't know what the heck is going here, but ignore the time the program is reporting and just pay attention to how long it actually takes wall-clock style and you'll see that your clojure and java programs already take the same time. Here are my findings: I saved Iterate.java into my rlm package and ran: time java -server rlm.Iterate results: time java -server rlm.Iterate Wanted 16777216 got 16777216 bytes counted 65341 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 66026 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65473 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65679 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65739 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65810 nls in 18 msec Wanted 16777216 got 16777216 bytes counted 65531 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65418 nls in 21 msec real 0m27.469s user 0m0.472s sys 0m26.638s I wrapped the last bunch of commands in your clojure script into a (run) function: (defn run [] (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls)) and ran (time (run)) at the repl: (time (run)) Wanted 16777216 got 16777216 bytes Elapsed time: 183.081975 msecs Got 65894 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.001814 msecs Got 65949 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.061934 msecs Got 65603 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.031131 msecs Got 65563 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.122567 msecs Got 65696 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.968066 msecs Got 65546 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.058508 msecs Got 65468 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.932395 msecs Got 65872 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.074646 msecs Got 65498 nls Wanted 16777216 got 16777216 bytes Elapsed time: 187.733636 msecs Got 65434 nls Elapsed time: 28510.331507 msecs nil Total running time for both programs is around 28 seconds. The java program seems to be incorrectly reporting it's time. --Robert McIntyre On Mon, Aug 30, 2010 at 4:03 PM, tsuraan tsur...@gmail.com wrote: Just to try to see if clojure is a practical language for doing byte-level work (parsing files, network streams, etc), I wrote a trivial function to iterate through a buffer of bytes and count all the newlines that it sees. For my testing, I've written a C version, a Java version, and a Clojure version. I'm running each routine 10 times over a 16MB buffer read from /dev/urandom (the buffer is refreshed between each call to the newline counting function). With gcc -O0, I get about 80ms per 16MB buffer. With gcc -O3, I get ~14ms per buffer. With javac (and java -server) I get 20ms per 16MB buffer. With clojure, I get 105ms per buffer (after the jvm warms up). I'm guessing that the huge boost that java and gcc -O3 get is from converting per-byte operations to per-int ops; at least that ~4x boost looks like it would come from something like that. Is that an optimization that is unavailable to clojure? The java_interop doc makes it sound like java and clojure get the exact same bytecode when using areduce correctly, so maybe there's something I could be doing better. Here are my small programs; if somebody could suggest improvements, I'd appreciate them. iterate.clj: (set! *warn-on-reflection* true) (import java.io.FileInputStream) (def *numbytes* (* 16 1024 1024)) (defn countnl [#^bytes buf] (let [nl (byte 10)] (areduce buf idx count 0 (if (= (aget buf idx) nl) (inc count) count (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs
Re: Is nil a compile-time literal?
That was my first thought too, but (hash nil) is zero. So it doesn't seem like it should be caused by that problem. I'm not familiar enough with the internals of clojure.core to follow all of the stuff going on in (source case), but it seems to be using (hash x) rather than (. x hashCode). And (min-hash) does the same, so at first glance it looks like there is no NPE caused by hashing. On the other hand, I can't see what else is causing an NPE, but maybe someone more experienced can point it out, or tell me why I'm wrong in concluding that it's not hashing that's at fault. On Aug 30, 5:12 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: case does constant-time dispatch using the hash codes of the test values. Since nil is Java null, it doesn't have a hash code, so case can't handle it. I wouldn't call it a bug, but there is work to be done on extending case to edge cases like this. -S On Aug 30, 5:07 pm, Paul Mooser taron...@gmail.com wrote: I was surprised today when using nil as the test value for one of the clauses of the new 1.2 case statement that it results in an NPE. Is this a bug, or intended behavior? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Problem reloading source file with imports
I ran into the same situation as Chris yesterday with clojure.contrib.seq-utils as well as with clojure.contrib.str-utils. The explanation is very timely for me and much appreciated. - John On Mon, Aug 30, 2010 at 4:05 PM, Robert McIntyre r...@mit.edu wrote: Sorry, I was tired and didn't explain very well. Right now you have a naked (:use clojure.contrib.seq-utils) somewhere. You want to use partition-by, but that's already in core, so you might just get rid of the :use altogether. But maybe there are some other functions in seq-utils that you do want to use --- in that case, do (:use [clojure.contrib [seq-utils :only [functions you want]]]) or (:use [clojure.contrib [seq-utils :only []]]) to avoid stepping on core and also to document what you actually use. If you really want the seq-utils version of partition-by, then you can do: (:use [clojure.contrib [seq-utils :as whatever]]) whatever/partition-by And if you really want to replace the core version with the seq version without any namespacing, do (:refer-clojure :exclude [partition-by]) (:use [clojure.contrib [seq-utils :only [partition-by]]]) does that help? --Robert McIntyre On Mon, Aug 30, 2010 at 2:43 PM, Chris Jenkins cdpjenk...@gmail.com wrote: How would using the :only keyword help here? Just to be clear, the problem here is that attempting to load my source file the second time fails (loading the first time having succeeded, albeit with a few warnings about replacing symbols from clojure.core), which makes it very difficult for me to use swank-clojure, for example, because I can't hit C-c C-k twice on the same file. Here is the failure when I try to load the file for the second time: java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) So here's my main question: If I'm working in the REPL and I edit a file that I've preu'vviously loaded, how can I cause the file to be reloaded without hitting that error? If my .clj file doesn't :use any other clojure modules then reloading works fine but, if it imports anything, then the second (load-file...) fails. On 30 August 2010 11:05, Robert McIntyre r...@mit.edu wrote: Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. If you accidently get this warning and don't want to restart the repl you can do (ns-unmap 'your-namespace 'offending-function), fix the naked import, and reload. --Robert McIntyre On Mon, Aug 30, 2010 at 5:54 AM, Chris Jenkins cdpjenk...@gmail.com wrote: Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit