Re: Two possible additions: non-reflective classobject calls & support for map-conj on arrays
Hi Karl, 2009/8/31 Krukow : > 2) I can do: > user> (into {} '([:k :v])) > {:k :v} > > This works for two-element vectors. However, I cannot do the same for > two-element arrays: > > user> (def str_array (.split "k=v" "=")) > #'user/str_array > user> (into {} (list str_array)) > ; Evaluation aborted. > > > The use-case arose from wanting to create a map from a properties file > using split ("=") on each line of the properties file (and not wanting > to copy the array into []). I just wanted to point out that the Java Properties class inherits Hashtable which is already (into) compatible, i.e. user> (let [props (. System getProperties)] ((into {} props) "os.arch")) "x86" -- ! Lauri --~--~-~--~~~---~--~~ You 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: Two possible additions: non-reflective classobject calls & support for map-conj on arrays
On Sep 1, 11:10 am, Lauri Pesonen wrote: > I just wanted to point out that the Java Properties class inherits > Hashtable which is already (into) compatible, i.e. > > user> (let [props (. System getProperties)] > ((into {} props) "os.arch")) > "x86" Ok. That is certainly a more concise way of doing it. In my case, that would amount to: (def properties-map (with-open [s (.getResourceAsStream java.lang.String "/resources/ myresource.properties")] (into {} (doto (java.util.Properties.) (.load s) However, the change could still be valid for other cases. Also this approach requires more memory as it has two live maps (one properties and one persistent map) while the persistent map is being built. Without creating a full "properties" object it is possible to "stream" the entries into the persistent map. Granted, often this would not be a problem. P.S. I realize that the change would also need to be made to APersistentMap cons method. --~--~-~--~~~---~--~~ You 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: Java security code in Clojure
Thanks a lot, Timothy, you're right. Sam On Aug 31, 7:12 pm, Timothy Pratley wrote: > The reason your byte-seq fails is because you coerce the int result to > a byte before comparing to -1. You should compare the int result to -1 > and coerce to a byte after: > (defn byte-seq [rdr] > (let [result (. rdr read)] > (if (= result -1) > (do (. rdr close) nil) > (lazy-seq (cons (byte result) (byte-seq rdr)) > > Because > user=> (byte 255) > -1 > > -1 is a valid byte to read in the file and will be returned as int 255 > by read > > security=> pk > # > Regards, > Tim. > > Alternatively here is a more direct translation of your java version > which also works: > (let [file (new File "public.der") > byte-arr (make-array Byte/TYPE (.length file)) > stream (new FileInputStream file)] > (println "READ: " (.read stream byte-arr)) > (let [pk-spec (new X509EncodedKeySpec byte-arr) > kf (KeyFactory/getInstance "RSA")] > (.generatePublic kf pk-spec))) > READ: 294 > # > On Sep 1, 9:18 am, Timothy Pratley wrote: > > > security=> (count byte-arr) > > 115 > > tprat...@neuromancer:~$ wc public.der > > 5 11 294 public.der > > > your byte-seq does not do what the java version does :) > > > On Aug 31, 9:19 pm, Sam Hughes wrote: > > > > Hey, > > > > I'm trying to write a Clojure security library. My first step is > > > porting some working Java code into Clojure. The Java and Clojure > > > snippets below are more or less the same, but with the Clojure code, > > > I'm getting: "java.security.InvalidKeyException: IOException: null > > > [Thrown class java.security.spec.InvalidKeySpecException]," which I > > > can't seem to replicate with the Java code. > > > > The goal of the code is to read in a DER file, use it to encrypt a > > > "Hello World" message, then output the encrypted message as a new > > > file. > > > > Neither of these snippets necessarily follow good coding standards. > > > That said, here's the working Java code snippet: > > > > final File keyFile = new File("public.der"); > > > byte[] encodedKey = new byte[(int) keyFile.length()]; > > > > new FileInputStream(keyFile).read(encodedKey); > > > final byte[] newEncoded = encodedKey; > > > > final X509EncodedKeySpec keySpec = new X509EncodedKeySpec(newEncoded); > > > KeyFactory kf = KeyFactory.getInstance("RSA"); > > > PublicKey pk = kf.generatePublic(keySpec); > > > > Cipher rsa = Cipher.getInstance("RSA"); > > > rsa.init(Cipher.ENCRYPT_MODE, pk); > > > OutputStream os = new CipherOutputStream(new FileOutputStream > > > ("encrypted.rsa"), rsa); > > > > Writer out = new OutputStreamWriter(os); > > > out.write("Hello World"); > > > out.close(); > > > os.close(); > > > > And here's the Exception throwing Clojure code: > > > > (ns security > > > (:import > > > [java.io File FileInputStream IOException] > > > [java.security.spec X509EncodedKeySpec] > > > [java.security KeyFactory PublicKey > > > KeyPairGenerator NoSuchAlgorithmException KeyPair] > > > [javax.crypto KeyGenerator Cipher])) > > > > (defn byte-seq [rdr] > > > (let [result (byte (. rdr read))] > > > (if (= result -1) > > > (do (. rdr close) nil) > > > (lazy-seq (cons result (byte-seq rdr)) > > > > (def stream (new FileInputStream (new File "public.der"))) > > > (def byte-arr (into-array Byte/TYPE (byte-seq stream))) > > > (def pk-spec (new X509EncodedKeySpec byte-arr)) > > > (def kf (. KeyFactory (getInstance "RSA"))) > > > (def pk (. kf (generatePublic pk-spec))) ; exception thrown > > > here > > > > Does anyone have any suggestion for what could be causing the > > > exception? I'm perplexed because, right now, I'm just trying to > > > replicate Java code in Clojure -- nothing too fancy. > > > > Thanks a lot, > > > Sam --~--~-~--~~~---~--~~ You 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 classpaths
Clojure is great. I have begun integrating Clojure v1.0 into my current project. I seem to be missing something real easy, ... It seems like every path I set from "java -cp" is ignored from inside of REPL, main or calling AOT classes. In fact, when I start Clojure from a directory, I have to explicitly (add-classpath "file:///some/path/") from REPL to compile clj files in the same directory that I started Clojure from (or any other directory). The best part is that when I enter... (println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader from REPL, I see the proper classpaths, but can't use them until I explicitly add them with (add-classpath "..."). I can get around REPL and main classpath issues easy enough, but I must use AOT compiled classes in my project. I need to call compiled classes from my Java code. I just don't know how to force AOT classes to recognize the java.class.path property. I keep finding new ways to print the exception... Caused by: java.io.FileNotFoundException: Could not locate com/genedavis/clojure/testing/test__init.class or com/genedavis/clojure/testing/test.clj on classpath: at clojure.lang.RT.load(RT.java:398) at clojure.lang.RT.load(RT.java:367) at clojure.core$load__5058$fn__5061.invoke(core.clj:3734) at clojure.core$load__5058.doInvoke(core.clj:3733) at clojure.lang.RestFn.invoke(RestFn.java:413) at clojure.lang.Var.invoke(Var.java:346) Any suggestions? Thanks in advance! --~--~-~--~~~---~--~~ You 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 classpaths
Hi, On Sep 1, 6:58 am, Terrance Davis wrote: > It seems like every path I set from "java -cp" is ignored from inside > of REPL, main or calling AOT classes. In fact, when I start Clojure > from a directory, I have to explicitly (add-classpath > "file:///some/path/") from REPL to compile clj files in the same > directory that I started Clojure from (or any other directory). For AOT compilation the source files must be reachable as well as the generated .class files. So if you sources are in the src subdirectory and the .class files go to the classes subdirectory, you'll need both subdirectories in the classpath. (Note: with "reachable" I mean "follow the usual convention", namespace foo.bar.baz must be in src/ foo/bar/baz.clj with src in the classpath) Adding "." to the classpath should take care of the current working directory. Maybe you can post an example, how you setup your classpath for the JVM and the exact steps to reproduce the error? That makes it easier to help. 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: clojure classpaths
Thanks. I should probably clarify. I have managed to compile the classes using (add-classpath ""). My problem is using the compiled classes. The example code is here: http://clojure.org/compilation Namely... (ns clojure.examples.hello (:gen-class)) (defn -main [greetee] (println (str "Hello " greetee "!"))) and, ... (compile 'clojure.examples.hello) and, ... java -cp ./classes:clojure.jar clojure.examples.hello Fred Calling the main method from the clojure.org doc results in the previously mentioned exception (or package/namespace specific exception) when using clojure v1.0 I have called the main method from the command line. I have called it from Java classes. I have called it with the doc's namespace and mine. It all results in the same exception. My Java classes recognize the -cp argument, and the AOT classes throw the file not found exception. Like I said, I must be missing something real simple. I just can't figure out what it is. Thanks again! On Tue, Sep 1, 2009 at 6:46 AM, Meikel Brandmeyer wrote: > > Hi, > > On Sep 1, 6:58 am, Terrance Davis wrote: > >> It seems like every path I set from "java -cp" is ignored from inside >> of REPL, main or calling AOT classes. In fact, when I start Clojure >> from a directory, I have to explicitly (add-classpath >> "file:///some/path/") from REPL to compile clj files in the same >> directory that I started Clojure from (or any other directory). > > For AOT compilation the source files must be reachable as well as the > generated .class files. So if you sources are in the src subdirectory > and the .class files go to the classes subdirectory, you'll need both > subdirectories in the classpath. (Note: with "reachable" I mean > "follow the usual convention", namespace foo.bar.baz must be in src/ > foo/bar/baz.clj with src in the classpath) > > Adding "." to the classpath should take care of the current working > directory. > > Maybe you can post an example, how you setup your classpath for the > JVM and the exact steps to reproduce the error? That makes it easier > to help. > > 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: Clojure for game programming?
I've been casually interested in game development for a while. I haven't done anything exciting, but I've been researching available libraries and surveying the landscape. I haven't checked out JOGL, so I'm not sure how it compares, but from what I've seen JMonkey looks like a pretty nice game engine. It might be worth a look. http://www.jmonkeyengine.com/ -Travis On Aug 30, 12:01 am, Elliott Slaughter wrote: > Hi, > > I'm visiting from the Common Lisp game-dev crowd and wanted to try out > Clojure for writing games. > > I saw some JOGL examples posted in this group, in addition to the > cloggle library which wraps some JOGL functionality. Cloggle is pretty > thin right now and uses glFunctionNames as they are, so I've added > some patches to convert glFunctionNames to Lispier function-names, and > tried to Lispify the interface in general [1]. > > I think I'd be fairly comfortable writing a graphics engine with my > patched version of cloggle. What I'm not so sure about is writing the > game simulation model. > > All game simulation models I've seen used graphs of mutable objects; > I'm not entirely sure how to move to a more functional model. One the > one hand, reallocating the game world on every frame seems excessive > (even if Java's GC is fast), and on the other hand putting refs > everywhere a value could potentially change seems equally excessive > (and probably detrimental to performance). > > I just saw zippers on the other libraries page, but haven't had the > time to read it and don't know if it meets my needs or not. > > If anyone has suggestions on simulating interactions between trees of > objects (especially on the Clojure way to do it), I'd appreciate it. > Comments on my cloggle patches also welcome. > > [1]http://github.com/slaguth/cloggle/tree/master --~--~-~--~~~---~--~~ You 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 classpaths
Hi, sorry. I'm off. Your example works for me on 1.5 on Windows as it does work for me on Mac with 1.5 and 1.6. 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: Two possible additions: non-reflective classobject calls & support for map-conj on arrays
On Mon, Aug 31, 2009 at 10:55 AM, Krukow wrote: > > I have two minor minor suggestions for Clojure changes. > > 1) Consider this function: > user> (set! *warn-on-reflection* true) > true > user> (defn reader-from-classpath [s] > (-> (.getResourceAsStream java.lang.String s) > (java.io.InputStreamReader.) > (java.io.BufferedReader.))) > Reflection warning, NO_SOURCE_PATH:2 - call to getResourceAsStream > can't be resolved. > #'user/reader-from-classpath > > In general, I think every call of form (.instanceMember Classname > args*) will generate such a warning since it expands to, e.g., > > user> (macroexpand ' (.getResourceAsStream java.lang.String s)) > (. (clojure.core/identity java.lang.String) getResourceAsStream s) > user> > > And identity doesn't have any type information. A simple fix would be. > user> (defn #^Class class-identity [#^Class c] c) > > #'user/class-identity > > and then expanding (.instanceMember Classname args*) to > > (. (class-identity Classname) instanceMember args*) > > --- > > 2) I can do: > user> (into {} '([:k :v])) > {:k :v} > > This works for two-element vectors. However, I cannot do the same for > two-element arrays: > > user> (def str_array (.split "k=v" "=")) > #'user/str_array > user> (into {} (list str_array)) > ; Evaluation aborted. > > It would be a simple addition to clojure.lang.ATransientMap: > import java.lang.reflect.Array;//change > ... > public ITransientMap conj(Object o) { > ensureEditable(); > if(o instanceof Map.Entry) > { > Map.Entry e = (Map.Entry) o; > > return assoc(e.getKey(), e.getValue()); > } > else if(o instanceof IPersistentVector) > { > IPersistentVector v = (IPersistentVector) o; > if(v.count() != 2) > throw new IllegalArgumentException("Vector arg > to map conj must be > a pair"); > return assoc(v.nth(0), v.nth(1)); > }//begin change > else if(o != null && o.getClass().isArray()) > { > if(Array.getLength(o) != 2) > throw new IllegalArgumentException("Array arg > to map conj must > have exactly two elements"); > return assoc(Array.get(o,0), Array.get(o,1)); > }//end change > > ITransientMap ret = this; > for(ISeq es = RT.seq(o); es != null; es = es.next()) > { > Map.Entry e = (Map.Entry) es.first(); > ret = ret.assoc(e.getKey(), e.getValue()); > } > return ret; > } > > After this change I have: > user> (def str_array (.split "k=v" "=")) > #'user/str_array > user> (into {} (list str_array)) > {"k" "v"} > user> > > The use-case arose from wanting to create a map from a properties file > using split ("=") on each line of the properties file (and not wanting > to copy the array into []). > > N.B. the cost is an additional null-check and o.getClass().isArray(). > > What do you guys think? #1 is fine idea. I've implemented the hinting in the compiler where that expansion takes place. (commit e45046da8f) As for #2, I'm less sure I want to encourage people to interoperate with the map library using arrays. Rich --~--~-~--~~~---~--~~ You 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 classpaths
Okay. Here's some additional information. I have tried on OS X 10.6 and Vista and no dice either place. I am NOT placing the AOT classes in the system classpath. I am intentionally using only the -cp command line argument. Also, I make sure the *.clj scripts are NOT in the path after compiling as they could load instead of the *.class files, thus tainting the test. Thanks for the help. On Tue, Sep 1, 2009 at 8:20 AM, Meikel Brandmeyer wrote: > > Hi, > > sorry. I'm off. Your example works for me on 1.5 on Windows as it does > work for me on Mac with 1.5 and 1.6. > > 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 -~--~~~~--~~--~--~---
NullPointerException with defmacro and none without?!
Hi all, I'm new to Clojure and I'm playing around with Qt Jambi, which works as expected, until I started to use a self written macro. Now I don't know if this is just a problem I don't see (probably) or if it is a bug in Clojure. I have the following sample code (I hope this is readable when posted. Otherwise I'll use something like pastebin): > (ns a.namespace.sample > (:gen-class) > (:import > (com.trolltech.qt.gui QApplication QMainWindow))) > > (defmacro RunQt [args & body] > `( > (try > (QApplication/initialize (into-array [~args])) > (catch RuntimeException e# (println e#))) > ~...@body > (QApplication/exec))) > > > (defn -main [args] > (RunQt args > (let [mainWindow (QMainWindow.)] > (.show mainWindow > > (defn -main2 [args] > (try > (QApplication/initialize (into-array [args])) > (catch RuntimeException e (println e))) > (let [mainWindow (QMainWindow.)] > (.show mainWindow)) > (QApplication/exec)) > > > ; (-main "") > ; (-main2 "") Now both -main and -main2 work as expected, they show a simple Window with nothing in it. So far so good. But after I close the Window, - main throws the following exception: > Exception in thread "main" java.lang.NullPointerException (qtest.clj:0) > at clojure.lang.Compiler.eval(Compiler.java:4543) > at clojure.lang.Compiler.load(Compiler.java:4857) > at clojure.lang.Compiler.loadFile(Compiler.java:4824) > at clojure.main$load_script__5833.invoke(main.clj:206) > at clojure.main$script_opt__5864.invoke(main.clj:258) > at clojure.main$main__5888.doInvoke(main.clj:333) > at clojure.lang.RestFn.invoke(RestFn.java:413) > at clojure.lang.Var.invoke(Var.java:346) > at clojure.lang.AFn.applyToHelper(AFn.java:173) > at clojure.lang.Var.applyTo(Var.java:463) > at clojure.main.main(main.java:39) > Caused by: java.lang.NullPointerException > at a.namespace.sample$_main__8.invoke(qtest.clj:16) > at a.namespace.sample$eval__20.invoke(qtest.clj:29) > at clojure.lang.Compiler.eval(Compiler.java:4532) > ... 10 more whereas -main2 does not. Now they both look to my newbie eyes the same, except the code of -main is generated by a macro. This is the same if I compile the code. The uncompiled version I started with (paths omitted for better readability): > java -cp clojure.jar;qtjambi-4.5.2_01.jar;qtjambi-win32-msvc2005-4.5.2_01.jar > clojure.main qtest.clj I have this behavior under WinXP and 2k, with Java RE 1.5.x and with JDK 1.6.0_16, Clojure 1.0.0 and the latest Qt Jambi. Am I just missing something totally fundamental and this is expected behavior? I fiddled with this code for I don't know how long, tried this and that but cannot figure out where this NullPointerException is coming from. Any help would be appreciated. Thanks and greetings --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: NullPointerException with defmacro and none without?!
Hello! On Tue, Sep 1, 2009 at 5:44 PM, Sir Diddymus wrote: > Hi all, > >> (defmacro RunQt [args & body] >> `( >> (try >> (QApplication/initialize (into-array [~args])) >> (catch RuntimeException e# (println e#))) >> ~...@body >> (QApplication/exec))) (defmacro RunQt [args & body] `(do ; <= here is the error (try (QApplication/initialize (into-array [~args])) (catch RuntimeException e# (println e#))) ~...@body (QApplication/exec))) Without the 'do the form was compiled as a function invocation, and thus it tries to call the return value of the try form (which is nil) only once all args are computed (ie when you close the window). Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (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: Two possible additions: non-reflective classobject calls & support for map-conj on arrays
On Tue, Sep 1, 2009 at 10:40 AM, Rich Hickey wrote: > On Mon, Aug 31, 2009 at 10:55 AM, Krukow wrote: > > > > I have two minor minor suggestions for Clojure changes. > > > > 1) Consider this function: > > user> (set! *warn-on-reflection* true) > > true > > user> (defn reader-from-classpath [s] > > (-> (.getResourceAsStream java.lang.String s) > > (java.io.InputStreamReader.) > > (java.io.BufferedReader.))) > > Reflection warning, NO_SOURCE_PATH:2 - call to getResourceAsStream > > can't be resolved. > > #'user/reader-from-classpath > > > > In general, I think every call of form (.instanceMember Classname > > args*) will generate such a warning since it expands to, e.g., > > > > user> (macroexpand ' (.getResourceAsStream java.lang.String s)) > > (. (clojure.core/identity java.lang.String) getResourceAsStream s) > > user> > > #1 is fine idea. I've implemented the hinting in the compiler where > that expansion takes place. (commit e45046da8f) > Why is there a call to identity at all? Why not just (. java.lang.String getResourceAsStream 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: clojure classpaths
On Sep 1, 5:03 pm, Terrance Davis wrote: > Okay. Here's some additional information. > > I have tried on OS X 10.6 and Vista and no dice either place. I am NOT This works for me on Mac: krukow:~/examples$ ls -R classes clojure.jar src ./classes: ./src: clojure ./src/clojure: examples ./src/clojure/examples: hello.clj krukow:~/examples$ java -cp clojure.jar:./src:./classes clojure.main Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java... Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java... Clojure 1.1.0-alpha-SNAPSHOT user=> (compile 'clojure.examples.hello) clojure.examples.hello user=> (clojure.examples.hello.) # user=> ^D krukow:~/examples$ java -cp clojure.jar:./src:./classes clojure.examples.hello Karl Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java... Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java... Hello Karl! krukow:~/examples$ --~--~-~--~~~---~--~~ You 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: NullPointerException with defmacro and none without?!
Hi, Am 01.09.2009 um 17:44 schrieb Sir Diddymus: (defmacro RunQt [args & body] `( (try (QApplication/initialize (into-array [~args])) (catch RuntimeException e# (println e#))) ~...@body (QApplication/exec))) You have to wrap the try and QApplication/exec call into a `do`: (do (try ) (Qapplication/exec)) (defn -main2 [args] (try (QApplication/initialize (into-array [args])) (catch RuntimeException e (println e))) (let [mainWindow (QMainWindow.)] (.show mainWindow)) (QApplication/exec)) `defn` does the `do`-wrapping for you. You get a NPE, because your macro basically expands to ((try ...) (QApplication/exec)). So the return value of the try is used as "function" which is called on the result of the QApp/exec. Now obviously QApp/initialize returns nil. Hence the exception. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Two possible additions: non-reflective classobject calls & support for map-conj on arrays
On Sep 1, 7:36 pm, John Harrop wrote: > Why is there a call to identity at all? Why not just (. java.lang.String > getResourceAsStream s)? If I understand correctly this is because there is only one special form for Java access called "dot", written: . At http://clojure.org/java_interop it is defined: "If the first operand is a symbol that resolves to a class name, the access is considered to be to a static member of the named class. Note that nested classes are named EnclosingClass$NestedClass, per the JVM spec. Otherwise it is presumed to be an instance member and the first argument is evaluated to produce the target object." In our case, we are not looking for a static-access, but a call to a method defined on the class object. I.e., the former is (. Classname-symbol member-symbol) where as we want (. instance-expr member-symbol) The slightly hackish solution is to replace the classname-symbol with an expression which evaluates to the class object, yielding the (. instance-expr member-symbol) semantics. Please correct me if I am wrong. /Karl --~--~-~--~~~---~--~~ You 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: Two possible additions: non-reflective classobject calls & support for map-conj on arrays
On Tue, Sep 1, 2009 at 1:36 PM, John Harrop wrote: > On Tue, Sep 1, 2009 at 10:40 AM, Rich Hickey wrote: >> >> On Mon, Aug 31, 2009 at 10:55 AM, Krukow wrote: >> > >> > >> > user> (macroexpand ' (.getResourceAsStream java.lang.String s)) >> > (. (clojure.core/identity java.lang.String) getResourceAsStream s) >> > user> >> >> >> >> #1 is fine idea. I've implemented the hinting in the compiler where >> that expansion takes place. (commit e45046da8f) > > Why is there a call to identity at all? Why not just > (. java.lang.String getResourceAsStream s)? That form means the same as (java.lang.String/getResourceAsStream s) user=> (macroexpand '(java.lang.String/getResourceAsStream s)) (. java.lang.String getResourceAsStream s) That is, a static method getResourceAsStrram of class String. There is no such method because you actually want the instance method of class Call, so you'd get an error. This (or more often its inverse) used to be Clojure FAQ #1 until the (.foo bar) vs. (Foo/bar) interop forms were fully implemented. You should be glad you only run into it now when poking around in macroexpanded internals! :-) --Chouser --~--~-~--~~~---~--~~ You 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 classpaths
The details help a lot. I was able to ensure I am doing the same steps with a file not found exception instead of a working file. I notice that the you used 'clojure.jar' whereas I am using 'clojure-1.0.0.jar'. Did you happen to compile your clojure.jar from source? I used the current release download. I am starting to wonder if I need to build from source to get this classpath problem to go away. On Tue, Sep 1, 2009 at 12:05 PM, Krukow wrote: > > > > On Sep 1, 5:03 pm, Terrance Davis wrote: >> Okay. Here's some additional information. >> >> I have tried on OS X 10.6 and Vista and no dice either place. I am NOT > > This works for me on Mac: > krukow:~/examples$ ls -R > classes clojure.jar src > ./classes: > ./src: > clojure > ./src/clojure: > examples > ./src/clojure/examples: > hello.clj > krukow:~/examples$ java -cp clojure.jar:./src:./classes clojure.main > Unable to find a $JAVA_HOME at "/usr", continuing with system-provided > Java... > Unable to find a $JAVA_HOME at "/usr", continuing with system-provided > Java... > Clojure 1.1.0-alpha-SNAPSHOT > user=> (compile 'clojure.examples.hello) > clojure.examples.hello > user=> (clojure.examples.hello.) > # > user=> ^D > krukow:~/examples$ java -cp clojure.jar:./src:./classes > clojure.examples.hello Karl > Unable to find a $JAVA_HOME at "/usr", continuing with system-provided > Java... > Unable to find a $JAVA_HOME at "/usr", continuing with system-provided > Java... > Hello Karl! > krukow:~/examples$ > > > > --~--~-~--~~~---~--~~ You 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: NullPointerException with defmacro and none without?!
Ah, thanks to both of you for the fast reply - as always, the problem's to be found between chair and keyboard. ;) Greetings from Germany, Sir Diddymus P.S.: Btw, great props to Meikel for vimclojure - now I can use the world's best editor with nice Clojure integration. 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: Order of keys within a map?
As, Patrick Sullivan, said, the built-in sorted-map guarantees that the keys will be in order. I'm probably missing something here, but wouldn't that fit the bill? http://clojure.org/api#sorted-map Rob Lachlan On Aug 27, 12:35 pm, Howard Lewis Ship wrote: > Is the order of keys in a map predictable? I have some tests I'm > concerned about, where the keys and values in a map are converted to a > string (ultimately, a URL, as query parameters) and the order will > affect the output string. > > I could sort the keys, but then I'm changing my code to support the > test in a somewhat non-trivial way. > > Literally: when iterating over the key/value pairs, the order seems to > be the order in which the key/values are defined in the map. Is this > true? > > -- > Howard M. Lewis Ship > > Creator of Apache Tapestry > > The source for Tapestry training, mentoring and support. Contact me to > learn how I can get you up and productive in Tapestry fast! --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Special Issue on Lisp: Research and Experience
Journal of Universal Computer Science (J.UCS) http://www.jucs.org Special Issue on Lisp: Research and Experience Call for Papers The Lisp family of languages is a driving force both in the programming language research field and in the software industry field. Lisp dialects have been used for the development of all kinds of software, from embedded systems to extremely large systems, and the Lisp DNA can be found in all modern programming languages. The Journal of Universal Computer Science is publishing a special issue dedicated to "Lisp - Research and Experience" and invites high quality papers about novel research results, insights and lessons learned from practical applications, and educational perspectives, all involving Lisp dialects, including Common Lisp, Scheme, Emacs Lisp, AutoLisp, ISLISP, Dylan, Clojure, and so on. All papers will be peer reviewed and will be selected on the basis of their quality and relevance to the theme of this special issue. Authors whose papers have been accepted and presented at the European Lisp Symposium (ELS) 2009 are also invited to submit extended versions of their papers to this special issue. The extended version must have at least 30% new material and a different title. In addition to ELS 2009 extended papers, the special issue will also consider for publication all submissions that are original and are not submitted, in any form, at any other forum. Papers on practical as well as on theoretical topics and problems are invited. Topics include, but are not limited to: * Language design and implementation techniques * Language integration, interoperation and deployment * Language critique and future directions * Reflection and meta-level architectures * Educational approaches * Software adaptation and evolution * Configuration management * Artificial intelligence * Large and ultra-large-scale systems * Development methodologies * Development support and environments * Persistent systems * Scientific computing * Parallel and distributed computing * Data mining * Semantic web * Dynamic optimization * Innovative applications * Hardware and virtual machine support * Domain-oriented programming * Lisp pearls * Experience reports and case studies We also encourage submissions about past approaches that have been largely forgotten about, as long as they are presented in a new setting. Schedule Full manuscript due: Oct. 19, 2009 Acceptance notification: Nov. 23, 2009 Final manuscript due:Dec. 21, 2009 Submission: Concerning the preparation of the manuscript, please refer to the "Submission Procedure" page at the journal website, http://www.jucs.org/jucs_info/submissions. However, don't use the submission link on that page! Instead, papers must be submitted through http://www.easychair.org/conferences/?conf=lispjucs09. J.UCS - The Journal of Universal Computer Science - is a high-quality electronic publication that deals with all aspects of computer science. J.UCS has been appearing monthly since 1995 and is thus one of the oldest electronic journals with uninterrupted publication since its foundation. The journal is currently indexed in Thompson Scientific's ISI Journal Citation Reports (JCR). Reviewers for this special issue Marco Antoniotti, Università degli Studi di Milano Bicocca, Italy Giuseppe Attardi, Università di Pisa , Italy Pascal Costanza, Vrije Universiteit Brussel, Belgium Marc Feeley, Université de Montréal, Canada Richard P. Gabriel, IBM Research, USA Ron Garret, Amalgamated Widgets Unlimited, USA Scott McKay, ITA Software, Inc., USA Peter Norvig, Google Inc., USA Julian Padget, University of Bath, UK Kent Pitman, PTC, USA Christian Queinnec, Université Pierre et Marie Curie, France Christophe Rhodes, Goldsmiths College, University of London, UK Jeffrey Mark Siskind, Purdue University, USA Robert Strandh, Université Bordeaux 1, France Didier Verna, EPITA Research and Development Laboratory, France JonL White, TheGingerIceCreamFactory of Palo Alto, USA Taiichi Yuasa, Kyoto University, Japan Guest Editor António Menezes Leitão, Universidade Técnica de Lisboa, Portugal --~--~-~--~~~---~--~~ You 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 classpaths
Just build it :-) I used the source at http://github.com/richhickey/clojure/tree/master to build the clojure.jar Now everything works fine. Terrance Davis wrote: > The details help a lot. I was able to ensure I am doing the same steps > with a file not found exception instead of a working file. > > I notice that the you used 'clojure.jar' whereas I am using > 'clojure-1.0.0.jar'. Did you happen to compile your clojure.jar from > source? I used the current release download. I am starting to wonder > if I need to build from source to get this classpath problem to go > away. > > On Tue, Sep 1, 2009 at 12:05 PM, Krukow wrote: > >> >> On Sep 1, 5:03 pm, Terrance Davis wrote: >> >>> Okay. Here's some additional information. >>> >>> I have tried on OS X 10.6 and Vista and no dice either place. I am NOT >>> >> This works for me on Mac: >> krukow:~/examples$ ls -R >> classes clojure.jar src >> ./classes: >> ./src: >> clojure >> ./src/clojure: >> examples >> ./src/clojure/examples: >> hello.clj >> krukow:~/examples$ java -cp clojure.jar:./src:./classes clojure.main >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Clojure 1.1.0-alpha-SNAPSHOT >> user=> (compile 'clojure.examples.hello) >> clojure.examples.hello >> user=> (clojure.examples.hello.) >> # >> user=> ^D >> krukow:~/examples$ java -cp clojure.jar:./src:./classes >> clojure.examples.hello Karl >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Hello Karl! >> krukow:~/examples$ >> >> >> >> >> > > --~--~-~--~~~---~--~~ You 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 classpaths
you could try running this test script: http://gist.github.com/179346 the script downloads clojure and does a test aot compile. if everything works the only output you should see is "Hello World" example: hiredman rincewind ~% sh ./clojure-aot-test.sh Hello World On Tue, Sep 1, 2009 at 11:37 AM, Terrance Davis wrote: > > The details help a lot. I was able to ensure I am doing the same steps > with a file not found exception instead of a working file. > > I notice that the you used 'clojure.jar' whereas I am using > 'clojure-1.0.0.jar'. Did you happen to compile your clojure.jar from > source? I used the current release download. I am starting to wonder > if I need to build from source to get this classpath problem to go > away. > > On Tue, Sep 1, 2009 at 12:05 PM, Krukow wrote: >> >> >> >> On Sep 1, 5:03 pm, Terrance Davis wrote: >>> Okay. Here's some additional information. >>> >>> I have tried on OS X 10.6 and Vista and no dice either place. I am NOT >> >> This works for me on Mac: >> krukow:~/examples$ ls -R >> classes clojure.jar src >> ./classes: >> ./src: >> clojure >> ./src/clojure: >> examples >> ./src/clojure/examples: >> hello.clj >> krukow:~/examples$ java -cp clojure.jar:./src:./classes clojure.main >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Clojure 1.1.0-alpha-SNAPSHOT >> user=> (compile 'clojure.examples.hello) >> clojure.examples.hello >> user=> (clojure.examples.hello.) >> # >> user=> ^D >> krukow:~/examples$ java -cp clojure.jar:./src:./classes >> clojure.examples.hello Karl >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Unable to find a $JAVA_HOME at "/usr", continuing with system-provided >> Java... >> Hello Karl! >> krukow:~/examples$ >> >> > >> > > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: for those who just can't get enough of monads
Thanks for the link. I've tried and tried to understand monads, with little success. It's lead me to the conclusion that monads won't easily become one of the dominating approaches to program organization. This is because, as the document says, without an understanding of category theory, "it's like talking about electricity without using calculus. Good enough to replace a fuse, not good enough to design an amplifier." Yet the "easy introduction" to category theory in this document (and every other I've read) is anything but easy for software engineers otherwise unconcerned with advanced or abstract mathematics. For monads to gain widespread support, someone will have to do a few things. First encode monadic operations into the OOP features of Java or C#. Then use them to solve a bunch of problems familiar in those cultures in a way that the gains are substantial and obvious, without incurring the overhead of a complete code reorganization. Essentially, monads will have to find a bunch of back doors into the engineering toolbox, a little like LINQ in C# (the IQueryable API, not the special query syntax). Monads tutorials are simply not going to get the job done. On Aug 31, 12:45 pm, Raoul Duke wrote: > http://patryshev.com/monad/crashcourse.pdf > (via SVP) --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Clj-record
Hi John, Clj-record will make its way into production in a couple of weeks. It's been working flawlessly in high volume tests here. We added an adapter on our medical message bus to capture historical census data in messages. It records patient visits, employees dealing with patients, service requests, diagnoses, rooms, ... This is a must to deal with pandemics, it allows medical personnel to track down who's been in contact with other parties and which physical locations maybe contaminated. The adapter (Clojure) populates the census database (MySql) using clj-record. A Rail GUI allows immediate access to the database and a report engine (in progress) will allow management to pull out reports from it. Users can go back in the past to find out how diseases have spread out within the hospital. We think that we could add some intelligent tracking here to identify how a disease propagated given it's transmission pattern (by contact, air, ...) We got an emergency request from our pilot site to get this out since winter is coming by and all these flue viruses are evolving pretty fast. Hell of a summer here... so version 1.0 is now in acceptance test at the pilot site. Thank you for the good work, it's very useful :))) Luc Préfontaine Armageddon was yesterday, today we have a real problem... --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
JSwat not displaying line numbers, can't set breakpoints in clj file. (Newbie question!)
Hello, I'm a clojure newbie, with little java experience. I've been skimming the net the last few days trying to solve my problem. Could anyone help? Here it is: I followed the instructions given by Rich on how to use JSwat with Clojure. The only difference is I'm using JSwat 4.5, the latest official release, running on Mac OS X 10.6. (Note that I had the same problem on 10.5). I also read the extra info gathered on this group in the "Debugging with JSwat" thread. Problem: - Can't get the line numbers to show up on .clj files in JSwat (even after selecting the menu option...) - Can't set any line breakpoint on sessions attached to Clojure REPL. What I can do: - run Clojure in CLI or using VimClojure, no problem. - can attach to remote session on JSwat and Pause/Continue the main thread (I can see the effect on the REPL in a Terminal session). - can break on exceptions Do I have to compile in order to be able to debug my clj files? I naively thought you could work in User space and in one clj file and reload and run in JSwat, as Rich is hinting in his debugging page. Like I said, I'm not deeply familiar with Java (yet), so I thought this could be a classpath problem. I set my CLASSPATH environment variable to contain: - clojure installation dir with.jar - clojure/src - clojure-contrib.jar (not using it in my code yet) -clojure-contrib/src - vimclojure stuff - . (current dir) - ./classes (even though I have not compiled yet). If I try to execute a newline of code in the loaded clj file in JSwat, here's the error I get: VM suspended for session Session 1 Error in breakpoint: Line brain.clj:69 There is no line number information for user$eval__69 at com.bluemarsh.jswat.core.breakpoint.DefaultLineBreakpoint.resolveReference (DefaultLineBreakpoint.java:201) at com.bluemarsh.jswat.core.breakpoint.DefaultResolvableBreakpoint.resolveEagerly (DefaultResolvableBreakpoint.java:257) at com.bluemarsh.jswat.core.breakpoint.DefaultResolvableBreakpoint.connected (DefaultResolvableBreakpoint.java:82) at com.bluemarsh.jswat.core.session.SessionEvent$Type $2.fireEvent(SessionEvent.java:59) at com.bluemarsh.jswat.core.session.AbstractSession.addSessionListener (AbstractSession.java:74) at com.bluemarsh.jswat.core.breakpoint.DefaultBreakpointManager.addBreakpoint (DefaultBreakpointManager.java:70) at com.bluemarsh.jswat.ui.actions.RunToCursorAction.performAction (RunToCursorAction.java:101) at org.openide.util.actions.CallableSystemAction$1.run (CallableSystemAction.java:118) at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction (ActionsBridge.java:77) at org.openide.util.actions.CallableSystemAction.actionPerformed (CallableSystemAction.java:114) at javax.swing.AbstractButton.fireActionPerformed (AbstractButton.java:2028) at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351) at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed (DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:389) at com.apple.laf.ScreenMenuItem.actionPerformed (ScreenMenuItem.java:95) at java.awt.MenuItem.processActionEvent(MenuItem.java:627) at java.awt.MenuItem.processEvent(MenuItem.java:586) at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java: 317) at java.awt.MenuComponent.dispatchEvent(MenuComponent.java: 305) at java.awt.EventQueue.dispatchEvent(EventQueue.java:638) at org.netbeans.core.TimableEventQueue.dispatchEvent (TimableEventQueue.java:104) at java.awt.EventDispatchThread.pumpOneEventForFilters (EventDispatchThread.java:296) at java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:196) at java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:188) at java.awt.EventDispatchThread.run(EventDispatchThread.java: 122) Caused by: com.sun.jdi.AbsentInformationException at com.sun.tools.jdi.ReferenceTypeImpl.locationsOfLine (ReferenceTypeImpl.java:904) at com.bluemarsh.jswat.core.breakpoint.DefaultLineBreakpoint.resolveReference (DefaultLineBreakpoint.java:189) ... 27 more What am I missing here? There's got to be something obvious that I over-looked! I would greatly appreciate it if you could help! 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 cl
Is there a cleaner way to filter a map?
Hi everyone! I was wondering if there was a better idiom in Clojure for filtering items from a map... Suppose we want to remove all items from a map that have an odd number as a value. Here's how I'd write it: => (apply hash-map (apply concat (filter (fn [[key val]] (even? val)) {:dog 5 :cat 4 :mouse 7 :cow 6}))) {:cow 6, :cat 4} This is ugly. Is there a more elegant way to write this kind of code? Please share! 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: Is there a cleaner way to filter a map?
Conrad, (into {} (filter (fn [[key val]] (even? val)) {:dog 5 :cat 4 :mouse 7 :cow 6})) => {:cat 4, :cow 6} There's probably also a higher-order function that does what you want in contrib, something like (defn filter-map-v [f m] (into {} (filter (fn [[k v]] (f v)) m))) so that you can write (filter-map-v even? {:dog 5 :cat 4 :mouse 7 :cow 6}) I haven't looked for it, though. -R --~--~-~--~~~---~--~~ You 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 there a cleaner way to filter a map?
It's currently being discussed in contrib, but noting is final yet. On Sep 1, 7:44 pm, Richard Newman wrote: > Conrad, > > (into {} > (filter (fn [[key val]] > (even? val)) > {:dog 5 :cat 4 :mouse 7 :cow 6})) > > => > {:cat 4, :cow 6} > > There's probably also a higher-order function that does what you want > in contrib, something like > > (defn filter-map-v [f m] > (into {} > (filter (fn [[k v]] (f v)) m))) > > so that you can write > > (filter-map-v even? > {:dog 5 :cat 4 :mouse 7 :cow 6}) > > I haven't looked for it, though. > > -R --~--~-~--~~~---~--~~ You 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 there a cleaner way to filter a map?
Hi Conrad, I find this an interesting question because there is already a select function in clojure.set, but it only works on sets. Why shouldn't it work on maps? To make select work with maps we just replace disj with dissoc: (defn select "Returns a set of the elements for which pred is true" [pred xset] (reduce (fn [s k] (if (pred k) s (dissoc s (key k xset xset)) (def m {:dog 5 :cat 4 :mouse 7 :cow 6}) (select (comp even? val) m) {:cat 4, :cow 6} If select was to support maps there seem to be a number of options: 1) allow disj to work on maps as (dissoc s (key %)) 2) test if xset is a hashmap and use a different reduce function 3) have separate functions (or namespaces) 4) have a multi-method Regards, Tim. On Sep 2, 9:35 am, Conrad wrote: > Hi everyone! I was wondering if there was a better idiom in Clojure > for filtering items from a map... Suppose we want to remove all items > from a map that have an odd number as a value. Here's how I'd write > it: > > => (apply hash-map > (apply concat > (filter (fn [[key val]] > (even? val)) > {:dog 5 :cat 4 :mouse 7 :cow 6}))) > > {:cow 6, :cat 4} > > This is ugly. Is there a more elegant way to write this kind of code? > Please share! > > 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: Is there a cleaner way to filter a map?
Thanks for the info- Using "into" definitely cuts down a lot on the ugliness. --~--~-~--~~~---~--~~ You 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 for game programming?
I've been fiddling with the LWJGL [1] with a view to making a game for my children. It's slow going because when I learn more about Clojure I end up changing my mind about how I want things structured. OpenGL is all new to me as well - as is game programming in general. As part of my explorations I came across scratch [2]. It has an interesting approach where every object seems to live in its own thread. That seems to make dealing with state a lot simpler. My initial approaches have been complicated by the fact that the event loop makes handling state kind of disconnected. It would be great to be able to express things in a more linear way. This is what I'm exploring now. [1] http://www.lwjgl.org/ [2] http://scratch.mit.edu/ 2009/8/30 Elliott Slaughter > > Hi, > > I'm visiting from the Common Lisp game-dev crowd and wanted to try out > Clojure for writing games. > > I saw some JOGL examples posted in this group, in addition to the > cloggle library which wraps some JOGL functionality. Cloggle is pretty > thin right now and uses glFunctionNames as they are, so I've added > some patches to convert glFunctionNames to Lispier function-names, and > tried to Lispify the interface in general [1]. > > I think I'd be fairly comfortable writing a graphics engine with my > patched version of cloggle. What I'm not so sure about is writing the > game simulation model. > > All game simulation models I've seen used graphs of mutable objects; > I'm not entirely sure how to move to a more functional model. One the > one hand, reallocating the game world on every frame seems excessive > (even if Java's GC is fast), and on the other hand putting refs > everywhere a value could potentially change seems equally excessive > (and probably detrimental to performance). > > I just saw zippers on the other libraries page, but haven't had the > time to read it and don't know if it meets my needs or not. > > If anyone has suggestions on simulating interactions between trees of > objects (especially on the Clojure way to do it), I'd appreciate it. > Comments on my cloggle patches also welcome. > > [1] http://github.com/slaguth/cloggle/tree/master > > > > --~--~-~--~~~---~--~~ You 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 there a cleaner way to filter a map?
On Sep 1, 7:35 pm, Conrad wrote: > Hi everyone! I was wondering if there was a better idiom in Clojure > for filtering items from a map... Suppose we want to remove all items > from a map that have an odd number as a value. Here's how I'd write > it: I like to use "reduce" for processing maps: (reduce (fn [result [key value]] (if (even? value) (assoc result key value) result)) {} {:dog 5 :cat 4 :mouse 7 :cow 6}) This is slightly more efficient than (into {} ...), although transients may soon change that. -SS --~--~-~--~~~---~--~~ You 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: Clj-record
On Tue, Sep 1, 2009 at 4:43 PM, Luc Prefontaine wrote: > Hi John, > > Clj-record will make its way into production in a couple of weeks. > > It's been working flawlessly in high volume tests here. Hi Luc, That's great to hear. I recently set up a Google Group for clj-record, so you may want to sign up. http://groups.google.com/group/clj-record-dev It's very low-volume. In fact, it's basically no-volume. :) Thanks for the encouragement. -hume. -- http://elhumidor.blogspot.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Is there a cleaner way to filter a map?
Hi, Am 02.09.2009 um 01:44 schrieb Richard Newman: (into {} (filter (fn [[key val]] (even? val)) {:dog 5 :cat 4 :mouse 7 :cow 6})) And to show one more road to Rome (where all roads lead to): (into {} (for [[k v] the-map :when (even? v)] [k v])) Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature