do-asynch-periodically

2009-06-11 Thread Wrexsoul
Consider this public domain for copyright purposes. Try it at the repl with: (defn make-counter [] (let [i (atom 0)] #(do (swap! i + 1) @i))) (def *counter* (make-counter)) (do-asynch-periodically *xxx* 1 (println (*counter*))) (do-asynch-periodically *xxx* 1 (println (str "changed! " (*counter*

Re: do-asynch-periodically

2009-06-12 Thread Wrexsoul
On Jun 12, 12:16 pm, Chouser wrote: > On Thu, Jun 11, 2009 at 3:35 AM, Wrexsoul wrote: > > > On a side note, I've noticed a few issues with clojure > > that could use a bit of sprucing up, no disrespect > > intended: > > > * If REPL code goes into infinite l

Re: A text about Clojure

2009-06-12 Thread Wrexsoul
On Jun 12, 11:58 am, CuppoJava wrote: > I would agree with Chouser. My first look at Lisp really turned me > away from FP, until I gave Clojure a chance. Same here, just about. Clojure has two very big advantages: 1. Access to the huge, very useful Java standard library. Graphics, threads, n

A few suggestions and useful things

2009-06-12 Thread Wrexsoul
Suggestion 1: In the undefined-symbol error message, special-case # by adding a note in the specific cases of clojure.core/unquote and clojure.core/unquote-splicing saying "The most common cause of this is forgetting a backtick in a macro." Var clojure.core/anything is unbound will otherwise ten

Re: A few suggestions and useful things

2009-06-12 Thread Wrexsoul
On Jun 12, 5:58 pm, Meikel Brandmeyer wrote: > > (defn eager-seq >    [s] >    (into [] s)) I guess that'd work. > > (with-files-line-seq (file1 file2 file3) lines > >  (take 10 lines)) > > The more idiomatic form would be [file1 file2 file3] > for the file arguments. Using (file1 file2 file3)

Re: do-asynch-periodically

2009-06-12 Thread Wrexsoul
On Jun 12, 4:58 pm, Chouser wrote: > > So it looks like when the compiler expands defonce, it actually > > evaluates a def right then and there, rather than the def only being > > evaluated when the expansion of the defonce macro is evaluated. > > Yes, the var is interned in the namespace at comp

super-lazy-seq

2009-06-12 Thread Wrexsoul
Well, I did it. Made implementing lazy seqs that require stateful generator functions easy, that is: (defn files-and-dirs-recursive [dir] (super-lazy-seq [stack [(to-file dir)]] (if-not (empty? stack) (let [file (first stack) s (rest stack)] (next-item file

Re: super-lazy-seq

2009-06-12 Thread Wrexsoul
Heh. Thought of an improvement: (defn make-atom-setter-fn-expr [names skip?] (let [arglist-1 (map #(gensym %) names) arglist (vec (if skip? arglist-1 (cons (gensym 'item) arglist-1)))] `(~(if skip? 'skip-item 'next-item) ~arglist ~@(map (fn [nm gs] (list 'reset! nm gs))

Re: A few suggestions and useful things

2009-06-12 Thread Wrexsoul
Here's a bit more, public domain as usual: (defn get-ultimate-cause [exception] (loop [e exception] (let [e2 (. e getCause)] (if-not e2 e (recur e2) (defmacro with-stack-trace [& body] `(try (eval (quote (do ~...@body))) (catch Throwable ex# (. (get-

Re: breaking early from a "tight loop"

2009-06-13 Thread Wrexsoul
On Jun 12, 9:44 pm, James Reeves wrote: >   (defn count-more-than? [n xs] >     (or (zero? n) >         (if (seq xs) >           (recur (dec n) (rest xs) > >   (defn interesting? [pixels c] >     (count-more-than? c (filter in-interval? pixels))) Nice, but user=> (count-more-than? 0 ()) tru

Re: breaking early from a "tight loop"

2009-06-13 Thread Wrexsoul
On Jun 13, 3:03 pm, Emeka wrote: > kedu Wrexsoul > > user=> (count-more-than? 0 ()) > true > > (defn count-more-than? [n xs] >   (if (not (seq xs)) >    (or (zero? n) >      (recur (dec n) (rest xs) > > I'm afraid your code didn't return true

EDT interaction

2009-06-13 Thread Wrexsoul
Now I'm working on some Swing code and came up with these, which are obviously going to be useful: (defmacro do-on-edt [& body] `(SwingUtilities/invokeLater #(do ~...@body))) (defmacro get-on-edt [& body] `(let [ret# (atom nil)] (SwingUtilities/invokeLater #(reset! ret# [(do ~...@body)]

Re: A few suggestions and useful things

2009-06-13 Thread Wrexsoul
On Jun 13, 4:11 pm, Jarkko Oranen wrote: > Also, try using (find-doc "foo") and (doc foo) in a repl for > documentation searches. For this function, you might want to check out > if-let. Find-doc seems to give about the same results as searching through the API page, only also cluttering up the

Re: super-lazy-seq

2009-06-13 Thread Wrexsoul
On Jun 13, 9:24 pm, James Reeves wrote: > On Jun 13, 4:18 am, Wrexsoul wrote: > > > Between files-and-dirs and file-lines-seq I think I have saved as many > > lines of code as are in the macro+helper fns, so those are at break- > > even. > > I'm not complete

Re: A few suggestions and useful things

2009-06-13 Thread Wrexsoul
; > you should take a look at it :) > > Wrexsoul:  Since you don't seem to have stumbled across > clojure-contrib yet, here is where you can find > it:http://code.google.com/p/clojure-contrib/ :) Went there earlier. http://code.google.com/p/clojure-contrib/downloads/list &q

Re: super-lazy-seq

2009-06-13 Thread Wrexsoul
On Jun 13, 11:07 pm, James Reeves wrote: > For instance, lets say I want to return a lazy list of all the lines > in all the files in a directory tree: > >   (use '(clojure.contrib java-utils >                          duck-streams)) When clojure.contrib releases version 1.0, that might be an op

Re: Primitive char Type

2009-06-13 Thread Wrexsoul
On Jun 13, 10:46 pm, "Stephen C. Gilardi" wrote: > On Jun 13, 2009, at 7:37 PM, Kevin Downey wrote: > > > works for me > > It's working for me in Java 6, but not Java 5. It looks like something   > changed there. Autoboxing. What I miss is foo-array for foo not in #{int long float double}, part

Re: super-lazy-seq

2009-06-14 Thread Wrexsoul
On Jun 14, 9:39 am, James Reeves wrote: > Okay, but don't underestimate the power of higher level functions. I > don't know whether it would apply to your code, but the repeatedly > function can be used to create a lazy seq from a function with side- > effects. > > For example: > >   (defn custom

Re: super-lazy-seq

2009-06-14 Thread Wrexsoul
On Jun 14, 2:53 pm, James Reeves wrote: > On Jun 14, 6:32 pm, Wrexsoul wrote: > > > I wrote super-lazy-seq because repeatedly can't generate a finite > > sequence. It just spat out > > > (File1 File2 File3 File4 nil nil nil nil nil nil nil ... > >

Re: Clojure goes Git!

2009-06-16 Thread Wrexsoul
On Jun 16, 10:04 pm, Antony Blakey wrote: > On 17/06/2009, at 10:58 AM, Antony Blakey wrote: > > >http://www.pragprog.com/screencasts/v-scgithub/insider-guide-to-github > > BTW: the first episode of this is free On Jun 16, 9:56 pm, Richard Newman wrote: > > And I forgot I had this:https://peepc

accum

2009-06-16 Thread Wrexsoul
I'm shocked that this is missing from clojure.core: (defn accum [f init coll] (loop [x init c coll] (if (empty? c) x (recur (f x (first c)) (rest c) user=> (accum + 0 [1 2 3]) 6 user=> (accum + 0 [1 2 3 4 5]) 15 This is one of the most basic, useful functions in functional

Re: accum

2009-06-16 Thread Wrexsoul
On Jun 17, 12:44 am, Parth wrote: > On Jun 17, 9:34 am, Wrexsoul wrote: > > I'm shocked that this is missing from clojure.core: > > > (defn accum [f init coll] > >   (loop [x init c coll] > >     (if (empty? c) > >       x > >       (recur (f x (fi

Re: accum

2009-06-16 Thread Wrexsoul
On Jun 17, 12:44 am, Daniel Lyons wrote: > Indeed! It's called reduce: > > http://clojure.org/api#toc476 > > I'm shocked you haven't noticed it in the API documentation. I SPECIFICALLY did a search of the entire api docs to see if there was anything like "accum" already in there. I examined ever

Re: accum

2009-06-16 Thread Wrexsoul
On Jun 17, 12:57 am, Sean Devlin wrote: > Daniel, don't feed the WrexTroll Personal attacks are unwelcome here. > > Indeed! It's called reduce: > > >http://clojure.org/api#toc476 > > > I'm shocked you haven't noticed it in the API documentation. I SPECIFICALLY did a search of the entire api do

Re: Clojure goes Git!

2009-06-16 Thread Wrexsoul
On Jun 16, 10:43 pm, Richard Newman wrote: > The docs produced by the Git project aren't proprietary: there are   > plenty at [1], not to mention `man git`. I just see a great deal of   > value in clear, explanatory text Enough value that there should be free clear, explanatory text about open s

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 3:10 am, Mark Derricutt wrote: > There's prebuilt SNAPSHOT releases available in Howard's Tapestry repository > - been using them happily from my maven based clojure app for awhile. > Thou an official 1.0 stamped release in maven central (along with > clojure-lang) would be most welcom

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 2:05 am, Parth wrote: > On Jun 17, 10:24 am, Wrexsoul wrote: > > > On Jun 17, 12:44 am, Daniel Lyons wrote: > > > > (use 'clojure.contrib.seq-utils) > > > Don't have that library. Still hasn't been released yet, last I >

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 3:20 am, kkw wrote: > I only knew about map, apply, and reduce from studying haskell in uni. > I've not heard of 'reduce' referred to as 'accum', but then again when > I wanted to determine the number of elements in a seq, I kept > searching for 'length' and 'size' but didn't think of

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 10:51 am, Mark Volkmann wrote: > On Wed, Jun 17, 2009 at 9:41 AM, CuppoJava wrote: > > Finding the right function in the doc admittedly takes a little > > practice. I've learned gradually, that Clojure pretty much has all its > > bases covered though. You just need to find the function

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 2:25 pm, Cosmin Stejerean wrote: > On Wed, Jun 17, 2009 at 12:51 PM, Wrexsoul wrote: > > > > Even though clojure.contrib hasn't been released as 1.0 or anything > > > official-sounding, I reckon it still beats the heck out of me > > > rein

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 2:47 pm, Kyle Schaffrick wrote: > As a friendly suggestion, I'd like to offer that perhaps the derision is > caused not by the fact that you had the initiative to implement it > yourself, but rather by such phrasing as: > > > I'm shocked that [reduce/accum/foldr] is missing from clojur

Re: accum

2009-06-17 Thread Wrexsoul
s here. > > My apologies to Wrexsoul. I was out of line. Civility and mutual   > respect are more important. Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. T

Re: accum

2009-06-17 Thread Wrexsoul
On Jun 17, 4:00 pm, Rich Hickey wrote: > On Jun 17, 1:22 am, Wrexsoul wrote: > > The docs definitely have problems if this can be missed despite a very > > thorough search. The only more-thorough search would have been to > > actually read the docs in their entirety, rathe

Re: Trying to use lazy-seq for the first time, failing.

2009-06-27 Thread Wrexsoul
On Jun 26, 8:23 pm, _hrrld wrote: > Hi, > > I'm trying to use lazy-seq to implement a cool piece of functionality > I saw in the Factor programming language. Here is the documentation > for that > functionality:http://docs.factorcode.org/content/word-produce,sequences.html > > I think a lazy ver