Re: print-base / print-radix?
t; > > > > for Clojure as it makes scenarios like the above very > > > > > > easy to deal with. Any chance of this being somewhere > > > > > > on the Clojue todo? :) > > > > > > Rich, > > > > > > If this is something you think would be a good addition > > > > > to Clojure I could give a shot at creating a patch for > > > > > this (with a CA of course). Please let me know. > > > > > > I think rather than a generic radix support, if > > > > > we have hex, bin and octal supported, most uses > > > > > cases should be covered. > > > > > > Regards, > > > > > Parth > > > > > > > I will probably create a poor mans radix based print > > > > > > in the mean time for the this scenario. That should > > > > > > be an interesting exercise. > > > > > > > Thanks, > > > > > > Parth > > > > > > > On Jul 2, 10:58 pm, Chouser wrote: > > > > > > > > On Thu, Jul 2, 2009 at 4:51 AM, Parth > > > > > > > > Malwankar wrote: > > > > > > > > > I frequently deal with hex and binary numbers. > > > > > > > > As of now when I need to view a list of numbers > > > > > > > > I just map a little hex function to it to translate it > > > > > > > > into a list of hex strings at the repl. > > > > > > > > > Having something like *print-base* / *print-radix* [1] may be > > > > > > > > valuable in such a scenario > > > > > > > > I don't think Java's built-in formatter is nearly as > > > > > > > flexible as those, but getting hex or octal strings is easy > > > > > > > enough: > > > > > > > > user=> (format "%d" 255) > > > > > > > "255" > > > > > > > user=> (format "%o" 255) > > > > > > > "377" > > > > > > > user=> (format "%x" 255) > > > > > > > "ff" > > > > > > > user=> (format "%X" 255) > > > > > > > "FF" > > > > > > > > --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
On Jul 5, 9:02 pm, Tom Faulhaber wrote: > Parth, > > I've created a little wrapper as promised at:http://gist.github.com/141001. > > It gives you my-pprint: > > user> (binding [*print-base* 2] (my-pprint (range 10))) > (0 1 10 11 100 101 110 111 1000 1001) > nil > user> > Thanks Tom. This works beautifully :) Here is the example that earlier example in the thread: user=> (binding [wrap-base/*print-base* 16] (wrap-base/my-pprint (decode :b32 (test-ops 3 {:inst {:prefix (), :code (c7 45 f8 a 0 0 0), :op :movl, :args [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} a]}, :more ()} nil user=> > While doing this, I realized to my horror that ~r doesn't do 0 > correctly for non-standard bases. I'll fix that soon. > > Also, I've started to implement *print-radix* and *print-base* for > real in cl-format and the pretty printer, so those should be available > soon. > Fantastic ... pprint just keeps getting better :) Regards, Parth > Enjoy, > > Tom > > On Jul 3, 3:16 am, Parth wrote: > > > On Jul 3, 11:25 am, Tom Faulhaber wrote: > > > > Parth, > > > > I was thinking about this a little more today and I came up with a way > > > to extend the pretty printer easily to support *print-radix* with a > > > little wrapper. I'll try to get a chance to write it up for you > > > tomorrow. > > > > Tom > > > Sounds perfect. Thanks very much :) > > > Regards, > > Parth > > > > On Jul 2, 6:29 pm, Parth wrote: > > > > > On Jul 3, 6:15 am, Parth wrote: > > > > > > Tom, Chouser, Thanks for your responses. > > > > > > As of now I am doing the same thing as suggested. > > > > > However, this tends be become painful the moment structures > > > > > start to nest. For e.g. I am using Clojure to decode a bit > > > > > of assembly and below is what I end up doing to see the > > > > > values of interest in hex: > > > > > > user=> (decode :b32 (nth test-ops 3)) > > > > > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args > > > > > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()} > > > > > user=> (def r (decode :b32 (nth test-ops 3))) > > > > > #'user/r > > > > > user=> (map hex (get-in r [:inst :code])) > > > > > ("c7" "45" "f8" "a" "0" "0" "0") > > > > > user=> (hex (second (get-in r [:inst :args]))) > > > > > "a" > > > > > user=> > > > > > > Basically, I need to extract each number seq or value > > > > > individually and print it in hex for every instruction I > > > > > decode and view. > > > > > > This isn't too much fun to do in the middle of a debug session :) > > > > > > Having something like *print-base* would be ideal IMHO > > > > > would make scenarios like this really easy as one could > > > > > simply do: > > > > > > user=> (set! *print-base* 16) > > > > > user=> (decode :b32 (nth test-ops 3)) > > > > > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args > > > > > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()} > > > > > > In the absence of this I thought of writing a function > > > > > that would take an arbitrary Clojure structure/coll and print > > > > > it out in the manner like above. But then it won't > > > > > be much different from pprint with radix support but without > > > > > the pretty part. > > > > > > I suppose what I am hoping is that a feature request for > > > > > *print-base* sort of a mechanism get considered > > > > > for Clojure as it makes scenarios like the above very > > > > > easy to deal with. Any chance of this being somewhere > > > > > on the Clojue todo? :) > > > > > Rich, > > > > > If this is something you think would be a good addition > > > > to Clojure I could give a shot at creating a patch for > > > > this (with a CA of course). Please let me know. > > > > > I think rather than a generic radix support, if > > > > we have hex, bin and octal supported, most uses > > > > cases should be covered. > > > > > Regards, > > > > Parth > > > > > > I will probably create a
Re: print-base / print-radix?
Parth, I've created a little wrapper as promised at: http://gist.github.com/141001. It gives you my-pprint: user> (binding [*print-base* 2] (my-pprint (range 10))) (0 1 10 11 100 101 110 111 1000 1001) nil user> While doing this, I realized to my horror that ~r doesn't do 0 correctly for non-standard bases. I'll fix that soon. Also, I've started to implement *print-radix* and *print-base* for real in cl-format and the pretty printer, so those should be available soon. Enjoy, Tom On Jul 3, 3:16 am, Parth wrote: > On Jul 3, 11:25 am, Tom Faulhaber wrote: > > > Parth, > > > I was thinking about this a little more today and I came up with a way > > to extend the pretty printer easily to support *print-radix* with a > > little wrapper. I'll try to get a chance to write it up for you > > tomorrow. > > > Tom > > Sounds perfect. Thanks very much :) > > Regards, > Parth > > > On Jul 2, 6:29 pm, Parth wrote: > > > > On Jul 3, 6:15 am, Parth wrote: > > > > > Tom, Chouser, Thanks for your responses. > > > > > As of now I am doing the same thing as suggested. > > > > However, this tends be become painful the moment structures > > > > start to nest. For e.g. I am using Clojure to decode a bit > > > > of assembly and below is what I end up doing to see the > > > > values of interest in hex: > > > > > user=> (decode :b32 (nth test-ops 3)) > > > > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args > > > > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()} > > > > user=> (def r (decode :b32 (nth test-ops 3))) > > > > #'user/r > > > > user=> (map hex (get-in r [:inst :code])) > > > > ("c7" "45" "f8" "a" "0" "0" "0") > > > > user=> (hex (second (get-in r [:inst :args]))) > > > > "a" > > > > user=> > > > > > Basically, I need to extract each number seq or value > > > > individually and print it in hex for every instruction I > > > > decode and view. > > > > > This isn't too much fun to do in the middle of a debug session :) > > > > > Having something like *print-base* would be ideal IMHO > > > > would make scenarios like this really easy as one could > > > > simply do: > > > > > user=> (set! *print-base* 16) > > > > user=> (decode :b32 (nth test-ops 3)) > > > > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args > > > > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()} > > > > > In the absence of this I thought of writing a function > > > > that would take an arbitrary Clojure structure/coll and print > > > > it out in the manner like above. But then it won't > > > > be much different from pprint with radix support but without > > > > the pretty part. > > > > > I suppose what I am hoping is that a feature request for > > > > *print-base* sort of a mechanism get considered > > > > for Clojure as it makes scenarios like the above very > > > > easy to deal with. Any chance of this being somewhere > > > > on the Clojue todo? :) > > > > Rich, > > > > If this is something you think would be a good addition > > > to Clojure I could give a shot at creating a patch for > > > this (with a CA of course). Please let me know. > > > > I think rather than a generic radix support, if > > > we have hex, bin and octal supported, most uses > > > cases should be covered. > > > > Regards, > > > Parth > > > > > I will probably create a poor mans radix based print > > > > in the mean time for the this scenario. That should > > > > be an interesting exercise. > > > > > Thanks, > > > > Parth > > > > > On Jul 2, 10:58 pm, Chouser wrote: > > > > > > On Thu, Jul 2, 2009 at 4:51 AM, Parth > > > > > > Malwankar wrote: > > > > > > > I frequently deal with hex and binary numbers. > > > > > > As of now when I need to view a list of numbers > > > > > > I just map a little hex function to it to translate it > > > > > > into a list of hex strings at the repl. > > > > > > > Having something like *print-base* / *print-radix* [1] may be > > > > > > valuable in such a scenario > > > > > > I don't think Java's built-in formatter is nearly as > > > > > flexible as those, but getting hex or octal strings is easy > > > > > enough: > > > > > > user=> (format "%d" 255) > > > > > "255" > > > > > user=> (format "%o" 255) > > > > > "377" > > > > > user=> (format "%x" 255) > > > > > "ff" > > > > > user=> (format "%X" 255) > > > > > "FF" > > > > > > --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
On Jul 3, 11:25 am, Tom Faulhaber wrote: > Parth, > > I was thinking about this a little more today and I came up with a way > to extend the pretty printer easily to support *print-radix* with a > little wrapper. I'll try to get a chance to write it up for you > tomorrow. > > Tom > Sounds perfect. Thanks very much :) Regards, Parth > On Jul 2, 6:29 pm, Parth wrote: > > > On Jul 3, 6:15 am, Parth wrote: > > > > Tom, Chouser, Thanks for your responses. > > > > As of now I am doing the same thing as suggested. > > > However, this tends be become painful the moment structures > > > start to nest. For e.g. I am using Clojure to decode a bit > > > of assembly and below is what I end up doing to see the > > > values of interest in hex: > > > > user=> (decode :b32 (nth test-ops 3)) > > > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args > > > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()} > > > user=> (def r (decode :b32 (nth test-ops 3))) > > > #'user/r > > > user=> (map hex (get-in r [:inst :code])) > > > ("c7" "45" "f8" "a" "0" "0" "0") > > > user=> (hex (second (get-in r [:inst :args]))) > > > "a" > > > user=> > > > > Basically, I need to extract each number seq or value > > > individually and print it in hex for every instruction I > > > decode and view. > > > > This isn't too much fun to do in the middle of a debug session :) > > > > Having something like *print-base* would be ideal IMHO > > > would make scenarios like this really easy as one could > > > simply do: > > > > user=> (set! *print-base* 16) > > > user=> (decode :b32 (nth test-ops 3)) > > > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args > > > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()} > > > > In the absence of this I thought of writing a function > > > that would take an arbitrary Clojure structure/coll and print > > > it out in the manner like above. But then it won't > > > be much different from pprint with radix support but without > > > the pretty part. > > > > I suppose what I am hoping is that a feature request for > > > *print-base* sort of a mechanism get considered > > > for Clojure as it makes scenarios like the above very > > > easy to deal with. Any chance of this being somewhere > > > on the Clojue todo? :) > > > Rich, > > > If this is something you think would be a good addition > > to Clojure I could give a shot at creating a patch for > > this (with a CA of course). Please let me know. > > > I think rather than a generic radix support, if > > we have hex, bin and octal supported, most uses > > cases should be covered. > > > Regards, > > Parth > > > > I will probably create a poor mans radix based print > > > in the mean time for the this scenario. That should > > > be an interesting exercise. > > > > Thanks, > > > Parth > > > > On Jul 2, 10:58 pm, Chouser wrote: > > > > > On Thu, Jul 2, 2009 at 4:51 AM, Parth > > > > > Malwankar wrote: > > > > > > I frequently deal with hex and binary numbers. > > > > > As of now when I need to view a list of numbers > > > > > I just map a little hex function to it to translate it > > > > > into a list of hex strings at the repl. > > > > > > Having something like *print-base* / *print-radix* [1] may be > > > > > valuable in such a scenario > > > > > I don't think Java's built-in formatter is nearly as > > > > flexible as those, but getting hex or octal strings is easy > > > > enough: > > > > > user=> (format "%d" 255) > > > > "255" > > > > user=> (format "%o" 255) > > > > "377" > > > > user=> (format "%x" 255) > > > > "ff" > > > > user=> (format "%X" 255) > > > > "FF" > > > > > --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
Parth, I was thinking about this a little more today and I came up with a way to extend the pretty printer easily to support *print-radix* with a little wrapper. I'll try to get a chance to write it up for you tomorrow. Tom On Jul 2, 6:29 pm, Parth wrote: > On Jul 3, 6:15 am, Parth wrote: > > > > > Tom, Chouser, Thanks for your responses. > > > As of now I am doing the same thing as suggested. > > However, this tends be become painful the moment structures > > start to nest. For e.g. I am using Clojure to decode a bit > > of assembly and below is what I end up doing to see the > > values of interest in hex: > > > user=> (decode :b32 (nth test-ops 3)) > > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args > > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()} > > user=> (def r (decode :b32 (nth test-ops 3))) > > #'user/r > > user=> (map hex (get-in r [:inst :code])) > > ("c7" "45" "f8" "a" "0" "0" "0") > > user=> (hex (second (get-in r [:inst :args]))) > > "a" > > user=> > > > Basically, I need to extract each number seq or value > > individually and print it in hex for every instruction I > > decode and view. > > > This isn't too much fun to do in the middle of a debug session :) > > > Having something like *print-base* would be ideal IMHO > > would make scenarios like this really easy as one could > > simply do: > > > user=> (set! *print-base* 16) > > user=> (decode :b32 (nth test-ops 3)) > > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args > > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()} > > > In the absence of this I thought of writing a function > > that would take an arbitrary Clojure structure/coll and print > > it out in the manner like above. But then it won't > > be much different from pprint with radix support but without > > the pretty part. > > > I suppose what I am hoping is that a feature request for > > *print-base* sort of a mechanism get considered > > for Clojure as it makes scenarios like the above very > > easy to deal with. Any chance of this being somewhere > > on the Clojue todo? :) > > Rich, > > If this is something you think would be a good addition > to Clojure I could give a shot at creating a patch for > this (with a CA of course). Please let me know. > > I think rather than a generic radix support, if > we have hex, bin and octal supported, most uses > cases should be covered. > > Regards, > Parth > > > I will probably create a poor mans radix based print > > in the mean time for the this scenario. That should > > be an interesting exercise. > > > Thanks, > > Parth > > > On Jul 2, 10:58 pm, Chouser wrote: > > > > On Thu, Jul 2, 2009 at 4:51 AM, Parth > > > > Malwankar wrote: > > > > > I frequently deal with hex and binary numbers. > > > > As of now when I need to view a list of numbers > > > > I just map a little hex function to it to translate it > > > > into a list of hex strings at the repl. > > > > > Having something like *print-base* / *print-radix* [1] may be > > > > valuable in such a scenario > > > > I don't think Java's built-in formatter is nearly as > > > flexible as those, but getting hex or octal strings is easy > > > enough: > > > > user=> (format "%d" 255) > > > "255" > > > user=> (format "%o" 255) > > > "377" > > > user=> (format "%x" 255) > > > "ff" > > > user=> (format "%X" 255) > > > "FF" > > > > --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
On Jul 3, 6:15 am, Parth wrote: > Tom, Chouser, Thanks for your responses. > > As of now I am doing the same thing as suggested. > However, this tends be become painful the moment structures > start to nest. For e.g. I am using Clojure to decode a bit > of assembly and below is what I end up doing to see the > values of interest in hex: > > user=> (decode :b32 (nth test-ops 3)) > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()} > user=> (def r (decode :b32 (nth test-ops 3))) > #'user/r > user=> (map hex (get-in r [:inst :code])) > ("c7" "45" "f8" "a" "0" "0" "0") > user=> (hex (second (get-in r [:inst :args]))) > "a" > user=> > > Basically, I need to extract each number seq or value > individually and print it in hex for every instruction I > decode and view. > > This isn't too much fun to do in the middle of a debug session :) > > Having something like *print-base* would be ideal IMHO > would make scenarios like this really easy as one could > simply do: > > user=> (set! *print-base* 16) > user=> (decode :b32 (nth test-ops 3)) > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()} > > In the absence of this I thought of writing a function > that would take an arbitrary Clojure structure/coll and print > it out in the manner like above. But then it won't > be much different from pprint with radix support but without > the pretty part. > > I suppose what I am hoping is that a feature request for > *print-base* sort of a mechanism get considered > for Clojure as it makes scenarios like the above very > easy to deal with. Any chance of this being somewhere > on the Clojue todo? :) > Rich, If this is something you think would be a good addition to Clojure I could give a shot at creating a patch for this (with a CA of course). Please let me know. I think rather than a generic radix support, if we have hex, bin and octal supported, most uses cases should be covered. Regards, Parth > I will probably create a poor mans radix based print > in the mean time for the this scenario. That should > be an interesting exercise. > > Thanks, > Parth > > On Jul 2, 10:58 pm, Chouser wrote: > > > On Thu, Jul 2, 2009 at 4:51 AM, Parth > > > Malwankar wrote: > > > > I frequently deal with hex and binary numbers. > > > As of now when I need to view a list of numbers > > > I just map a little hex function to it to translate it > > > into a list of hex strings at the repl. > > > > Having something like *print-base* / *print-radix* [1] may be > > > valuable in such a scenario > > > I don't think Java's built-in formatter is nearly as > > flexible as those, but getting hex or octal strings is easy > > enough: > > > user=> (format "%d" 255) > > "255" > > user=> (format "%o" 255) > > "377" > > user=> (format "%x" 255) > > "ff" > > user=> (format "%X" 255) > > "FF" > > > --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
On Jul 2, 9:44 pm, Tom Faulhaber wrote: > Hi Parth, > > It is on the agenda to support this for pprint, but I don't know > exactly when. > Thanks Tom. I look forward to this addition to the wonderful pprint function :) Regards, Parth > In the meantime, arbitrary bases *are* supported in the common lisp > compatible format function (cl-format) which is also part of > clojure.contrib.pprint. > > The interesting directives are ~X, ~B, and ~bR, where b is the base of > interest. For example, > > (cl-format nil "~X" 256) => "100" > > (cl-format nil "~12r" 256) => "194" > > (cl-format true "~{~X ~}~%" [2 4 8 16 32 64 128 256]) > > prints to *out*: > > 2 4 8 10 20 40 80 100 > > For all the dirt on using radix, look at the Common Lisp > Hyperspec:http://www.lispworks.com/documentation/HyperSpec/Body/22_cb.htm > > More info about the clojure implementation of format > here:http://code.google.com/p/clojure-contrib/wiki/CommonLispFormat(a > little out of date and about to be moved). > > HTH, > > Tom > On Jul 2, 1:51 am, Parth Malwankar wrote: > > > I frequently deal with hex and binary numbers. > > As of now when I need to view a list of numbers > > I just map a little hex function to it to translate it > > into a list of hex strings at the repl. > > > Having something like *print-base* / *print-radix* [1] may be > > valuable in such a scenario > > > Or maybe an enhanced pprint? Not sure if pprint already provides > > such an option or if its planned. > > > I would appreciate any comments or ideas if someone > > is doing something similar. > > > Thanks. > > Parth > > [1]http://www.lispworks.com/documentation/lw50/CLHS/Body/v_pr_bas.htm --~--~-~--~~~---~--~~ 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: print-base / print-radix?
Tom, Chouser, Thanks for your responses. As of now I am doing the same thing as suggested. However, this tends be become painful the moment structures start to nest. For e.g. I am using Clojure to decode a bit of assembly and below is what I end up doing to see the values of interest in hex: user=> (decode :b32 (nth test-ops 3)) {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()} user=> (def r (decode :b32 (nth test-ops 3))) #'user/r user=> (map hex (get-in r [:inst :code])) ("c7" "45" "f8" "a" "0" "0" "0") user=> (hex (second (get-in r [:inst :args]))) "a" user=> Basically, I need to extract each number seq or value individually and print it in hex for every instruction I decode and view. This isn't too much fun to do in the middle of a debug session :) Having something like *print-base* would be ideal IMHO would make scenarios like this really easy as one could simply do: user=> (set! *print-base* 16) user=> (decode :b32 (nth test-ops 3)) {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()} In the absence of this I thought of writing a function that would take an arbitrary Clojure structure/coll and print it out in the manner like above. But then it won't be much different from pprint with radix support but without the pretty part. I suppose what I am hoping is that a feature request for *print-base* sort of a mechanism get considered for Clojure as it makes scenarios like the above very easy to deal with. Any chance of this being somewhere on the Clojue todo? :) I will probably create a poor mans radix based print in the mean time for the this scenario. That should be an interesting exercise. Thanks, Parth On Jul 2, 10:58 pm, Chouser wrote: > On Thu, Jul 2, 2009 at 4:51 AM, Parth > > Malwankar wrote: > > > I frequently deal with hex and binary numbers. > > As of now when I need to view a list of numbers > > I just map a little hex function to it to translate it > > into a list of hex strings at the repl. > > > Having something like *print-base* / *print-radix* [1] may be > > valuable in such a scenario > > I don't think Java's built-in formatter is nearly as > flexible as those, but getting hex or octal strings is easy > enough: > > user=> (format "%d" 255) > "255" > user=> (format "%o" 255) > "377" > user=> (format "%x" 255) > "ff" > user=> (format "%X" 255) > "FF" > > --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
On Thu, Jul 2, 2009 at 4:51 AM, Parth Malwankar wrote: > > I frequently deal with hex and binary numbers. > As of now when I need to view a list of numbers > I just map a little hex function to it to translate it > into a list of hex strings at the repl. > > > Having something like *print-base* / *print-radix* [1] may be > valuable in such a scenario I don't think Java's built-in formatter is nearly as flexible as those, but getting hex or octal strings is easy enough: user=> (format "%d" 255) "255" user=> (format "%o" 255) "377" user=> (format "%x" 255) "ff" user=> (format "%X" 255) "FF" --Chouser --~--~-~--~~~---~--~~ 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: print-base / print-radix?
Hi Parth, It is on the agenda to support this for pprint, but I don't know exactly when. In the meantime, arbitrary bases *are* supported in the common lisp compatible format function (cl-format) which is also part of clojure.contrib.pprint. The interesting directives are ~X, ~B, and ~bR, where b is the base of interest. For example, (cl-format nil "~X" 256) => "100" (cl-format nil "~12r" 256) => "194" (cl-format true "~{~X ~}~%" [2 4 8 16 32 64 128 256]) prints to *out*: 2 4 8 10 20 40 80 100 For all the dirt on using radix, look at the Common Lisp Hyperspec: http://www.lispworks.com/documentation/HyperSpec/Body/22_cb.htm More info about the clojure implementation of format here: http://code.google.com/p/clojure-contrib/wiki/CommonLispFormat (a little out of date and about to be moved). HTH, Tom On Jul 2, 1:51 am, Parth Malwankar wrote: > I frequently deal with hex and binary numbers. > As of now when I need to view a list of numbers > I just map a little hex function to it to translate it > into a list of hex strings at the repl. > > Having something like *print-base* / *print-radix* [1] may be > valuable in such a scenario > > Or maybe an enhanced pprint? Not sure if pprint already provides > such an option or if its planned. > > I would appreciate any comments or ideas if someone > is doing something similar. > > Thanks. > Parth > [1]http://www.lispworks.com/documentation/lw50/CLHS/Body/v_pr_bas.htm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
print-base / print-radix?
I frequently deal with hex and binary numbers. As of now when I need to view a list of numbers I just map a little hex function to it to translate it into a list of hex strings at the repl. Having something like *print-base* / *print-radix* [1] may be valuable in such a scenario Or maybe an enhanced pprint? Not sure if pprint already provides such an option or if its planned. I would appreciate any comments or ideas if someone is doing something similar. Thanks. Parth [1] http://www.lispworks.com/documentation/lw50/CLHS/Body/v_pr_bas.htm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---