On Sat, Oct 31, 2009 at 1:23 PM, Stuart Sierra <the.stuart.sie...@gmail.com>wrote:
> > For even more fun, you can take advantage of the fact that commas are > whitespace, and use a macro to do it at compile time: > > (defmacro bignum [& parts] > (read-string (apply str parts))) > > (bignum 99,871,142) > 99871142 Eh. Who needs converting to a string and back? Why not: (defmacro bignum [& args] `(reduce (fn [a# b#] (+ a# (apply * b#))) 0 (map vector (reverse '~args) (iterate (fn [x#] (* 1000 x#)) 1)))) user=> (bignum 318,584,297) 318584297 No mess, no fuss. For some reason though changing "defmacro" here to "definline" doesn't work. It says #<CompilerException java.lang.Exception: Unable to resolve symbol: & in this context (NO_SOURCE_FILE:129)> which is clearly bogus, since the only & in there indicates a rest part rather than being in a position where it would be evaluated as a var name. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---