Gosling on Clojure
Hi, anybody seen this already? http://www.basementcoders.com/transcripts/James_Gosling_Transcript.html (Transcript from http://basementcoders.com/?p=721) When being asked about other languages he says: Clojure. Clojure's got a lot of coolness about it but it's not for everyone. Kind regards, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
How to write this in Clojure? Example from PAIP
Hallo all, I'm started working on PAIP and doing the examples in Clojure. I understand what this function does (i think) now but I'm not sure how to write it in Clojure since I have no CL background. (defun find-all (item sequence rest keyword-args key (test #'eql) test-not allow-other-keys) Find all those elements of sequence that match item, according to the keywords. Doesn't alter sequence. (if test-not (apply #'remove item sequence :test-not (complement test-not) keyword-args) (apply #'remove item sequence :test (complement test) keyword-args))) So I just wanted to drop it in here. Can you make a idiomatic clojure version? -- 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: Generating type hints dynamically
nathanmarz wrote: That worked great, thanks. Could you please post the working example you got? Regards, Shantanu -- 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: Generating type hints dynamically
Hi, On 29 Sep., 11:28, Shantanu Kumar kumar.shant...@gmail.com wrote: Could you please post the working example you got? (defmacro hinted-fn [class-sym] (let [arg (gensym arg)] `(fn [~(with-meta arg {:tag class-sym})] (.get_val ~arg Hope that helps. 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: lein swank Aquamacs slime-connect test failed. Help!
On Sep 29, 1:08 pm, Phil Hagelberg p...@hagelb.org wrote: On Tue, Sep 28, 2010 at 4:17 AM, Alex yal...@gmail.com wrote: $ lein swank user= Connection opened on local port 4005 #ServerSocket ServerSocket[addr=localhost/ 127.0.0.1,port=0,localport=4005] First question: why no visible output? Running lein swank just launches a swank server. It doesn't run any of your project's code. Once you connect via slime, you can use C-c C-k to compile a given namespace. But generally it's poor form to have side-effects in the top-level; you should wrap your code in a defn and run that function at the repl. Understood. I need to read more on this because I'm not clear then on how to launch a simple print X to stdout, sleep, then loop app, while being able to communicate with it from emacs, and seeing consequent changes in the app's output. Aquamacs: I hear you. I came to the same conclusions last night and am now running emacs 23. Thanks again Alex -- 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: How to write this in Clojure? Example from PAIP
On Sep 29, 2010, at 3:55 AM, nickikt wrote: (defun find-all (item sequence rest keyword-args key (test #'eql) test-not allow-other-keys) Find all those elements of sequence that match item, according to the keywords. Doesn't alter sequence. (if test-not (apply #'remove item sequence :test-not (complement test-not) keyword-args) (apply #'remove item sequence :test (complement test) keyword-args))) Both Clojure and Common Lisp have a function to remove a value from a sequence. However, the CL version supports quite a few more options, which accounts for the complexity of this FIND-ALL function. The function 'remove' in both languages obviously has to take an item to look for and a sequence to search. But the CL version also accepts various keyword arguments that tailor how it behaves. There is a default test which determines whether the item matches a given element, but another test can be specified by the :test keyword. This allows for various flavors of equality when matching. There is also a :test-not keyword which works in the opposite sense. You can see both of those keywords above. The CL version also accepts other keywords such as :start, :end, :from-end, :count, and :key. In the section after the lambda-list keyword key above you can see that FIND-ALL also accepts :test and :test-not keywords, with a default :test of the function EQL. The lambda-list keyword allow-other-keys is used to show that FIND-ALL will also accept the other REMOVE keywords and pass them along. Before the key section, however, there is the rest section. What actually happens is that every argument passed to FIND-ALL, besides the first two required arguments, is captured as a list in the variable KEYWORD-ARGS. CL also processes the :test and :test-not keyword arguments separately, but they and their keywords are also bundled up in KEYWORD-ARGS. This makes it easy to pass everything along to REMOVE via the APPLY form. Here is a Clojure implementation that is pretty true to the spirit of the CL version. All of the optional arguments are captured in the list 'keyword-args', but we also break out the keywords into a map: (defn find-all [item coll keyword-args] (let [keywords (apply hash-map keyword-args)] (if (:test-not keywords) (remove (fn [elt] ((:test-not keywords) item elt)) coll) (remove (fn [elt] (not ((:test keywords) item elt))) coll Since we want to find things that match our criterion we reverse the sense of the :test and remove things that fail our criterion. But we have to do the opposite with the :test-not case here since Clojure's 'remove' doesn't understand that :test-not is the opposite of :test. Notice also that we can call 'remove' directly (without 'apply') since we aren't passing in a list of keywords. (find-all 1 '(1 2 3 2 1) :test =) = (1 1) (find-all 1 '(1 2 3 2 1) :test not=) = (2 3 2) (find-all 1 '(1 2 3 2 1) :test-not =) = (2 3 2) Have all good days, 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 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
prn-str and lists
Hello, I have some questions about how to use the prn functions. From the documentation of the prn function: [...] By default, pr and prn print in a way that objects can be read by the reader [...] In this case, why does the prn-str function does not quote sequences? For instance (pr-str '(+ 1 2)) returns (+ 1 2), which can not be read back since (eval (read-string (pr-str '(+ 1 2 returns 3! There is the *print-dup* function but it does not produce a string readable by an (advanced) user: (binding [*print-dup* true] (pr-str '(+ 1 2))) returns ^#=(clojure.lang.PersistentArrayMap/create {:line 1}) (+ 1 2) where I just would like to display to the user '(+ 1 2) So how can one print and read back quoted s-expressions so that a user can modify them? I have implemented a pr-str-data function: (defn- pr-str-data [data] (if (seq? data) (str ' (pr-str data)) (pr-str data))) but there should be a better way. Thanks in advance for your help. -- 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.string
On 09/24/2010 01:45 PM, Rasmus Svensson wrote: 2010/9/24 cej38 junkerme...@gmail.com: I noticed that clojure.string is not showing up on the API webpage, http://clojure.github.com/clojure/, is that an oversight? All the clojure.java.* namespaces and clojure.test are gone too... I don't think this is intentional... I reported the problem on IRC, and they've fixed it. Tim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to write this in Clojure? Example from PAIP
Hi, a slight enhancement for 1.2: Clojure now supports keyword arguments directly. (defn find-all [item coll {:keys [test test-not] :or {test =}}] (if test-not (remove #(test-not item %) coll) (filter #(test item %) coll))) 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: prn-str and lists
Hi, On 29 Sep., 15:33, K. kotot...@gmail.com wrote: For instance (pr-str '(+ 1 2)) returns (+ 1 2), which can not be read back since (eval (read-string (pr-str '(+ 1 2 returns 3! Here is your misunderstanding. Reading ends at read-string. When you look at the result you will find a list with the symbol + and the two numbers 1 and 2. eval is evaluation and a complete separate issue. 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: prn-str and lists
Ok, I see. The example from http://clojuredocs.org/v/1859 did mislead me and is incorrect. Thanks for your answer. -- 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: prn-str and lists
(pr-str '(+ 1 2)) : pr-str is not given code-as-data , because it's not a macro. pr-str is given the result of first evaluating its arg, that is '(+ 1 2). And evaluating '(+ 1 2) results in the list (+ 1 2). So pr-str is right, your assumptions were wrong. To achieve your goal, just use (pr-str ''(+ 1 2)). HTH, -- Laurent 2010/9/29 K. kotot...@gmail.com Hello, I have some questions about how to use the prn functions. From the documentation of the prn function: [...] By default, pr and prn print in a way that objects can be read by the reader [...] In this case, why does the prn-str function does not quote sequences? For instance (pr-str '(+ 1 2)) returns (+ 1 2), which can not be read back since (eval (read-string (pr-str '(+ 1 2 returns 3! There is the *print-dup* function but it does not produce a string readable by an (advanced) user: (binding [*print-dup* true] (pr-str '(+ 1 2))) returns ^#=(clojure.lang.PersistentArrayMap/create {:line 1}) (+ 1 2) where I just would like to display to the user '(+ 1 2) So how can one print and read back quoted s-expressions so that a user can modify them? I have implemented a pr-str-data function: (defn- pr-str-data [data] (if (seq? data) (str ' (pr-str data)) (pr-str data))) but there should be a better way. Thanks in advance for your help. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to write this in Clojure? Example from PAIP
Thx, for your answers. Helps alot. I think the clojure version is cleaner. The meaning of all those ... words are confusing in CL. -- 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: How to write this in Clojure? Example from PAIP
On Sep 29, 2010, at 11:01 AM, Meikel Brandmeyer wrote: Hi, a slight enhancement for 1.2: Clojure now supports keyword arguments directly. (defn find-all [item coll {:keys [test test-not] :or {test =}}] (if test-not (remove #(test-not item %) coll) (filter #(test item %) coll))) That's really nice Meikel. I was trying to remember how to do the new keywords, but I couldn't find an example. You have the default value for :test in there too. Interesting idea to replace 'remove not' with 'filter'. Have all good days, 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 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
dj updates
Hello all, I made an update to dj, for those who care. The new branch generaldeps supports proper SNAPSHOT behavior and has been reworked to support generically different types of dependencies. Accessible at git://github.com/bmillare/dj.git I've also compiled a more concise feature list. # Feature list * Practically no dependencies, only needs clojure and java, simplifying deployment of dj on to many systems * Supports source dependencies, you can have your project depend on other projects you are developing. * Everything is installed locally to a directory, no messing up existing configuration files and repositories. If you want, you can have multiple dj distributions on the same computer. This should simplfy deploying dj onto different systems. * Classpath is computed during runtime. No forking of the jvm is required. No copying or symlinking of jar files. * Supports native dependencies * Extracts dependency information from project.clj file just as leiningen and cake do * Easy to extend adding new dependency types or new tasks -- 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: How to write this in Clojure? Example from PAIP
Hi, Am 29.09.2010 um 21:37 schrieb David Sletten: I was trying to remember how to do the new keywords, but I couldn't find an example. You have the default value for :test in there too. It's basically normal map destructuring in the varags position, ie. after the in the argument list. 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
Find file from namespace symbol
Hi all, Anyone know of a utility that returns a absolute filename given a namespace symbol? Actually what I'm trying to do is adjust ring.middleware.reload to only reload source files if they've changed (otherwise I run into problems with session management), so if anyone knows of utilities that already do that, or utilities to help me to determine when a file changes that would be pretty useful too. Cheers, David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Find file from namespace symbol
On Wed, 29 Sep 2010 at 15:18, David Jagoe wrote: Anyone know of a utility that returns a absolute filename given a namespace symbol? If you're using Emacs/SLIME, you could use swank-clojure's classpath browsing information. The var available-classes in namespace swank.util.class-browse holds clojure namespaces and java classes on the classpath as a list of maps. For example to see where the clojure.set namespace comes from: user (clojure.pprint/pprint (filter #(= (:name %) clojure.set) swank.util.class-browse/available-classes)) ({:loc /home/jeff/.clojure/clojure-1.3.0-alpha1.jar, :file clojure/set__init.class, :name clojure.set}) The same applies to java classes: user (clojure.pprint/pprint (filter #(= (:name %) java.net.Socket) swank.util.class-browse/available-classes)) ({:loc /usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar, :file java/net/Socket.class, :name java.net.Socket}) The map keys are as follows: :name Java class or Clojure namespace name :loc Classpath entry (directory or jar) on which the class is located :file Path of the class file, relative to :loc Also see: (doc swank.util.class-browse) Hope this helps! - Jeff -- 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: Find file from namespace symbol
swank.commands.basic (find-ns-definition 'clojure.set) ((clojure.set (:location (:zip /home/scott/project/lib/clojure-1.2.0-master-20100813.160144-94.jar clojure/set.clj) (:line 1) nil))) Scott On Wed, Sep 29, 2010 at 6:34 PM, Jeff Valk jv-li...@tx.rr.com wrote: On Wed, 29 Sep 2010 at 15:18, David Jagoe wrote: Anyone know of a utility that returns a absolute filename given a namespace symbol? If you're using Emacs/SLIME, you could use swank-clojure's classpath browsing information. The var available-classes in namespace swank.util.class-browse holds clojure namespaces and java classes on the classpath as a list of maps. For example to see where the clojure.set namespace comes from: user (clojure.pprint/pprint (filter #(= (:name %) clojure.set) swank.util.class-browse/available-classes)) ({:loc /home/jeff/.clojure/clojure-1.3.0-alpha1.jar, :file clojure/set__init.class, :name clojure.set}) The same applies to java classes: user (clojure.pprint/pprint (filter #(= (:name %) java.net.Socket) swank.util.class-browse/available-classes)) ({:loc /usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar, :file java/net/Socket.class, :name java.net.Socket}) The map keys are as follows: :name Java class or Clojure namespace name :loc Classpath entry (directory or jar) on which the class is located :file Path of the class file, relative to :loc Also see: (doc swank.util.class-browse) Hope this helps! - Jeff -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Idiomatic Way to Build String or Simply Use StringBuilder
Is there an idiomatic way to build up a string over different lines of code? Or, should one simply use StringBuilder. -- 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: An Emacs command to close the various balanced expressions in Clojure
It's too small to be an Emacs package, but I've forked it into its own file and a few improvements have been made to it. Here: http://furius.ca/pubcode/pub/conf/common/elisp/blais/close-matching.el ( It is linked from this page: http://furius.ca/pubcode/ ) On Sep 28, 6:03 pm, .Bill Smith william.m.sm...@gmail.com wrote: Blais, Thank you for contributing the emacs code. I have been looking for the same thing, for the reasons you and Laurent PETIT described. Bill Smith Austin, Texas -- 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: Idiomatic Way to Build String or Simply Use StringBuilder
On 30 September 2010 12:48, HiHeelHottie hiheelhot...@gmail.com wrote: Is there an idiomatic way to build up a string over different lines of code? Or, should one simply use StringBuilder. I would just use (str) - it uses a StringBuilder when given more than one argument: user (source str) (defn str With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args. {:tag String :added 1.0} ([] ) ([^Object x] (if (nil? x) (. x (toString ([x ys] ((fn [^StringBuilder sb more] (if more (recur (. sb (append (str (first more (next more)) (str sb))) (new StringBuilder ^String (str x)) ys))) Regards, 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 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: Idiomatic Way to Build String or Simply Use StringBuilder
On Sep 29, 2010, at 10:32 PM, Stuart Campbell wrote: I would just use (str) - it uses a StringBuilder when given more than one argument: There's also (format), which I find helpful for building more complex strings. -- 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: Idiomatic Way to Build String or Simply Use StringBuilder
Thanks for the response. What if you are appending over different lines of code? Would it be slightly more efficient to use one StringBuilder or not worth the bother. On Sep 29, 11:32 pm, Stuart Campbell stu...@harto.org wrote: On 30 September 2010 12:48, HiHeelHottie hiheelhot...@gmail.com wrote: Is there an idiomatic way to build up a string over different lines of code? Or, should one simply use StringBuilder. I would just use (str) - it uses a StringBuilder when given more than one argument: user (source str) (defn str With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args. {:tag String :added 1.0} ([] ) ([^Object x] (if (nil? x) (. x (toString ([x ys] ((fn [^StringBuilder sb more] (if more (recur (. sb (append (str (first more (next more)) (str sb))) (new StringBuilder ^String (str x)) ys))) Regards, 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 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: Idiomatic Way to Build String or Simply Use StringBuilder
On Sep 29, 2010, at 11:01 PM, HiHeelHottie wrote: What if you are appending over different lines of code? Could you give an example of what you're trying to do? Mutable strings are almost never necessary, in my experience. -- 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: Idiomatic Way to Build String or Simply Use StringBuilder
Start with an empty vector, say v. conj your strings to the vector at the various points in your code, so at the end v will be something like [this is a string] Then, when you're done, apply str to the vector, i.e., (apply str v) to get thisisastring str uses a string builder behind the scenes, so it's efficient this way. If you keep applying str at each point in your code, it won't be. On Wed, Sep 29, 2010 at 7:48 PM, HiHeelHottie hiheelhot...@gmail.com wrote: Is there an idiomatic way to build up a string over different lines of code? Or, should one simply use StringBuilder. -- 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: Idiomatic Way to Build String or Simply Use StringBuilder
On Wed, Sep 29, 2010 at 9:01 PM, HiHeelHottie hiheelhot...@gmail.com wrote: Thanks for the response. What if you are appending over different lines of code? Would it be slightly more efficient to use one StringBuilder or not worth the bother. I'm trying to think what your code would look like that you'd have multiple 'lines' computing pieces that you are assembling into a string section at a time...? If you're accumulating things that you want to turn into a string later, you could always put the pieces into a vector and then do: (apply str vector-of-pieces) -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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: Idiomatic Way to Build String or Simply Use StringBuilder
On Thu, Sep 30, 2010 at 04:48, HiHeelHottie hiheelhot...@gmail.com wrote: Is there an idiomatic way to build up a string over different lines of code? Or, should one simply use StringBuilder. I recently wrote a program that generates complex java enums (as source) from input data recorded in clojure syntax (by a VBA macro running in excel ...). As java is syntactically correct, I quickly found that it was smart of break up the algorithm into various functions that called each other. A few examples (sketeched out from memory): (defn enum-item-init [name args] [name ( (interpose , (map enum-format-arg)) )]) (defn enum-items [item-map] [(interpose , (map (fn [[name args]] (enum-item-init name args)) item-map)) ;]) (defn enum-class [name item-map] [public enum name {\n (enum-items item-map) \n}\n]) I also used Clojure's multi-line string literals to good effect, though that's now shown here. So, really I'd invented a sort of poor-man's templating language within Clojure. So, I have each function return a sequence of strings. Some return vectors, some return lazy sequences resulting from list comprehensions (for [...] ...). In the end, the top-level function returns a sort of seq of seq of seq ... of strings. So, a tree of strings really. This worked well for me as a way of decomposing my program. Here's the punch-line: (apply str (flatten (enum-class name item-map))) // Ben -- 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
Evaling forms that require
The following form fails in Clojure 1.0, but was fixed in 1.1: (eval '(do (require 'clojure.inspector) clojure.inspector/inspect)) It used to fail because it tried to compile the whole quoted form, but it couldn't compile the inspect reference because the require hadn't been run yet. I think it's great that it works in 1.1, but I'm boggled as to how it works. Does the compiler split apart certain forms like do and compile/run each form separately? It seems like it wouldn't be possible to make this work without multiple passes, but I'm curious how it's done. -Phil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en