Re: Property file IO failing Incorrect data type conversion

2017-04-15 Thread manas . marthi
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  on behalf of 
> manas@gmail.com "  
> on behalf of manas@gmail.com > 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 
> 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 
> 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 .
> 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.


Re: Property file IO failing Incorrect data type conversion

2017-04-14 Thread Sean Corfield
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, "clojure@googlegroups.com on behalf of 
manas.mar...@gmail.com"  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 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.


-- 
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.


Property file IO failing Incorrect data type conversion

2017-04-14 Thread manas . marthi
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 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.


Re: file io

2009-03-30 Thread Stuart Sierra

On Mar 26, 1:34 pm, Victor Rodriguez  wrote:
> (defmacro with-out-as
>   [f & body]
>   `(with-open [w# (writer ~f)]
>      (binding [*out* w#]
>       �...@body)))

I've added something very similar to this to clojure.contrib.duck-
streams.

-Stuart Sierra
--~--~-~--~~~---~--~~
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: file io

2009-03-29 Thread Korny Sietsma
sweet :)

- Korny

On Fri, Mar 27, 2009 at 4:34 AM, Victor Rodriguez  wrote:

>
> On Tue, Mar 24, 2009 at 11:05 PM, Korny Sietsma  wrote:
> > It'd be nice to have a macro that worked more like the first example -
> > "spit" is great for one-liners, but the fact that it opens and closes the
> > file each time you call it seems a bit painful for anything more complex.
> > Something that ends up working like:
> >
> > (with-out-as "test.txt"
> >(println "hello")
> >(println "world"))
>
> WARNING: spoilers ahead:
>
> (use 'clojure.contrib.duck-streams)
>
> (defmacro with-out-as
>  [f & body]
>  `(with-open [w# (writer ~f)]
> (binding [*out* w#]
>   ~...@body)))
>
> (with-out-as "/tmp/test.txt"
>  (print "hola,")
>  (println " crayola"))
>
>
> Cheers,
>
> Victor Rodriguez.
>
> > Hmm - I've never written a macro, maybe I should give this a try...
> >
> > - Korny
> >
> > On Wed, Mar 25, 2009 at 5:10 AM, Stuart Sierra <
> the.stuart.sie...@gmail.com>
> > wrote:
> >>
> >> On Mar 24, 12:42 pm, Parth Malwankar 
> >> wrote:
> >> > user=> (with-open [f (writer (file "test.txt"))]
> >> >  (binding [*out* f]
> >> >(println "hello world !!!")))
> >>
> >> Or even more simply:
> >>
> >> (use 'clojure.contrib.duck-streams)
> >> (spit  "test.txt"  "Hello, world!\n")
> >>
> >> -Stuart Sierra
> >>
> >
> >
> >
> > --
> > Kornelis Sietsma  korny at my surname dot com
> > "Every jumbled pile of person has a thinking part
> > that wonders what the part that isn't thinking
> > isn't thinking of"
> >
> > >
> >
>
> >
>


-- 
Kornelis Sietsma  korny at my surname dot com
"Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of"

--~--~-~--~~~---~--~~
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: file io

2009-03-26 Thread Victor Rodriguez

On Tue, Mar 24, 2009 at 11:05 PM, Korny Sietsma  wrote:
> It'd be nice to have a macro that worked more like the first example -
> "spit" is great for one-liners, but the fact that it opens and closes the
> file each time you call it seems a bit painful for anything more complex.
> Something that ends up working like:
>
> (with-out-as "test.txt"
>    (println "hello")
>    (println "world"))

WARNING: spoilers ahead:

(use 'clojure.contrib.duck-streams)

(defmacro with-out-as
  [f & body]
  `(with-open [w# (writer ~f)]
 (binding [*out* w#]
   ~...@body)))

(with-out-as "/tmp/test.txt"
  (print "hola,")
  (println " crayola"))


Cheers,

Victor Rodriguez.

> Hmm - I've never written a macro, maybe I should give this a try...
>
> - Korny
>
> On Wed, Mar 25, 2009 at 5:10 AM, Stuart Sierra 
> wrote:
>>
>> On Mar 24, 12:42 pm, Parth Malwankar 
>> wrote:
>> > user=> (with-open [f (writer (file "test.txt"))]
>> >          (binding [*out* f]
>> >            (println "hello world !!!")))
>>
>> Or even more simply:
>>
>> (use 'clojure.contrib.duck-streams)
>> (spit  "test.txt"  "Hello, world!\n")
>>
>> -Stuart Sierra
>>
>
>
>
> --
> Kornelis Sietsma  korny at my surname dot com
> "Every jumbled pile of person has a thinking part
> that wonders what the part that isn't thinking
> isn't thinking of"
>
> >
>

--~--~-~--~~~---~--~~
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: file io

2009-03-25 Thread Korny Sietsma
Hmm - both literal clojure structures, and JSON, are tempting.
JSON is probably my preferred option - but a lot depends on the audience.
If the audience is lisp programmers, then literal structures is probably
ideal.
If the audience is other programmers, I'd probably go for JSON.
If the audience is the geniuses who run our systems where I work, I think
i'd stick to properties files :-}

- Korny (who has spent most the last 6 hours struggling with deployment
pain)

On Thu, Mar 26, 2009 at 1:06 PM, e  wrote:

> clojure file sounds good to me, but who am I?  now, a JSON file  that
> would sound good to a whole LOT of people . . . .and is compatible with many
> many languages ... even looks lispy.  JSON is a good thing to get behind
> because it has a chance of killing xml.
>
>
> On Wed, Mar 25, 2009 at 6:19 PM, Mark McGranaghan wrote:
>
>>
>> + 1 for literal using literal Clojure data structures for configuration.
>>
>> On Wed, Mar 25, 2009 at 5:50 PM, Laurent PETIT 
>> wrote:
>> > And why not just use clojure source code literal datastructures as the
>> > persistence format ?
>> >
>> > With the pretty print function released by Tom Faulhaber, it's even
>> possible
>> > to painlessly write configuration back while keeping it clear (though
>> not
>> > currently possible to maintain things such as comments, I fear),
>> >
>> > --
>> > Laurent
>> >
>> > 2009/3/25 Korny Sietsma 
>> >>
>> >> ooh - that's precisely why I was looking into duck-streams myself;
>> thanks
>> >> for that!
>> >>
>> >> Mind you, after a while in the Ruby world, I'd highly recommend looking
>> at
>> >> YAML for config files - it's human readable and fairly easily
>> writeable, and
>> >> lets you add arrays, nested structures, etc. fairly easily.
>> >> For simple config, and for Java friendliness, I can also see the value
>> of
>> >> properties files - I just keep working on java projects that have 200
>> line
>> >> property files with hacks to handle nested structures and lists - it
>> gets
>> >> ugly real soon!
>> >>
>> >> - Korny
>> >>
>> >> On Thu, Mar 26, 2009 at 5:57 AM, Rayne 
>> wrote:
>> >>>
>> >>> I wrote a simple, small configuration file parser and reader that uses
>> >>> the duck-streams library. You might find some of the examples
>> >>> interesting.
>> >>>
>> >>> http://paste.pocoo.org/show/109498/
>> >>>
>> >>> On Mar 24, 11:20 am, e  wrote:
>> >>> > is there something as simple as this in clojure?
>> >>> >
>> >>> > whole python program:
>> >>> >
>> >>> > of = open(filename,"w")
>> >>> > of.write("hello")
>> >>> > of.close()
>> >>> >
>> >>> > I checked the api and looked around the wiki and google quickly and
>> saw
>> >>> > how
>> >>> > to use java's stuff to do it ... but, welll...
>> >>> >
>> >>> > I noticed "slurp" in the api for reading ... but only the whole file
>> at
>> >>> > once
>> >>> > (read() but no readline()).  Is there something symmetrical for
>> writing
>> >>> > (outputting)?  Is there a web page called "File IO" somewhere?
>> >>> >
>> >>> > Thanks.
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Kornelis Sietsma  korny at my surname dot com
>> >> "Every jumbled pile of person has a thinking part
>> >> that wonders what the part that isn't thinking
>> >> isn't thinking of"
>> >>
>> >>
>> >
>> >
>> >
>> > >
>> >
>>
>>
>>
>
> >
>


-- 
Kornelis Sietsma  korny at my surname dot com
"Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of"

--~--~-~--~~~---~--~~
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: file io

2009-03-25 Thread e
clojure file sounds good to me, but who am I?  now, a JSON file  that
would sound good to a whole LOT of people . . . .and is compatible with many
many languages ... even looks lispy.  JSON is a good thing to get behind
because it has a chance of killing xml.

On Wed, Mar 25, 2009 at 6:19 PM, Mark McGranaghan wrote:

>
> + 1 for literal using literal Clojure data structures for configuration.
>
> On Wed, Mar 25, 2009 at 5:50 PM, Laurent PETIT 
> wrote:
> > And why not just use clojure source code literal datastructures as the
> > persistence format ?
> >
> > With the pretty print function released by Tom Faulhaber, it's even
> possible
> > to painlessly write configuration back while keeping it clear (though not
> > currently possible to maintain things such as comments, I fear),
> >
> > --
> > Laurent
> >
> > 2009/3/25 Korny Sietsma 
> >>
> >> ooh - that's precisely why I was looking into duck-streams myself;
> thanks
> >> for that!
> >>
> >> Mind you, after a while in the Ruby world, I'd highly recommend looking
> at
> >> YAML for config files - it's human readable and fairly easily writeable,
> and
> >> lets you add arrays, nested structures, etc. fairly easily.
> >> For simple config, and for Java friendliness, I can also see the value
> of
> >> properties files - I just keep working on java projects that have 200
> line
> >> property files with hacks to handle nested structures and lists - it
> gets
> >> ugly real soon!
> >>
> >> - Korny
> >>
> >> On Thu, Mar 26, 2009 at 5:57 AM, Rayne  wrote:
> >>>
> >>> I wrote a simple, small configuration file parser and reader that uses
> >>> the duck-streams library. You might find some of the examples
> >>> interesting.
> >>>
> >>> http://paste.pocoo.org/show/109498/
> >>>
> >>> On Mar 24, 11:20 am, e  wrote:
> >>> > is there something as simple as this in clojure?
> >>> >
> >>> > whole python program:
> >>> >
> >>> > of = open(filename,"w")
> >>> > of.write("hello")
> >>> > of.close()
> >>> >
> >>> > I checked the api and looked around the wiki and google quickly and
> saw
> >>> > how
> >>> > to use java's stuff to do it ... but, welll...
> >>> >
> >>> > I noticed "slurp" in the api for reading ... but only the whole file
> at
> >>> > once
> >>> > (read() but no readline()).  Is there something symmetrical for
> writing
> >>> > (outputting)?  Is there a web page called "File IO" somewhere?
> >>> >
> >>> > Thanks.
> >>>
> >>
> >>
> >>
> >> --
> >> Kornelis Sietsma  korny at my surname dot com
> >> "Every jumbled pile of person has a thinking part
> >> that wonders what the part that isn't thinking
> >> isn't thinking of"
> >>
> >>
> >
> >
> >
> > >
> >
>
> >
>

--~--~-~--~~~---~--~~
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: file io

2009-03-25 Thread Mark McGranaghan

+ 1 for literal using literal Clojure data structures for configuration.

On Wed, Mar 25, 2009 at 5:50 PM, Laurent PETIT  wrote:
> And why not just use clojure source code literal datastructures as the
> persistence format ?
>
> With the pretty print function released by Tom Faulhaber, it's even possible
> to painlessly write configuration back while keeping it clear (though not
> currently possible to maintain things such as comments, I fear),
>
> --
> Laurent
>
> 2009/3/25 Korny Sietsma 
>>
>> ooh - that's precisely why I was looking into duck-streams myself; thanks
>> for that!
>>
>> Mind you, after a while in the Ruby world, I'd highly recommend looking at
>> YAML for config files - it's human readable and fairly easily writeable, and
>> lets you add arrays, nested structures, etc. fairly easily.
>> For simple config, and for Java friendliness, I can also see the value of
>> properties files - I just keep working on java projects that have 200 line
>> property files with hacks to handle nested structures and lists - it gets
>> ugly real soon!
>>
>> - Korny
>>
>> On Thu, Mar 26, 2009 at 5:57 AM, Rayne  wrote:
>>>
>>> I wrote a simple, small configuration file parser and reader that uses
>>> the duck-streams library. You might find some of the examples
>>> interesting.
>>>
>>> http://paste.pocoo.org/show/109498/
>>>
>>> On Mar 24, 11:20 am, e  wrote:
>>> > is there something as simple as this in clojure?
>>> >
>>> > whole python program:
>>> >
>>> >     of = open(filename,"w")
>>> >     of.write("hello")
>>> >     of.close()
>>> >
>>> > I checked the api and looked around the wiki and google quickly and saw
>>> > how
>>> > to use java's stuff to do it ... but, welll...
>>> >
>>> > I noticed "slurp" in the api for reading ... but only the whole file at
>>> > once
>>> > (read() but no readline()).  Is there something symmetrical for writing
>>> > (outputting)?  Is there a web page called "File IO" somewhere?
>>> >
>>> > Thanks.
>>>
>>
>>
>>
>> --
>> Kornelis Sietsma  korny at my surname dot com
>> "Every jumbled pile of person has a thinking part
>> that wonders what the part that isn't thinking
>> isn't thinking of"
>>
>>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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: file io

2009-03-25 Thread Laurent PETIT
And why not just use clojure source code literal datastructures as the
persistence format ?

With the pretty print function released by Tom Faulhaber, it's even possible
to painlessly write configuration back while keeping it clear (though not
currently possible to maintain things such as comments, I fear),

-- 
Laurent

2009/3/25 Korny Sietsma 

> ooh - that's precisely why I was looking into duck-streams myself; thanks
> for that!
>
> Mind you, after a while in the Ruby world, I'd highly recommend looking at
> YAML for config files - it's human readable and fairly easily writeable, and
> lets you add arrays, nested structures, etc. fairly easily.
> For simple config, and for Java friendliness, I can also see the value of
> properties files - I just keep working on java projects that have 200 line
> property files with hacks to handle nested structures and lists - it gets
> ugly real soon!
>
> - Korny
>
> On Thu, Mar 26, 2009 at 5:57 AM, Rayne  wrote:
>
>>
>> I wrote a simple, small configuration file parser and reader that uses
>> the duck-streams library. You might find some of the examples
>> interesting.
>>
>> http://paste.pocoo.org/show/109498/
>>
>> On Mar 24, 11:20 am, e  wrote:
>> > is there something as simple as this in clojure?
>> >
>> > whole python program:
>> >
>> > of = open(filename,"w")
>> > of.write("hello")
>> > of.close()
>> >
>> > I checked the api and looked around the wiki and google quickly and saw
>> how
>> > to use java's stuff to do it ... but, welll...
>> >
>> > I noticed "slurp" in the api for reading ... but only the whole file at
>> once
>> > (read() but no readline()).  Is there something symmetrical for writing
>> > (outputting)?  Is there a web page called "File IO" somewhere?
>> >
>> > Thanks.
>>
>>
>
>
> --
> Kornelis Sietsma  korny at my surname dot com
> "Every jumbled pile of person has a thinking part
> that wonders what the part that isn't thinking
> isn't thinking of"
>
> >
>

--~--~-~--~~~---~--~~
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: file io

2009-03-25 Thread Korny Sietsma
ooh - that's precisely why I was looking into duck-streams myself; thanks
for that!

Mind you, after a while in the Ruby world, I'd highly recommend looking at
YAML for config files - it's human readable and fairly easily writeable, and
lets you add arrays, nested structures, etc. fairly easily.
For simple config, and for Java friendliness, I can also see the value of
properties files - I just keep working on java projects that have 200 line
property files with hacks to handle nested structures and lists - it gets
ugly real soon!

- Korny

On Thu, Mar 26, 2009 at 5:57 AM, Rayne  wrote:

>
> I wrote a simple, small configuration file parser and reader that uses
> the duck-streams library. You might find some of the examples
> interesting.
>
> http://paste.pocoo.org/show/109498/
>
> On Mar 24, 11:20 am, e  wrote:
> > is there something as simple as this in clojure?
> >
> > whole python program:
> >
> > of = open(filename,"w")
> > of.write("hello")
> > of.close()
> >
> > I checked the api and looked around the wiki and google quickly and saw
> how
> > to use java's stuff to do it ... but, welll...
> >
> > I noticed "slurp" in the api for reading ... but only the whole file at
> once
> > (read() but no readline()).  Is there something symmetrical for writing
> > (outputting)?  Is there a web page called "File IO" somewhere?
> >
> > Thanks.
> >
>


-- 
Kornelis Sietsma  korny at my surname dot com
"Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of"

--~--~-~--~~~---~--~~
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: file io

2009-03-25 Thread Rayne

I wrote a simple, small configuration file parser and reader that uses
the duck-streams library. You might find some of the examples
interesting.

http://paste.pocoo.org/show/109498/

On Mar 24, 11:20 am, e  wrote:
> is there something as simple as this in clojure?
>
> whole python program:
>
>     of = open(filename,"w")
>     of.write("hello")
>     of.close()
>
> I checked the api and looked around the wiki and google quickly and saw how
> to use java's stuff to do it ... but, welll...
>
> I noticed "slurp" in the api for reading ... but only the whole file at once
> (read() but no readline()).  Is there something symmetrical for writing
> (outputting)?  Is there a web page called "File IO" somewhere?
>
> 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
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: file io

2009-03-25 Thread Stephen C. Gilardi


On Mar 25, 2009, at 5:52 AM, Paul Drummond wrote:


Anyone else hate the names 'slurp' and 'spit' as much as me?



You're not alone there.

http://groups.google.com/group/clojure/browse_frm/thread/d8064dbb94c5cd2c/bce36a47121d6faf?lnk=gst&q=slurp+name#bce36a47121d6faf

IMO changing these names would be a great idea whether these  
functions are moved up to core or not.


I agree.

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: file io

2009-03-25 Thread Paul Drummond

2009/3/25 e :
> For example, "slurp" is, perhaps, marginally better than "read" because it
> may help express that it reads the whole file.

Anyone else hate the names 'slurp' and 'spit' as much as me?  IMO
changing these names would be a great idea whether these functions are
moved up to core or not.
-- 
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: file io

2009-03-24 Thread Cosmin Stejerean
On Tue, Mar 24, 2009 at 10:19 PM, e  wrote:

> I'm interested to know what the process/priority is on bubbling things up
> from contrib into the core.  Is a discussion under way about going through
> it all?
>
> I also think it's good to have cross-language conventions sometimes unless
> there are compelling reasons.
>
> For example, "slurp" is, perhaps, marginally better than "read" because it
> may help express that it reads the whole file.  Whereas, in Python, one only
> knows that "read" reads the whole file when they compare it to the fact that
> there is "readline()".  BUT, basing it on python, yet IMPROVING, I'd
> advocate for "read-all" and "read-line".  Totally consistent AND
> unambiguous.
>

There's a reason Python's read is called read and not read-all, because it
takes an argument for how many bytes to read. This argument just happens to
be optional, in which case it will read everything. This is particularly
useful when reading data from a binary file where you have to read the data
in chunks (and you obviously can't rely on readline). Given that I don't see
the need for also having a read-all function.

-- 
Cosmin Stejerean
http://offbytwo.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: file io

2009-03-24 Thread e
I'm interested to know what the process/priority is on bubbling things up
from contrib into the core.  Is a discussion under way about going through
it all?

I also think it's good to have cross-language conventions sometimes unless
there are compelling reasons.

For example, "slurp" is, perhaps, marginally better than "read" because it
may help express that it reads the whole file.  Whereas, in Python, one only
knows that "read" reads the whole file when they compare it to the fact that
there is "readline()".  BUT, basing it on python, yet IMPROVING, I'd
advocate for "read-all" and "read-line".  Totally consistent AND
unambiguous.

Unless there is a compelling reason (saving a few chars or being cute don't
count) to deviate from read and write, it just makes it needlessly harder
for people coming from other languages (IMnsHO)

On Tue, Mar 24, 2009 at 11:05 PM, Korny Sietsma  wrote:

> It'd be nice to have a macro that worked more like the first example -
> "spit" is great for one-liners, but the fact that it opens and closes the
> file each time you call it seems a bit painful for anything more complex.
> Something that ends up working like:
>
> (with-out-as "test.txt"
>(println "hello")
>(println "world"))
>
> Hmm - I've never written a macro, maybe I should give this a try...
>
> - Korny
>
> On Wed, Mar 25, 2009 at 5:10 AM, Stuart Sierra <
> the.stuart.sie...@gmail.com> wrote:
>
>>
>> On Mar 24, 12:42 pm, Parth Malwankar 
>> wrote:
>> > user=> (with-open [f (writer (file "test.txt"))]
>> >  (binding [*out* f]
>> >(println "hello world !!!")))
>>
>> Or even more simply:
>>
>> (use 'clojure.contrib.duck-streams)
>> (spit  "test.txt"  "Hello, world!\n")
>>
>> -Stuart Sierra
>>
>>
>
>
> --
> Kornelis Sietsma  korny at my surname dot com
> "Every jumbled pile of person has a thinking part
> that wonders what the part that isn't thinking
> isn't thinking of"
>
>
> >
>

--~--~-~--~~~---~--~~
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: file io

2009-03-24 Thread Korny Sietsma
It'd be nice to have a macro that worked more like the first example -
"spit" is great for one-liners, but the fact that it opens and closes the
file each time you call it seems a bit painful for anything more complex.
Something that ends up working like:

(with-out-as "test.txt"
   (println "hello")
   (println "world"))

Hmm - I've never written a macro, maybe I should give this a try...

- Korny

On Wed, Mar 25, 2009 at 5:10 AM, Stuart Sierra
wrote:

>
> On Mar 24, 12:42 pm, Parth Malwankar 
> wrote:
> > user=> (with-open [f (writer (file "test.txt"))]
> >  (binding [*out* f]
> >(println "hello world !!!")))
>
> Or even more simply:
>
> (use 'clojure.contrib.duck-streams)
> (spit  "test.txt"  "Hello, world!\n")
>
> -Stuart Sierra
> >
>


-- 
Kornelis Sietsma  korny at my surname dot com
"Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of"

--~--~-~--~~~---~--~~
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: file io

2009-03-24 Thread Parth



On Mar 24, 11:53 pm, e  wrote:
> does anyone else think that should be more fundamental like the python
> example?  imagine saying that out loud to your friend who asks . . . and the
> amount of noise, visually:
>
> "use clojure dot contrib dot duck dash streams".
>
> perhaps it is already the hope that it will "spit" will eventually sit next
> to "slurp"?
>

This has come up before on the list.
I am not sure about where things stand with that though.

http://groups.google.com/group/clojure/browse_thread/thread/31f01808c225ecc1/d0e286fa0c8ef7d2
http://groups.google.com/group/clojure/browse_thread/thread/d8064dbb94c5cd2c/ba355cfe2c708068

I think it would be nice to have "spit" in the core, especially for
people like me who aren't too good with java. But having
clojure-contrib.duck-streams definately makes life easier :)

Parth

--~--~-~--~~~---~--~~
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: file io

2009-03-24 Thread e
i guess another way to say this is that I can see both sides of the argument
... on one side, it shouldn't be a priority to resolve problems that java
already provides when there are probably other more pressing issues.  And
it's part of the design decision to allow users to leverage java libraries.
On the other, I've heard people complain about the verbosity of trying to
find libraries in java vs. python, and this could be an opportunity to fix
that.

On Tue, Mar 24, 2009 at 2:53 PM, e  wrote:

> does anyone else think that should be more fundamental like the python
> example?  imagine saying that out loud to your friend who asks . . . and the
> amount of noise, visually:
>
> "use clojure dot contrib dot duck dash streams".
>
> perhaps it is already the hope that it will "spit" will eventually sit next
> to "slurp"?
>
> I had thought of "java.io.FileWriter. "/path/to/your/file" . . .. but it's
> sometimes the case that using the jvm is acceptable enough, but learning the
> java libraries isn't ... because then folks are learning two languages and
> it also really ties a basic thing to the java language.
>
> Thanks for the answer.
>
>
> On Tue, Mar 24, 2009 at 2:10 PM, Stuart Sierra <
> the.stuart.sie...@gmail.com> wrote:
>
>>
>> On Mar 24, 12:42 pm, Parth Malwankar 
>> wrote:
>> > user=> (with-open [f (writer (file "test.txt"))]
>> >  (binding [*out* f]
>> >(println "hello world !!!")))
>>
>> Or even more simply:
>>
>> (use 'clojure.contrib.duck-streams)
>> (spit  "test.txt"  "Hello, world!\n")
>>
>> -Stuart Sierra
>> >>
>>
>

--~--~-~--~~~---~--~~
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: file io

2009-03-24 Thread e
does anyone else think that should be more fundamental like the python
example?  imagine saying that out loud to your friend who asks . . . and the
amount of noise, visually:

"use clojure dot contrib dot duck dash streams".

perhaps it is already the hope that it will "spit" will eventually sit next
to "slurp"?

I had thought of "java.io.FileWriter. "/path/to/your/file" . . .. but it's
sometimes the case that using the jvm is acceptable enough, but learning the
java libraries isn't ... because then folks are learning two languages and
it also really ties a basic thing to the java language.

Thanks for the answer.

On Tue, Mar 24, 2009 at 2:10 PM, Stuart Sierra
wrote:

>
> On Mar 24, 12:42 pm, Parth Malwankar 
> wrote:
> > user=> (with-open [f (writer (file "test.txt"))]
> >  (binding [*out* f]
> >(println "hello world !!!")))
>
> Or even more simply:
>
> (use 'clojure.contrib.duck-streams)
> (spit  "test.txt"  "Hello, world!\n")
>
> -Stuart Sierra
> >
>

--~--~-~--~~~---~--~~
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: file io

2009-03-24 Thread Stuart Sierra

On Mar 24, 12:42 pm, Parth Malwankar 
wrote:
> user=> (with-open [f (writer (file "test.txt"))]
>          (binding [*out* f]
>            (println "hello world !!!")))

Or even more simply:

(use 'clojure.contrib.duck-streams)
(spit  "test.txt"  "Hello, world!\n")

-Stuart Sierra
--~--~-~--~~~---~--~~
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: file io

2009-03-24 Thread Parth Malwankar



e wrote:
> is there something as simple as this in clojure?
>
> whole python program:
>
> of = open(filename,"w")
> of.write("hello")
> of.close()
>
> I checked the api and looked around the wiki and google quickly and saw how
> to use java's stuff to do it ... but, welll...
>

There are possibly other (better) ways to do it. One way is:
user=> (use 'clojure.contrib.duck-streams)
nil
user=> (with-open [f (writer (file "test.txt"))]
 (binding [*out* f]
   (println "hello world !!!")))
nil
user=>
% cat test.txt
hello world !!!
%

clojure.contrib.duck-stream has an interesting set of
functions.

Parth

> I noticed "slurp" in the api for reading ... but only the whole file at once
> (read() but no readline()).  Is there something symmetrical for writing
> (outputting)?  Is there a web page called "File IO" somewhere?
>
> 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
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: file io

2009-03-24 Thread Laurent PETIT
Hello,

try

(with-open [of (java.io.FileWriter. "/path/to/your/file")]
  (.write of "coucou"))

As far as java libraries are concerned, and answer commonly seen in this ml
is : "use apache commons io". And indeed it does the job well, but, yes,
it's then another dependency to your project, for what one might consider a
very basic feature.

http://commons.apache.org/io/

HTH,

-- 
Laurent



2009/3/24 e 

> is there something as simple as this in clojure?
>
> whole python program:
>
> of = open(filename,"w")
> of.write("hello")
> of.close()
>
> I checked the api and looked around the wiki and google quickly and saw how
> to use java's stuff to do it ... but, welll...
>
> I noticed "slurp" in the api for reading ... but only the whole file at
> once (read() but no readline()).  Is there something symmetrical for writing
> (outputting)?  Is there a web page called "File IO" somewhere?
>
> 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
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
-~--~~~~--~~--~--~---



file io

2009-03-24 Thread e
is there something as simple as this in clojure?

whole python program:

of = open(filename,"w")
of.write("hello")
of.close()

I checked the api and looked around the wiki and google quickly and saw how
to use java's stuff to do it ... but, welll...

I noticed "slurp" in the api for reading ... but only the whole file at once
(read() but no readline()).  Is there something symmetrical for writing
(outputting)?  Is there a web page called "File IO" somewhere?

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
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
-~--~~~~--~~--~--~---