Hi Saul, > (defn explode-to-digits [number] > (seq (str number))) This gives you a sequence of character representations for the digits e.g: (explode-to-digits 1234) => (\1 \2 \3 \4)
On 17/02/2011, at 4:01 PM, Saul Hazledine wrote: > On Feb 17, 6:29 am, Andreas Kostler <andreas.koestler.le...@gmail.com> > wrote: >> Is there an easy and idiomatic way of getting the digits of a number in >> clojure? >> >> (defn explode-to-digits [number] >> (map #(- (int %) (int \0)) (str number))) >> (explode-to-digits 123456) >> => (1 2 3 4 5 6) > > I'd do it this way: > > (defn explode-to-digits [number] > (seq (str number))) > > Saul > > -- > 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 -- "Programs must be written for people to read, and only incidentally for machines to execute." - Abelson & Sussman, SICP -- ********************************************************** Andreas Koestler, Software Engineer Leica Geosystems Pty Ltd 270 Gladstone Road, Dutton Park QLD 4102 Main: +61 7 3891 9772 Direct: +61 7 3117 8808 Fax: +61 7 3891 9336 Email: andreas.koest...@leica-geosystems.com ************www.leica-geosystems.com************* when it has to be right, Leica Geosystems Please consider the environment before printing this email. -- 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