Re: JavaWorld article
The article I wrote just came out at JavaWorld http://www.JavaWorld.com (archived here) http://www.javaworld.com/javaworld/jw-05-2009/jw-05-clojure.html. Hopefully this article will influence Java developers to give Clojure a try. Thanks to Rich and to the whole Clojure community: The responsiveness, the skill, the quality and power of the code, never cease to amaze me. Thanks also to everyone who read and commented on the article. Regards, Joshua On Wed, Mar 4, 2009 at 8:33 PM, Joshua Fox joshuat...@gmail.com wrote: I am working on a short article to appear in JavaWorld sometime this spring. Its goal is to encourage senior Java developers to learn more about Clojure. The audience is experienced and knowledgeable about Java, but LISP to them is a distant memory from college. So, rather than present a tutorial, or an advanced study of language features, I focus on comparing language constructs in Clojure to similar (often inferior) ones in Java If anyone would like to comment on a draft, please contact me offline. I'd appreciate the input. Joshua --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Saving repl functions
When I have been experimenting on the REPL, I sometimes want to save my work. Is there a way of serializing an image of the REPL into Clojure sourcecode? Joshua --~--~-~--~~~---~--~~ 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 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: Trying to get a list of random numbers using repeat
Why presumably with side effects?Otherwise you would use repeat. A pure function returns the same value every time, so there is no reason to call it repeatedly. Joshua On Tue, Mar 24, 2009 at 10:04 AM, Paul Drummond paul.drumm...@iode.co.ukwrote: 2009/3/23 Krešimir Šojat kso...@gmail.com: (rand-int 49) will produce one integer, and repeat will repeat it 10 times, that is why you see same number repeated. How embarrassing! As soon as I switched my machine off last night I realised rand-int was only being called once - of course it was! I did consider 'repeatedly' but I couldn't get it to work for some reason - thank you for showing me how to use it. Also, I was put off from using it when I read its doc-string which says: Takes a function of no args, presumably with side effects, and returns an infinite lazy sequence of calls to it Why presumably with side effects? Cheers, Paul. -- Iode Software Ltd, registered in England No. 6299803. Registered Office Address: 12 Sancroft Drive, Houghton-le-Spring, Tyne Wear, DH5 8NE. This message is intended only for the use of the person(s) (the intended recipient(s)) to whom it is addressed. It may contain information which is privileged and confidential within the meaning of applicable law. If you are not the intended recipient, please contact the sender as soon as possible. The views expressed in this communication may not necessarily be the views held by The Company. --~--~-~--~~~---~--~~ 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 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: simple debugging utility
Eric Rochester has a debug macro, together with a walkthrough of how he built it, here http://writingcoding.blogspot.com/2008/09/stemming-part-19-debugging.html Joshua On Tue, Mar 24, 2009 at 4:43 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote: I want to write a function or macro that allows me to output the value of an expression without repeating it. For example, I want something like (dump (+ 1 2)) to output (+ 1 2) = 3. This works. (defn dump1 [string] (println string = (load-string string))) (dump1 (+ 1 2)) Note how I had to put the expression passed to dump1 in quotes to make a string. I'm wondering if there is a way to avoid that using a macro. The hard part is printing the expression. The following doesn't work. It outputs 3 = 3. (defmacro dump2 [expr] `(let [value# ~expr] (pr ~expr) (println = value#))) (dump2 (+ 1 2)) -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Information Hiding
Any other tricks or techniques There is defn- http://clojure.org/api#toc189 as well as the :private metadata tag. Joshua --~--~-~--~~~---~--~~ 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 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: Information Hiding
I was envisioning .. only traverse the public keys You could provide a function which uses select-keys to return a new map with only the public* *keys. This can be seen as an interface into the map held in the ref for read access, though not for write. Joshua --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
What makes Clojure an easier Lisp?
I dove into Lisp and Scheme several times in the past, but only with Clojure did Lisp really catch? 1. Clojure abandons the 1950's cruft, with all-caps and abbreviations like SETQ and CDR. However, Scheme does this too, without achieving the ease of Clojure. 2. Clojure is typically illustrated with simple, practical examples. Other Lisps are often introduced as tools for theory. Not that there's anything wrong with that, like they said on Seinfeld. On the other hand, Clojure's examples are often, for better or worse, somewhat more sophisticated than the typical examples used for teaching other languages. 3. Clojure has some syntax choices that make it more readable. It specifies the use of fewer parentheses and uses three types brackets rather than just parentheses. However, some dialects of Lisp do allow the mixture of bracket types for visual variety. 4. The connection to Java, even if not essential to most introductory examples, provides a lifeline for the user. 5. Even though pure-functional is not what most programmers are used to, once you learn it, it makes everything else easier; in contrast to non-pure-functional Lisp dialects Any other thoughts on this? Joshua --~--~-~--~~~---~--~~ 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 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: March 20th 2009 Rich Hickey Appreciation Day!
Hear, Hear! It was far more natural to learn than Lisp and Scheme. The language has lots of brilliant features that make me think I wish I had thought of that. And I like the way Rich has built the community. Joshua --~--~-~--~~~---~--~~ 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 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: Request Feedback on Clojure Blog Article
I like the sequential let too. For one thing, it allows for the breaking apart of complex expressions into more comprehensible parts, with well named intermediate variables resulting in self documenting code. About the 7-part *let* as shown in your example: Could we get some opinions about whether it is idiomatic Clojure? I thought of *let *as a sort of variable declaration, and so, one would want to keep it simple and not do complex calculations in the *let *binding expressions. On the other hand, the sequential mutually-dependent *let *bindings are of course legal Clojure and completely immutability-safe. If it is considered idomatic, then that's great, as it safely simulates the sequential building up of values usual to procedural programs. Joshua --~--~-~--~~~---~--~~ 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 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: Request Feedback on Clojure Blog Article
Great article! Although I’ve done only a little Ruby metaprogramming, my sense is that Clojure’s macros make it more powerful than Ruby in this respect It would be good to see a comparison of metaprogramming with macros. They sometimes are used for similar purposes, but of course are not the same thing. Joshua --~--~-~--~~~---~--~~ 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 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: Request Feedback on Clojure Blog Article
On Wed, Mar 18, 2009 at 10:40 PM, Stephen C. Gilardi squee...@mac.com wrote: Because parallel bindings are also useful Could you explain? I don't understand the justification for let in Lisp, when let* seems so much more useful. Joshua --~--~-~--~~~---~--~~ 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 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: Main Function for Program Entry Point
Of course, defining the function makes it easier to invoke your code if you think it might have wider usefulness. Joshua On Sun, Mar 15, 2009 at 3:55 AM, Keith Bennett keithrbenn...@gmail.comwrote: Is it a good idea or a bad idea to provide a main() function as the program's entry point? As an example, I have a program at http://is.gd/ndTV. If you look at the bottom you'll see (unless and until I change it) the specification of a main function, and then a call to it. I'm aware that I could just list the contents of main() outside any function, and it would work the same way. So which approach is better, and why? Thanks, Keith --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Bytecode optimization
I was just reading thishttp://developer.amd.com/documentation/Articles/pages/01302008_jvm.aspx and wondering: Does Clojure's pure-functional design enhance VM-level bytecode optimization by simplifying escape analysis? Joshua --~--~-~--~~~---~--~~ 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 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: Capitalize string
How about this? user= (defn upper-first [s] (apply str (Character/toUpperCase (first s)) (rest s))) #'user/upper-first user= (upper-first a) A On Sun, Mar 8, 2009 at 3:39 PM, David Sletten da...@bosatsu.net wrote: Is there a function to capitalize the first letter of a string or a better way than this idiotic code? (apply str (map #(if (zero? %2) (Character/toUpperCase %1) %1) clojuriffic (iterate inc 0))) Aloha, David Sletten --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
What is Clojure NOT good for?
Is it fair to say that Clojure shines in algorithmic processing, string processing, concurrency management, but that there are better choices in other areas: - Application programming , where the key challenge is fitting a standard three-tier application to the business domain. - Enterprise programming, where the challenge is gluing together overweight and fragile libraries, and one should always use exactly the set of software which the API creators envisioned? Rich himself has suggested something along these lines, but I wonder what others think. Joshua --~--~-~--~~~---~--~~ 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 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's syntax design: macros vs functions
expressions get evaluated and which don't, at least when you are dealing with side effects. I think that this is the key point. The Clojure syntax is built around its pure-functional core. Side effects are dangerous, and the rule there is mutator beware. Joshua --~--~-~--~~~---~--~~ 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 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: Inclusive-exclusive range
With pointer-based strings or arrays, as in C , it is natural to start at index 0, so that you can do pointer arithmetic: address+0 is the first character/item. Then, if you have a string or array of length n, the last item is at n-1. Joshua On Wed, Mar 4, 2009 at 2:07 PM, Mibu mibu.cloj...@gmail.com wrote: Why does range in Clojure use an inclusive-exclusive range? I'm aware of the traditional substring range convention, which always puzzled me as to how an unintuitive and error-prone use became cemented as the norm. I'm not calling for a change in range. I'm just genuinely curious. --~--~-~--~~~---~--~~ 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 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: Inclusive-exclusive range
This is discussed, with references, here http://en.wikipedia.org/wiki/Array#Index_of_the_first_element --~--~-~--~~~---~--~~ 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 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 creates lots of classloaders
I think it is the best way to load and discard lots of dynamically-loaded and in fact dynamically-generated classes. Joshua On Wed, Mar 4, 2009 at 5:21 PM, Hendrik geheimm...@gmail.com wrote: Hi, I got a question: Clojure seems to create poopillions of DynamicClassLoader instances. Why does it do that? Could I try patching it so that it creates less of them? I need this cause I ran into trouble working with JNI. I looked at the Clojure source rev 1323. I'm no expert, this is my first look at the sources, but the following struck me as hack-ish: (from Compiler.java, shortened slightly) public static Object eval(Object form) throws Exception{ if(true)//!LOADER.isBound()) makeClassLoader(); To me, that looks like for evaluating _every form_, a new classloader gets created. Isn't that a bit much? Also, it looks temporary that the if() has its condition commented out and replaced with true ... :-/ So Clojure's behavior seems to have been different at some point in the past. Thanks a bunch for your opinions. Cheers Hendrik Details: I'm asking because I was loading a native library through JNI. The rule here (apparently) is that you can load a library through only one classloader, not the same library through several loaders. For example, this program fails: (System/load /home/hk/inotify-java-0.1/build/native/libinotify- java.so) (System/load /home/hk/inotify-java-0.1/build/native/libinotify- java.so) I feel that the program should work. Apparently Clojure creates new classloaders between line 1 and 2. An equivalent Java program does work (the first System.load() loads the library, the second sees the library is already loaded and does nothing). This is the exact error message: $ cat t3.clj (System/load /home/hk/inotify-java-0.1/build/native/libinotify- java.so) (System/load /home/hk/inotify-java-0.1/build/native/libinotify- java.so) (println 42) $ java -jar /home/hk/clojure-svn-2/clojure.jar t3.clj java.lang.UnsatisfiedLinkError: Native Library /home/hk/inotify- java-0.1/build/native/libinotify-java.so already loaded in another classloader (t3.clj:0) at clojure.lang.Compiler.eval(Compiler.java:4533) at clojure.lang.Compiler.load(Compiler.java:4846) at clojure.lang.Compiler.loadFile(Compiler.java:4813) at clojure.main$load_script__5685.invoke(main.clj:206) at clojure.main$script_opt__5716.invoke(main.clj:258) at clojure.main$main__5740$fn__5742.invoke(main.clj:333) at clojure.main$main__5740.doInvoke(main.clj:328) 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.UnsatisfiedLinkError: Native Library /home/hk/ inotify-java-0.1/build/native/libinotify-java.so already loaded in another classloader at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1743) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1674) at java.lang.Runtime.load0(Runtime.java:770) at java.lang.System.load(System.java:1005) at user$eval__4.invoke(t3.clj:2) at clojure.lang.Compiler.eval(Compiler.java:4522) ... 11 more $ --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
warning on mutation
Can Clojure generate warnings when a function has side effects, particularly in transactions and other places where one should avoid them? Perhaps just a warning on access to any objects other than those of Clojure types and pre-approved immutable Java types (String, Number, etc.)? Joshua --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
JavaWorld article
I am working on a short article to appear in JavaWorld sometime this spring. Its goal is to encourage senior Java developers to learn more about Clojure. The audience is experienced and knowledgeable about Java, but LISP to them is a distant memory from college. So, rather than present a tutorial, or an advanced study of language features, I focus on comparing language constructs in Clojure to similar (often inferior) ones in Java If anyone would like to comment on a draft, please contact me offline. I'd appreciate the input. Joshua --~--~-~--~~~---~--~~ 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 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: Opinions on - macro?
Meikel and eyeris, Thanks, that clarifies the usage of - even multiple parameters. IMHO, - simplifies things where unary functions are involved and where the list-parens are absent, so that - creates the list. In the other cases, the standard syntax is easier on the eye. Joshua On Sun, Mar 1, 2009 at 12:17 AM, eyeris drewpvo...@gmail.com wrote: You are wrong. Many writings use ,, as a place-holder for where - is placing the argument. Take Meikel's example above: (foo (bar (baz (frobnicate a-thing)) bla)) Becomes (- a-thing frobnicate baz (bar bla) foo) So bar is a function of more than one argument. Re-written with place- holders it would be: (- a-thing (frobnicate ,,) (baz ,,) (bar ,, bla) (foo ,,)) Does that make it more clear? -Drew On Feb 28, 9:39 pm, Joshua Fox joshuat...@gmail.com wrote: - confuses me: Does it treat functions with multiple parameters different from functions with one parameter? Am I right that it can only be used with the latter? Joshua --~--~-~--~~~---~--~~ 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 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: Internal structure of evaluation results
I find it confusing. Nothing seems to be where it should be, there are almost no examples Just my opinion, but I think that Clojure is very well documented, both on clojure.org and on various online articles. But I'm tired of doing it every time when some (sub)results type gets changed In good encapsulated fashion, Clojure guarantees the interface of its returned objects, but not the implementation class to its documentation How about doc and find-doc user= (doc +) user= (find-doc vec) ... namespace names ...distinct intern or public names Take a look at fnuctions mentioned here http://clojure.org/namespaces like ns-name http://clojure.org/api#ns-name ns-aliaseshttp://clojure.org/api#ns-aliases ns-imports http://clojure.org/api#ns-imports ns-internshttp://clojure.org/api#ns-interns ns-map http://clojure.org/api#ns-map ns-publicshttp://clojure.org/api#ns-publics ns-refers http://clojure.org/api#ns-refers Joshua On Sun, Mar 1, 2009 at 10:15 PM, David david.ra...@gmail.com wrote: Every now and again I try to get serious about learning Clojure and every time I quit due to its documentation. I find it confusing. Nothing seems to be where it should be, there are almost no examples etc. So, every time I end up writing (in Java, I might add) a documentation browser with index, full-text search support, bookmarks (something similar to Eclipses help system or kchmviewer) and maybe a possibility of adding custom examples to meta :doc with aspiration of building a personal tutorial as I go along. I can't seem to find a way of obtaining that information from Clojures runtime in a standard manner, however. I tried tackling the 'problem' with evaluating a (map meta (reduce concat (map vals (map ns- publics (all-ns) and then parsing the result using Clojures java classes. I can do that without major problems. But I'm tired of doing it every time when some (sub)results type gets changed (the last one was from LazyCons to LazySeq) and I naively update everything from the SVN. Is there any guarantee with regard to the internal structure of evaluation results (speaking in Java terms)? If not, is there something planed to that effect for official release(s)? Alternatively, what's the best (quickest, most robust, ...) way of obtaining Clojures runtime info in a manner similar to this: MapString, interns // keys == distinct namespace names interns: MapString, meta // keys == distinct intern or public names meta: MapString, String (or MapString, ListString for the sake of arguments ;-) ) // keys == meta names in a sentence: something that could be parsed from within Java using java.lang.String and Java collection classes? Regards, 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 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: Opinions on - macro?
- confuses me: Does it treat functions with multiple parameters different from functions with one parameter? Am I right that it can only be used with the latter? Joshua --~--~-~--~~~---~--~~ 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 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: Extensive use of let?
Of course, the use of let does not make the code any more imperative or less functional, as long as there are no side effects. Also, the scope is limited to the let block, keeping it clean, and there should be no harm to performance. IMHO, the code with let is simply more readable and therefore more elegant. Joshua On Wed, Feb 25, 2009 at 10:57 PM, levand luke.vanderh...@gmail.com wrote: Recently, in my code, I have been struggling with which of the two equivalent forms is, in a general sense, better. (defn my-fn1 [input] (let [value1 (op1 input) value2 (op2 input) value3 (op4 value1 value2)] (op5 value3))) (defn my-fn2 [input] (op5 (op4 (op1 input) (op2 input Now, the second is definitely cleaner and more elegant, besides being smaller, which is a non-trivial benefit when I have a fair amount of code to page through. However, if I've been away from the code awhile, it's much easier to come back determine what the code is doing when its written the first way, especially when it uses descriptive names. An operation that is impenetrable when written in nested form can become quite simple when each step is broken down and labeled. Clojure is my first Lisp - should I just stick with the second form until I learn to see through the nested s-expressions? It's not that I'm trying to make my code more imperative - Although I come from a Java background, I love functional programming, and it is a delight to see how much I can do without side-effects. But I do miss the self-documentation that well-named variables can provide. Any thoughts? Also, is there any performance degradation from the first way, or can the compiler optimize it away? --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Why pass bindings as vector
Why do many core macros pass bindings as a vector, then destructure them in various ways into symbols and values. This is instead of just providing the symbol and value, e.g., (defmacro my-macro [s v body] `(let [~s ~v] ... In at least five macros in core.clj, this was changed recently, as validated by an IllegalArgumentException. What is the reasoning behind the newer design? In some cases, I think this is done because there could be multiple pairs of symbol-values in the bindings, but in other cases, the vector is expected to have exactly two items. Joshua --~--~-~--~~~---~--~~ 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 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: alternate syntax
It's a good idea. Not for anyone to actually use, but as an demonstration of code is data, and of the separation of surface syntax from the code data-structure. Can you do this without reader macros? Can you keep it homoiconic? (Apparently so, given the transformation rules, but I wonder if there are any corner cases.) Joshua On Mon, Feb 23, 2009 at 5:42 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote: I have an idea I'd like to float to see if there are reasons why it's a bad idea. What if Clojure had an alternate surface syntax that was translated into standard Clojure syntax by a kind of preprocessor? Many people that don't like Lisp dialects don't like them because of the parentheses. I'm trying to address that. Here's a simple example of valid Clojure code. (defn pig-latin [word] (let [first-letter (first word)] (if (.contains aeiou (str first-letter)) (str word ay) (str (subs word 1) first-letter ay (println (pig-latin red)) (println (pig-latin orange)) Here's what that same code would look like in my alternate syntax. defn pig-latin [word] let [first-letter (first word)] if .contains aeiou (str first-letter) str word ay str (subs word 1) first-letter ay println (pig-latin red) println (pig-latin orange) The rules for turning this into standard Clojure syntax are pretty simple. 1) If a line is indented farther than the previous one, it is part of the previous line. 2) If a line doesn't start with a (, then add one. 3) If the next line is indented less than this one, add the appropriate number of )'s at the end. 4) If the first token on a line is if and the first non-whitespace character after it is not ( then assume the rest of the line is the condition and wrap it in ( ). A translation from standard Clojure syntax to this alternate form should also be possible. Is this a bad idea? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: building a class or jar file from clojure
Ahead of Time compilation might be what you are looking for . This lets you distribute.class files rather than your .clj source files, and makes for slightly faster code at startup. http://groups.google.com/group/clojure/msg/58e3f8e5dfb876c9 Joshua On Mon, Feb 9, 2009 at 6:52 PM, hank williams hank...@gmail.com wrote: How does one make a standard clojure based class file or jar file without embedding clojure source files. Hank -- blog: whydoeseverythingsuck.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 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: Programming Clojure sample code: fixes for breaking changes
A related point about the validator function (for Refs), possible the result of the same change in the Clojure codebaseOn page 133 of Beta 5.0, (def messages (ref () :validator validate-message-list) The code samples, using, the bundled clojure, do work. However, right above the code on p. 133, the keyword :validate is given instead. Using the Clojure release of Dec. 17,http://clojure.googlecode.com/files/clojure_20081217.zip that line of code does not work. I get to it work by eliminating the :validatorkeyword and passing the function as an additional parameter; following this documentation http://clojure.org/api#toc434 Joshua On Fri, Jan 16, 2009 at 5:37 PM, Telman Yusupov use...@yusupov.com wrote: Thank you very much, Stuart! I think it's a good idea for me to start reading Clojure source code and keep track of the changes, as the language changes so quickly... On Jan 16, 10:02 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Hi Telman, The signature for agent has changed. Use: (def counter (agent 0 :validator number?)) I will update the prose in Beta 6. Stuart I keep running into the following problem trying to supply agent validation function. Here is sample code from page 135 (from book version beta 5) (use '[clojure.contrib.except :only (throw-if)]) (def counter (agent 0 #(throw-if (not (number? %)) not a number))) triggers the following exception: java.lang.IllegalArgumentException: No value supplied for key: user $fn__1...@89f302 (NO_SOURCE_FILE:2) [Thrown class clojure.lang.Compiler$CompilerException] I'm using the latest versions of clojure (r1216) and clojure-contrib (r374) on Mac OS X 10.5.6, Java version 1.5.0_16 Many thanks, Telman On Jan 16, 8:49 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Long, long ago (Tuesday) when Beta 5 of the book shipped, there were some breakages in the sample code due to changes in clojure- contrib. I believe everything is now fixed in the github repository ( http://github.com/stuarthalloway/programming-clojure ). Summary of the issues: 1. clojure.contrib.seq-util/includes? changed the argument order for consistency with other operations. This caused problems with the snippet web app; Compojure is now updated to match the change in contrib. 2. clojure.contrib.sql/with-results has been removed and replaced with with-query-results. This broke the snippet model. The code is now fixed and I will update the prose in the next Beta. 3. A change to clojure.lang.Util necessitated a _clean_ rebuild of contrib and compojure. I have rebuild these dependencies in the lib directory. 4. A change to clojure.contrib.test-is.is broke a few unit tests. The book doesn't reference any of these tests directly, but they are now fixed in the code. You can run the whole test suite with ./ runtests.sh. Let me know if you find any other issues! Thanks, Stuart --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---