Re: writing binary values (bytes) to a file

2008-11-21 Thread Graham Fawcett
Hi Vlad, On Thu, Nov 20, 2008 at 5:36 PM, prhlava <[EMAIL PROTECTED]> wrote: > > Hello Graham, > >> Bonus question for the bored reader: write a function, >> (byte-array-maker N), that takes a width N, and returns a function >> that takes an Integer as input and returns an N-width byte array >> c

Re: writing binary values (bytes) to a file

2008-11-21 Thread prhlava
Hello Jeffrey, > Code is located at: > http://github.com/jbester/cljext/tree/master/cljext%2Fbinpack.clj Thanks for the link, more food for study on how to write a generic library... Basically, I am scheme/lisp noob, learning it in my spare time, the progress is slow but rewarding... Few obs

Re: writing binary values (bytes) to a file

2008-11-20 Thread prhlava
Hello Graham, > Bonus question for the bored reader: write a function, > (byte-array-maker N), that takes a width N, and returns a function > that takes an Integer as input and returns an N-width byte array > containing the Integer in big-endian order. E.g. > > ((byte-array-maker 4) 652187261) >

Re: writing binary values (bytes) to a file

2008-11-19 Thread Jeff Bester
Not sure if this will help with what you are working on. I ran across a similar problem last week and ended up writing a generic library that converts various sizes of integers to big or little endian byte arrays and then back again. Code is located at: http://github.com/jbester/cljext/tree/mas

Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread Mark Volkmann
Thanks Stu! I wasn't aware of the meta function. That helps a lot! I looked for occurrences of "(meta " throughout the clojure and clojure-contrib repositories, but I didn't find a function that prints the code for a given function. That would be incredibly useful for learning! Does anybody know

Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread Graham Fawcett
On Wed, Nov 19, 2008 at 4:49 PM, Mark Volkmann <[EMAIL PROTECTED]> wrote: > > On Wed, Nov 19, 2008 at 2:45 PM, prhlava <[EMAIL PROTECTED]> wrote: >> >> >> Hello again, >> >> Thank you all for the posts and explanations, >> >> After getting the clojure SVN version and few tweaks in the code, the >>

Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread Stuart Halloway
Hi Mark, The metadata points to the source: user> (meta #'with-open) {:doc "bindings => name init\n\n Evaluates body in a try expression with name bound to the value of\n init, and a finally clause that calls (.close name).", :ns #, :arglists ([bindings & body]), :file "core.clj", :name

Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread Mark Volkmann
On Wed, Nov 19, 2008 at 2:45 PM, prhlava <[EMAIL PROTECTED]> wrote: > > > Hello again, > > Thank you all for the posts and explanations, > > After getting the clojure SVN version and few tweaks in the code, the > working result looks like: > > (with-open [ofile (new java.io.Fil

Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread prhlava
Hello again, Thank you all for the posts and explanations, After getting the clojure SVN version and few tweaks in the code, the working result looks like: (with-open [ofile (new java.io.FileOutputStream (str result-directory

Re: writing binary values (bytes) to a file

2008-11-19 Thread Graham Fawcett
Hi, > Dealing with byte-arrays, you will want to use the write-method that > takes an array, not the one that takes a string. > > Constructing the array is a bit tricky: > > ; Define your int > (def pix 652187261) > > ; Define your array, typed as array of char > (def payload > (into-array Chara

Re: writing binary values (bytes) to a file

2008-11-19 Thread wwmorgan
In general, Writers are for character data and OutputStreams are for binary data. If possible, create a FileOutputStream like this: (ns my.ns (:import (java.io FileOutputStream))) (def ofile (FileOutputStream. "/some/file/somewhere")) and use one of the write methods of FileOutputStream. --~-

Re: writing binary values (bytes) to a file

2008-11-19 Thread pmf
On Nov 19, 5:51 pm, prhlava <[EMAIL PROTECTED]> wrote: > (. ofile write (str >                                            (char (bit-shift-right pix 16)) >                                            (char (bit-shift-right pix 8)) >                                            (char pix))) >        

writing binary values (bytes) to a file

2008-11-19 Thread prhlava
Hello all, I have started to play with the clojure a day ago and today I have almost finished porting simple program (from plt-scheme). The place I got stuck in is - how to write a binary value (multiple bytes) in one write operation to a file... The code uses java.io.FileWriter, but this wants