Hi Sean, Thank you very much. I changed read-string to str. And it worked fine now. So is ".toString" working fine. for [[k v] props] [(keyword k) (.toString v)]
regards Manas On Saturday, April 15, 2017 at 2:28:16 AM UTC+1, Sean Corfield wrote: > > Trying to convert arbitrary strings to Clojure objects via read-string is > rather dangerous – read-string can execute arbitrary code (if the string > happens to look like a tagged literal). > > > > Aside from that, read-string is only going to read the first expression > from the string: > > > > (read-string “42 13”) ;=> 42 – the “ 13” portion is just > ignored > > > > And anything like a file path is going to give you a read failure as well: > > > > (read-string "/path/to/file") ;=> > *java.lang.RuntimeException*: *Invalid token: /path/to/file* > > > > or if it’s a Windows path with a drive specifier: > > > > (read-string "c\\:/path/to/file") ;=> c – and the rest of > the string is ignored > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > On 4/14/17, 2:39 PM, "clo...@googlegroups.com <javascript:> on behalf of > manas....@gmail.com <javascript:>" <clo...@googlegroups.com <javascript:> > on behalf of manas....@gmail.com <javascript:>> wrote: > > > > Hi > > I am trying to compare two eclipse preferences files with a piece of code > I picked from internet > > Some of the values in the file are version numbers and clojure is > throwing number format error. How to force clojure read the properties as > strings. > > > > > > > > CompilerException java.lang.NumberFormatException: Invalid number: 2.1.2, > compiling:(CompareEclipsePrefs.clj:25:21) > > > > > > Code I used is below. Please can someone advise how to prevent number > conversion from string > > > > (require 'clojure.java.io);' > (defn load-props > [file-name] > (with-open [^java.io.Reader reader (clojure.java.io/reader file-name)] > (let [props (java.util.Properties.)] > (.load props reader) > (into {} > (for [[k v] props] [(keyword k) (read-string v)]))))) > > > > > > thanks > > Manas > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clo...@googlegroups.com <javascript:> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+u...@googlegroups.com <javascript:> > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+u...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.