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  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 assign the result of for 
> to a variable instead of entering it at the REPL.
>
> Nurullah's response on this thread shows a nice separation of building the 
> (lazy) structure and printing it.
>
> Stu
>
> > (for [y (range 1999 2011) w (range 1 52)] (println "year=" y "w=" w))
>
> > On Jul 7, 2010, at 10:47 AM, uap12 wrote:
>
> >> Hi!
> >> I try to make a printout witch vill have year 1999->2010 and every
> >> week
> >> Eg.
> >> Year=1999 Week=1
> >> Year=1999 Week=2
> >> Year=1999 Week=3
> >> Year=1999 Week=4
> >> 
> >> Year=2000 Week=1
>
> >> I have made the program in java, but like to try making it in Clojure,
> >> but so far i have got
> >> 
> >> (defn print-data [year week]
> >>        (println  (str  "Y=" year " W=" week)))
>
> >> // This would not work and  i can't find how to map (print-data with a
> >> external variabel and a range
> >> // I can set week to a fixed number but not.
> >> // Or is this the wrong way of doing it ??
>
> >> (defn print-data2 [year]
> >>        (map (print-data year *) (range 1 53 1)))
>
> >> (defn run []
> >> (map print-data2 (range 1999 2010 1) ) )
>
> >> The program vill call an externa system program, with year and week as
> >> input, but for this test i just
> >> like to write them...
>
> >> // Anders
>
> >> --
> >> 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
>
> > --
> > 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

-- 
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: 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 resolver
  (proxy [EntityResolver] []
(resolveEntity [public-id system-id]
  (InputSource.
(if (= system-id the-bad-system-id)
  the-good-system-id
  system-id)

(def parser
  (doto (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver resolver)))

(defn parse-xml [source] (xml/parse source parser))



On Jun 29, 8:18 pm, Manfred Lotz  wrote:
> Hi there,
> I got a directory tree of xml documents all having the same dtd.
> However the dtd file is not where the DOCTYPE SYSTEM entry says it is.
>
> Currently, xml/parse throws an exception that the dtd file will not be
> found.
>
> Is there a possibility to tell xml/parse about a different location
> of that dtd file?
>
> --
> Thanks,
> Manfred

-- 
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: 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 want libraries that can't
be combined. Macros work, user-defined reader macros don't"

On Jun 27, 8:15 pm, rob levy  wrote:
> Certainly macros can be dangerous if used recklessly or clumsily, but
>
> > isn't trusting the programmer and giving him powerful tools what Lisp
> > is all about? No other language provides the same power of expression.
> > A tour through the Clojure code demonstrates just how powerful this
> > idea is and how easy it makes it for the language implementors to
> > implement features in a few lines of code that are major bullet-point
> > features in other languages.
>
> In my opinion it is much better to empower developers and build a culture of
> good taste and self-discipline, than to limit the language in an attempt to
> enforce particular styles.  Python is the latter and Lisp is the former.
>  And Python code is  often convoluted because of programmers working around
> the limitations imposed by the language.  And don't get me started on lines
> of code that begin at column 80 etc. ;)
>
> I would argue in favor of user-defined reader macros for these same reasons,
> they are rarely needed but why not maximize the power of Clojure?  I think
> the last word on this from Rich Hickey was "many things that would otherwise
> have
> forced people to reader macros may end up in Clojure, where everyone can
> benefit from a common approach".  To me this is Rich being like Guido von
> Rossum, but maybe there are other good reasons behind the decision that he
> has either not articulated or I just am not aware of/haven't read.
>
> Rob

-- 
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: 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  wrote:

> Unfortunately there seems to be a lot more commercial momentum for
> Scala though. It's still a blip compared to the mainstream languages
> but I'm seeing more and more job posts mentioning it, and hardly any
> for Clojure.

-- 
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: 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 "&" coded





On Jun 16, 9:21 pm, Timothy Washington  wrote:
> Hey all, something very weird happens when trying to use the http-agent. If
> I execute a) or b) in a browser, I get the desired result XML.
> a)http://RESTful/path/to/xml
> b)http://RESTful/path/to/xml?_wrap=no&_query=declaredefault element
> namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']
>
> However, using clojure, If I try the same call, d) in this case will NOT
> work.
> c) (clojure.contrib.http.agent/http-agent "http://RESTful/path/to/xml";)
>     ; works
> d) (clojure.contrib.http.agent/http-agent 
> "http://RESTful/path/to/xml?_wrap=no&_query=declaredefault element namespace
> 'com/interrupt/bookkeeping/users';//user[ @id='one']")         ; doesn't
> work
>
> I've tried url-encoding the url using the below function, but that doesn't
> help either.
> (defn url-encode [text]
>   (URLEncoder/encode text "UTF-8"))
>
> Is the something obvious I'm missing?
> Thanks

-- 
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: 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 May 6, 10:21 pm, Micah Martin  wrote:
> Hey all,
>
> I'm having trouble writing a macro and I hoping some one here can help.  My 
> desired result is the following:
>
> (defroutes all-routes
>   (GET "/one"   (foo "one"))
>   (GET "/two"   (foo "two"))
>   (GET "/three" (foo "three")))
>
> But I'd like to write it like so:
>
> (defroutes all-routes
>   (make-foos "one" "two" "three"))
>
> How do I write make-foos?  Does if have to be a macro, or can it be a 
> function?
>
> Thanks,
>
> Micah
>
> --
> 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 
> athttp://groups.google.com/group/clojure?hl=en

-- 
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: 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 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: 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 
wrote:
> In Clojure 1.1.0, the documentation states:
>
> clojure.core/defmulti
> ([name docstring? attr-map? dispatch-fn & options])
> Macro
>   Creates a new multimethod with the associated dispatch function.
>   The docstring and attribute-map are optional.
>
>   Options are key-value pairs and may be one of:
>     :default    the default dispatch value, defaults to :default
>     :hierarchy  the isa? hierarchy to use for dispatching
>                 defaults to the global hierarchy
>
> What is the purpose of the attribute map (and, perhaps more
> importantly, where could I have found an explanation in the
> documentation) ?
>
> Thank you.
-- 
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: roll call of production use?

2009-11-24 Thread RandyHudson


On Nov 24, 11:30 am, John Harrop  wrote:

> There's a Clojure or a Java library for generating pdf?

Apache FOP is an XSL-FO processor than can generate PDF documents.
I've heard good things about iText, a Java library for generating or
modifying PDF docs.

-- 
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: Standard calling-a-function function?

2009-10-22 Thread RandyHudson

(apply arg)

On Oct 21, 7:49 pm, samppi  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 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
-~--~~~~--~~--~--~---