Re: Make a loop in a loop

2010-07-07 Thread RandyHudson
'doseq instead 'for works fine: (doseq [y (range 1999 2011), w (range 1 52)] (print-data y w)) On Jul 7, 11:14 am, Stuart Halloway stuart.hallo...@gmail.com wrote: This usage of for is ill-advised: for is not a loop, it is a comprehension. This will not do what you want if, for example, you

Re: dtd question

2010-06-29 Thread RandyHudson
Yes, you can do this by defining an EntityResolver that corrects the bad system id, define a SAXParser that uses that resolver, and pass the parser into the xml/parse call. Something like this: (import '[javax.xml.parsers SAXParserFactory] '[org.xml.sax EntityResolver InputSource]) (def

Re: the joys of lisp

2010-06-28 Thread RandyHudson
Here's some of Rich Hickey's rationale, from an old IRC chat (http:// clojure-log.n01se.net/date/2008-11-06.html): Clojure doesn't allow user-defined reader macros because they can't be combined - there's no namespace support, unlike for regular macros the clash problem is significant - I don't

Re: scala

2010-06-18 Thread RandyHudson
Bear in mind that Scala is about 5 years older than Clojure, so it's had more time to build up momentum. On Jun 18, 5:56 pm, cageface milese...@gmail.com wrote: Unfortunately there seems to be a lot more commercial momentum for Scala though. It's still a blip compared to the mainstream

Re: Problems with URL params and http-agent

2010-06-17 Thread RandyHudson
You don't want to encode the whole URL, just the keys and values in the query string. Something like this: (defn encode-params [request-params] (let [encode #(URLEncoder/encode (str %) UTF-8) coded (for [[n v] request-params] (str (encode n) = (encode v)))] (apply str (interpose

Re: macro help

2010-05-10 Thread RandyHudson
As Lauren Petit points out, you need the macro to define the whole desired result. Something like this should do it: (defmacro defautoroutes [name paths] (let [getps (for [p paths] `(GET ~(str / p) (foo ~p)))] `(defroutes ~name ~...@getps))) (defautoroutes all-routes one two three) On

Re: rand-int with bignums

2010-05-02 Thread RandyHudson
Per Alex Osborne's reference to BigInteger constructors, here's a random BigInteger function: (defn rand-bigint [#^BigInteger bign, #^Random rnd] (let [bits (inc (.bitLength bign)) bigr (BigInteger. bits rnd)] (- bign (.multiply bigr) (.shiftRight bits -- You received this

Re: Multimethod attribute maps

2010-01-21 Thread RandyHudson
The attr-map adds key-value pairs to the metadata for the function symbol. The doc for 'defn' makes this clearer. On Jan 20, 8:02 am, Jacek Generowicz jacek.generow...@googlemail.com wrote: In Clojure 1.1.0, the documentation states: clojure.core/defmulti ([name docstring? attr-map?

Re: Standard calling-a-function function?

2009-10-22 Thread RandyHudson
(apply arg) On Oct 21, 7:49 pm, samppi rbysam...@gmail.com wrote: Is there a standard function that takes one argument and calls it? That is, the function equivalent to #(%). Or is that the best idiom there is? --~--~-~--~~~---~--~~ You received this message