Re: Newbie : Java Interop question

2010-10-15 Thread Randy Hudson
Nested classes require the syntax AClass$NestedClass -- this being the "real name" of the class in the JVM. Static members of classes are referenced as AClass/member -- essentially treating the class as a namespace of its static members. So this should do it: (IEssbase$Home/create IEssbase/JAPI_VE

Re: Agent errors

2010-10-05 Thread Randy Hudson
The docstring for set-error-handler!, to which the docstring for agent refers, does document the argument list of a handler-fn. I'd also be interested in an explanation of the new scheme. The discussion on http://clojure.org/agents hasn't been updated to 1.2. On Oct 5, 8:48 pm, Lee Spector wrot

Re: big integers in 1.2 leading to parked processes? (maybe somehow, I think)

2010-10-03 Thread Randy Hudson
Oops, that changes doc is http://github.com/clojure/clojure/blob/1.2.x/changes.txt On Oct 3, 6:52 pm, Randy Hudson wrote: > One thing that did change between 1.1 and 1.2 is agent error handling. > The 1.2 changes doc  (http://github.com/clojure/clojure/blob/1.2.x/ > hanges.txt) shows se

Re: big integers in 1.2 leading to parked processes? (maybe somehow, I think)

2010-10-03 Thread Randy Hudson
One thing that did change between 1.1 and 1.2 is agent error handling. The 1.2 changes doc (http://github.com/clojure/clojure/blob/1.2.x/ hanges.txt) shows several new agent error handling functions, a couple of deprecated ones, an improved 'await docstring -- which now says: "Blocks the current

Re: Using Enum Qt.AlignmentFlag ClassNotFoundException

2010-09-21 Thread Randy Hudson
Try Qt$AlignmentFlag On Sep 21, 6:20 am, Matt Hoyt wrote: > I trying to use QtJambi and I'm having problems using the enums that > have this format Qt.. > > Error: > > error: java.lang.ClassNotFoundException > > Code: > > (ns collab-web-qt.dialog.connect >   (:import (com.trolltech.qt.gui QDialog

Re: Interesting Paper on Macros

2010-09-12 Thread Randy Hudson
Here's the teaser, er, I mean abstract: "Existing macro systems force programmers to make a choice between clarity of specification and robustness. If they choose clarity, they must forgo validating significant parts of the specification and thus produce low-quality language extensions. If they ch

Re: Knowing in advance the complexity of count

2010-09-09 Thread Randy Hudson
Inexplicably (counted? "abcd") returns false. On Sep 9, 11:33 am, Sunil S Nandihalli wrote: > actually there is a function called > > counted? > > Sunil. > > On Thu, Sep 9, 2010 at 8:59 PM, Nicolas Oury wrote: > > Thank you very much. > > > Never looked closely at count definition. > > > I assum

Re: trouble using nested map fn

2010-08-23 Thread Randy Hudson
Well, #(<= lo % hi) is to my mind much more readable than (fn [x] (<= lo x hi)), especially embedded in another form or two (as it would be). On Aug 23, 11:48 am, gary ng wrote: > On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic wrote: > > It's not about nested maps, but about nested anonymous f

Re: Protocols and default method implementations

2010-08-12 Thread Randy Hudson
Protocols are very similar to Java interfaces: they specify a set of functions/methods without providing an implementation. The big distinction is in more dynamic usage. Rich Hickey's description at http://clojure.org/protocols is well written. On Aug 12, 7:52 pm, Tim Daly wrote: > I find that I

Re: take-while2?

2010-08-07 Thread Randy Hudson
Nice! On Aug 7, 11:56 pm, Michał Marczyk wrote: > Yet another version: > > (defn take-while-acc [f pred coll] >   (map (fn [_ x] x) >        (take-while pred (reductions f coll)) >        coll)) > > Seems to work: > > user> (take-while-acc + #(< % 100) (range)) > (0 1 2 3 4 5 6 7 8 9 10 11 12 13)

Re: take-while2?

2010-08-07 Thread Randy Hudson
Andreas, there's no such function in Clojure core, and I'm fairly sure there's not one in contrib. Stop reading if you don't want to see my version; it was a fun little puzzle. (defn take-while-reduction [f pred coll] (let [rf (juxt #(reductions f %) identity)] (->> coll rf (apply map vecto

Re: 2 links for beginners

2010-08-05 Thread Randy Hudson
Here's a nice commentary by fogus on Yegge's piece: http://blog.fogus.me/2009/02/06/yegge-clojure-arc-and-lolita-or-days-of-future-past/ "For all intents and purposes, Clojure’s creator Rich Hickey is Arc’s Torvalds quipped on by Mr. Yegge. " On Aug 5, 8:08 am, faenvie wrote: > >http://steve-yeg

Re: Need help with syntax for implementing multiple arity protocol method

2010-08-04 Thread Randy Hudson
You need to name the protocol before the method implementations. That's why the "PersistentList cannot be cast to Symbol" message -- the compiler's expecting a protocol (or interface) symbol after [r]. And, as the examples on http://clojure.org/protocols show, you need to define the different arit

Re: = and byte arrays

2010-08-03 Thread Randy Hudson
(= (seq ba1) (seq ba2)) will give you a value (byte-by-byte) comparison. On Aug 3, 2:00 pm, Steven Devijver wrote: > Given two byte arrays that have the same content (value) the code > below runs without errors: > > (def ba1 (...)) > (def ba2 (...)) > > (assert (not= ba1 ba2)) > (assert (= (Strin

Re: dtd question

2010-08-01 Thread Randy Hudson
ope this has been helpful despite my mistakes. On Aug 1, 2:50 pm, Manfred Lotz wrote: > Hi Randy, > > On Sun, 1 Aug 2010 10:04:16 -0700 (PDT) > > Randy Hudson wrote: > > Right you are Michael; sorry for the missing paren at the end of the > > def. > > No

Re: dtd question

2010-08-01 Thread Randy Hudson
Right you are Michael; sorry for the missing paren at the end of the def. On Aug 1, 11:59 am, Michael Wood wrote: > On 1 August 2010 17:15, Manfred Lotz wrote: > > > > > > > Hi Randy, > > > On Sun, 1 Aug 2010 06:23:58 -0700 (PDT) > > Randy Hudson wrote:

Re: dtd question

2010-08-01 Thread Randy Hudson
Hi Manfred, I'm sorry the code wasn't quite correct. The EntityResolver is set on the parser's XMLReader, not on the parser itself: (def parser (.newSAXParser (SAXParserFactory/newInstance)) (.setEntityResolver (.getXMLReader parser) resolver) You don't need any external jars: all the classes an

Re: destructuring using :as in fn arg vector

2010-07-27 Thread Randy Hudson
The form you're looking for is (defn foo [ & [a b :as c]] ...) On Jul 27, 2:57 pm, Cameron wrote: > Hey all, just wondering if this is normal or not. There seems to be > something weird going on with :as in a functions arg vector. > > This little example works as I'd expect... > user=> (defn foo

Re: java.lang.OutOfMemoryError

2010-07-26 Thread Randy Hudson
You can get a lazy sequence of all the lines in all the files by something like: (for [file out-files line (with-open [r (io/reader file)] (line-seq r))] line) If "StatusJSONImpl" is on a separate line, you can throw in a :when clause to filter them out: (for [file out-files line (

Re: Efficiency of reduce function for lists.

2010-07-25 Thread Randy Hudson
This is a wholly appropriate use of reduce; it's the obvious function to use when you want to "accumulate" some calculation over a sequence. As you say, you can just produce a function that acts on the result, something like (defn fstep [c] (if (= c \<) pop #(conj % c)) However, the obvious way

Re: Remove-first function

2010-07-24 Thread Randy Hudson
Here's my take: (defn remove-first [x coll] (let [[pre post] (split-with #(not= x %) coll)] (concat (pre (rest post On Jul 24, 11:41 am, nickikt wrote: > Hallo all, > > I'm working trough Essentials of Programming Languages. I'm trying to > right a function like this one: > > (defn sch

Re: gobble up a collection 2 at a time

2010-07-22 Thread Randy Hudson
(partition 2 coll) will give you the sequence two at a time. To map your function, you'd do (map #(apply myfcn %) (partition 2 '(1 2 3 4 5 6 7 8))) On Jul 21, 10:20 pm, Glen Rubin wrote: > Hi!  I want to process a collection 2 elements at a time using map. > > My function accepts 2 parameters (a,

Re: randomizing a vector

2010-07-21 Thread Randy Hudson
Clojure 1.2 has a shuffle function. If you're using 1.1, you can just cop the 1.2 implementation. On Jul 21, 1:18 pm, Ryan Waters wrote: > http://gist.github.com/484747 > > - - - > > My sad little program has a number of issues and I would welcome > suggestions on any aspect of it.  I come from a