Re: table vaadin?

2011-06-25 Thread Benny Tsai
That usually means somewhere in the code, an object of class com.vaadin.ui.Table is being used where a function is expected. For example, evaluating this code: (abc 1) ...will result in java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn, because a String can't

Re: function to split a collection into predicate passes and failures?

2011-06-25 Thread Benny Tsai
You could also use group-by: user= (group-by odd? [1 2 3 4 5]) {true [1 3 5], false [2 4]} The nice thing is that you can also use this with functions that return more than 2 values: user= (group-by class [0 nil false]) {java.lang.Integer [0], nil [nil], java.lang.Boolean [false]} --

Re: struct sharing same key?

2011-06-27 Thread Benny Tsai
:1 and :3 are keywords, not numbers. map literals are specified in terms of key-value pairs; for example, in {a b c d}, a and c are keys, b and d are values. In your person struct, :1 is only used as a key once, which is why that works. This might help make things clearer: (struct person

Re: Data filtering function

2011-07-05 Thread Benny Tsai
This should work: (defn my-filter [coll k] (for [m coll] (get m k))) -- 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

Re: Correct way to define the else clause of a cond form?

2011-07-06 Thread Benny Tsai
I believe (d) is considered the idiomatic way*. Btw, I think the second case may not be written correctly; if the intended logic is that 9.75 should be returned when either amount 20 or country = US, the code should look something like this: (cond (= total 20) 8.75 (or ( amount 20) (=

Re: Correct way to define the else clause of a cond form?

2011-07-06 Thread Benny Tsai
Could you please post the entire form, including the code surrounding the cond form (since total, amount, and country need to be defined somewhere)? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Correct way to define the else clause of a cond form?

2011-07-06 Thread Benny Tsai
On Wednesday, July 6, 2011 9:06:30 PM UTC-6, Tim Robinson wrote: You have some rogue text cluttering your cond statement. Remove the question mark... or whatever this is...  and you'll be fine. That's what I encountered too. Conrad, when I pasted your code into emacs, there was a

Re: Help on a Clojure performance question

2011-07-08 Thread Benny Tsai
Hi Christopher, I ran your code with only one modification, using the time macro to measure the execution time of the mapper function itself: (use ['clojure.java.io :only '(reader)]) (use ['clojure.string :only '(split)]) (defn mapper [lines] (doseq [line lines] (doseq [word (split line

Re: Modelling complex data structures (graphs and trees for example)

2011-07-09 Thread Benny Tsai
Hi Colin, Sorry, a bit late to the party here, but it might be worth taking a look at Jeffrey Straszheim's c.c.graph library to see one way of modeling DAG's and implementing various graph operations (such as topological sort and computing strongly connected components) in Clojure: API:

Re: Modelling complex data structures (graphs and trees for example)

2011-07-09 Thread Benny Tsai
Oops, correction: since the library already defines a struct called directed-graph, it appears that you can't define a record of the same name. So it'll have to be called something else: (defrecord graph [nodes neighbors]) (def my-graph (graph. [:a :b] {:a [:b], :b [:a]})) -- You

Re: help with some code

2011-07-12 Thread Benny Tsai
alist is missing parens around the fn, so it's really a list of 4 elements like so: (1, fn, [x y], (+ x y)) So (second alist) returns just the symbol 'fn. And when you apply a Symbol to a list, the result is the last item in the list (not sure why). To do what you want, alist should be

Re: Help with some code

2011-07-12 Thread Benny Tsai
Hi Paul, I posted an answer to your question in the monads macros discussion. -- 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

Re: help with some code

2011-07-12 Thread Benny Tsai
Nice, yes, that works just as well :) On Tuesday, July 12, 2011 4:09:09 PM UTC-6, LaPingvino wrote: Didn't try, but shoudn't (def alist `(1 ~(fn [x y] (+ x y be better? Then you don't need the eval :) 2011/7/12 Benny Tsai benny...@gmail.com alist is missing parens around the fn, so

Re: help with some code

2011-07-12 Thread Benny Tsai
For that method, you need a back-quote ` (used in macro definition) in front of the 1, not a single quote ' (used to make a form data instead of code). -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Questions About Assoc-in, Dissoc-in, etc.

2011-07-16 Thread Benny Tsai
W.r.t. item 2, would get-in be close to what you're looking for? http://clojuredocs.org/clojure_core/clojure.core/get-in -- 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

Re: use of subseq on a vector which I know is already sorted

2011-07-18 Thread Benny Tsai
Hi Sunil, If you know that the input sequence is already sorted, then you can use take-while and drop-while in lieu of subseq. (subseq (sorted-set 1 2 3 4) 3) - (take-while #( % 3) [1 2 3 4]) (subseq (sorted-set 1 2 3 4) = 3) - (take-while #(= % 3) [1 2 3 4]) (subseq (sorted-set 1 2 3 4) 3) -

Re: use of subseq on a vector which I know is already sorted

2011-07-18 Thread Benny Tsai
On Monday, July 18, 2011 9:12:05 AM UTC-6, Meikel Brandmeyer wrote: Hi, *snip* However with a different performance promise, I believe. Hi Meikel, I took a look at the source for subseq, and you're right. To be specific, when the comparison operation is either or =, seqFrom allows

Problem with ClojureScript and Node.js

2011-07-23 Thread Benny Tsai
I'm experimenting with the latest build of ClojureScript from github on Windows. I can get as far as compiling nodehello.cljs from the Quick Start guide, but I get the following error when trying to run the compiled .js file with Node: node.js:195 throw e; // process.nextTick error,

Re: Problem with ClojureScript and Node.js

2011-07-23 Thread Benny Tsai
I should add that I did have to make one change to closure.clj in order to compile nodehello.cljs; I changed the following line in the ns-file-name function: path (string/replace (munge ns) \. java.io.File/separatorChar)] To: path (string/replace (munge ns) \. \/)] -- You received this

Problem with ClojureScript + Node.js

2011-07-24 Thread Benny Tsai
I'm experimenting with ClojureScript on Windows. After applying the patch kindly provided by pmbauer in this thread: https://groups.google.com/d/topic/clojure/kObCK4Ik3tY/discussion ... I was able to get as far as compiling the nodehello.cljs example code from the Quick Start guide. However,

Re: Problem with ClojureScript + Node.js

2011-07-24 Thread Benny Tsai
On Sunday, July 24, 2011 1:33:47 PM UTC-6, Sean Corfield wrote: That gave me version v0.4.11-pre and it seems to be working just fine with ClojureScript. The build from source option on Windows sounds like it isn't very stable which makes we wonder about the pre-built binaries and why those

Re: Problem with ClojureScript and Node.js

2011-07-24 Thread Benny Tsai
Thank you for your response, Urlik. It's good to know someone else saw the same error, on a non-Windows platform, no less. Sean Corfield, responding to an earlier failed attempt by me to post about the problem, said that he was able to use Node with ClojureScript on OSX after following the

Re: Code structure/design problems

2011-07-27 Thread Benny Tsai
Hi Oskar, I just came across this article yesterday, which I thought you may find useful. It's a 4-part series where the author discusses his experience implementing games in a functional style: http://prog21.dadgum.com/23.html He was using Erlang, but I think many of the same ideas apply

Re: ClojureScript on Windows

2011-07-30 Thread Benny Tsai
Brenton, thank you for your efforts! I noticed that in the current .bat files, CLASSPATH is directly modified and over-written. Perhaps they should instead use CLJSC_CP like the sh scripts? On Saturday, July 30, 2011 10:10:03 AM UTC-6, Brenton wrote: The problems with paths on Windows have

Re: Problem with ClojureScript and Node.js

2011-07-30 Thread Benny Tsai
Thank you for tracking it down and doing the legwork, Anthony :) On Thursday, July 28, 2011 5:50:37 PM UTC-6, Anthony Grimes wrote: Oh! I apologize. I was replying via the google interface and didn't realize it wasn't quoting. Here is a link to the topic for context:

Re: Non-binary tree?

2011-08-19 Thread Benny Tsai
Probably a good idea for get-nodes to handle potential cycles: (defn get-nodes [from to] (loop [visited #{} [x xs] [from]] (if-not x visited (let [new-visited (conj visited x) neighbors (candidates x to) new-queue (remove new-visited (concat xs

Re: Apply concat and mapcat evaluate seqs unnecessarily

2011-08-22 Thread Benny Tsai
This is my attempt to take Meikel's code and extend it to accept arbitrarily many collections as 'mapcat' does: (defn lazy-mapcat [f colls] (lazy-seq (when (every? seq colls) (concat (apply f (map first colls)) (apply lazy-mapcat f (map rest colls)) user= (- (iterate

Re: clojure and emacs

2011-09-03 Thread Benny Tsai
You can set lein repl as your inferior lisp program via: M-x describe-variable inferior-lisp-program And as long as you start emacs somewhere in your lein project directory (or M-x cd to it), you'll have all the libraries loaded in your REPL buffer. On Thursday, September 1, 2011 11:03:13 AM

Re: clojure and emacs

2011-09-03 Thread Benny Tsai
will be available to (require ...) in your REPL buffer. On Saturday, September 3, 2011 7:32:28 PM UTC-6, Benny Tsai wrote: You can set lein repl as your inferior lisp program via: M-x describe-variable inferior-lisp-program And as long as you start emacs somewhere in your lein project directory (or M-x

Re: clojure.contrib.io, clojure.contrib.http.agent and clojure.contrib.http.connection for Clojure 1.3

2011-09-26 Thread Benny Tsai
Mark McGranaghan and Lee Hinman's clj-http is a nice HTTP library that's fully compatible with Clojure 1.3: https://github.com/dakrone/clj-http -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Benny Tsai
The reason that (rand-nth (seq (sorted-set 1 2 3))) performs badly on large sets is probably because nth is O(n) on sequences. nth is much much faster on vectors, so I would suggest trying out (rand-nth (vec (sorted-set 1 2 3))) and see if that works for your application. -- You received

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Benny Tsai
On Monday, September 26, 2011 2:58:59 PM UTC-6, Paul Richards wrote: This will replace an O(n) call to nth with an O(n) call to copy into a vector, so still leaving me with O(n). Oops, right :) If you're getting random elements out of the same sorted set multiple times, then it might be

Re: Flattening a tree

2011-10-21 Thread Benny Tsai
The example tree was not accepted as a valid data structure, so I used this instead. Hopefully it represents what you had in mind: (def tree {:parent1 {:relationship1 {:child1 1 :child2 2} :relationship2 {:child3 3} :_meta

Re: Clojure Conj extracurricular activities spreadsheet

2011-10-28 Thread Benny Tsai
Please add me for core.logic, Heroku Drinkup, and Jamming with Overtone. -- 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

Re: Datestreams

2011-11-01 Thread Benny Tsai
Untested, since I don't have JodaTime installed, but something like this maybe? (defn day-of-week-stream [ day-nums] (filter #((set day-nums) (.. % dayOfWeek get)) (today+all-future-dates))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post

Re: Datestreams

2011-11-02 Thread Benny Tsai
day-nums)] (filter #(day-set (.. % dayOfWeek get)) (today+all-future- dates On Nov 1, 10:57 pm, Baishampayan Ghose b.g...@gmail.com wrote: On Wed, Nov 2, 2011 at 11:01 AM, Benny Tsai benny...@gmail.com wrote: Untested, since I don't have JodaTime installed, but something like

Re: a better way to write this

2011-11-04 Thread Benny Tsai
This is slightly shorter: full-test (fn [element] (every? #(% element) [type-pred bounds-check contact])) On Friday, November 4, 2011 10:51:43 AM UTC-6, HamsterofDeath wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 here's a part of my clojureoids-code: (let [type-pred #()

Re: a better way to write this

2011-11-04 Thread Benny Tsai
Oh that is cool! On Friday, November 4, 2011 12:11:43 PM UTC-6, Paul Mooser wrote: You could try using every-pred to combine your predicates, which I think would be equivalent: (let [full-test (every-pred type-pred bounds-check contact)] ... On Nov 4, 9:51 am, Dennis Haupt

Re: All subsets of a vector

2011-11-09 Thread Benny Tsai
Another way to do it, using 'reductions': (rest (reductions conj [] a1)) On Wednesday, November 9, 2011 5:47:08 PM UTC-5, Shoeb Bhinderwala wrote: Is there a more elegant/idomatic way to achieve the following result: user= a1 [a b c d] user= (map-indexed (fn [n x] (vec (take (inc n)

Re: All subsets of a vector

2011-11-09 Thread Benny Tsai
That's exactly what 'reductions' does :) On Wednesday, November 9, 2011 6:09:08 PM UTC-5, Alex Baranosky wrote: Does Clojure have the equivalent of Haskell's 'scan' function? (I am on my phone...) Seems like a solution with that would be nice. (scan is like reduce except it keeps all

Re: Clojure Conj extracurricular activities spreadsheet

2011-11-10 Thread Benny Tsai
Does anyone know if the Web and Clojure session will be taking place tonight or another night? -- 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

Re: Implementing a clojure-only periodic timer...

2011-12-01 Thread Benny Tsai
Overtone's 'at-at' library is a thin Clojure wrapper over ScheduledThreadPoolExecutor with a nice interface. I think you should be able to build a timer on top of it pretty easily. https://github.com/overtone/at-at On Thursday, December 1, 2011 10:17:40 AM UTC-7, Bill Caputo wrote: Hi All,

Re: Agents vs. Actors

2011-12-03 Thread Benny Tsai
Hi Nils, A while back, I also took a stab* at implementing Erlang-style actors in Clojure, along with solutions for a few classic concurrency problems (Dining Philosophers, Sleeping Barber). I was blown away by how easy it was to implement actor semantics on top of agents. Comparing our

Bug in core.match?

2011-12-10 Thread Benny Tsai
Hi all, Ran into what appears to be a bug tonight. This is the simplest example I could come up with: (defn f [xs] (match xs [:a] a [:b b] b [:c] c :else problem!)) [:a] and [:b b] can be matched with no problems, but [:c] can't be matched for some

Re: Bug in core.match?

2011-12-10 Thread Benny Tsai
Done! On Saturday, December 10, 2011 9:08:22 AM UTC-7, David Nolen wrote: Please open a ticket on JIRA with this case - http://dev.clojure.org/jira/browse/MATCH Thanks! David On Sat, Dec 10, 2011 at 5:33 AM, Benny Tsai benny...@gmail.com wrote: Hi all, Ran into what appears

Re: Get sequence of values in arbitrarily nested collection

2010-12-05 Thread Benny Tsai
When I saw the part about traversing an arbitrarily nested collection, I immediately thought of clojure.walk (http://clojure.github.com/ clojure/clojure.walk-api.html). I ended up with this: (use 'clojure.walk) (defn all-vals [k coll] (let [vals (atom []) find-val (fn [form]

Re: math utilities question

2010-12-05 Thread Benny Tsai
Always nice to see a fellow Neal Stephenson fan! On Dec 5, 10:26 pm, Ken Wesson kwess...@gmail.com wrote: On Mon, Dec 6, 2010 at 12:14 AM, Miki miki.teb...@gmail.com wrote: Have you looked at Incanter? (http://incanter.org/) Hmm, interesting. Is there a Rhetor too? -- You received this

Re: Get sequence of values in arbitrarily nested collection

2010-12-06 Thread Benny Tsai
Nice! I knew there had to be a nicer way of traversing nested collections :) Thank you for this. On Dec 6, 8:30 am, Justin Kramer jkkra...@gmail.com wrote: tree-seq makes this pretty simple: (defn nested-vals [key coll]   (for [x (tree-seq coll? seq coll) :when (contains? x key)]     (get

Re: String-friendly first/rest?

2010-12-08 Thread Benny Tsai
(subs test 1) will work as well; the default behavior is to go to the end if no end position is specified. On Dec 8, 3:16 pm, Miki miki.teb...@gmail.com wrote: (.substring test 1 (count test)) bc FYI: Clojure has subs - (subs test 1 (count test)) -- You received this message because you

Re: Clojure 1.3 Alpha 4

2010-12-14 Thread Benny Tsai
As Brian said, primitive math is now the default in 1.3. If auto- promotion on overflow is desired, you can use the +', -', *', inc', dec' functions (note the single quote suffix). http://dev.clojure.org/display/doc/Enhanced+Primitive+Support On Dec 14, 5:36 pm, Brian Goslinga

Re: Clojure 1.3 Alpha 4

2010-12-14 Thread Benny Tsai
Of course, TANSTAAFL: the auto-promoting version of the functions will be slower than their primitive counterparts. On Dec 14, 6:23 pm, Benny Tsai benny.t...@gmail.com wrote: As Brian said, primitive math is now the default in 1.3.  If auto- promotion on overflow is desired, you can use

Re: currying in clojure for fixed number of arg functions

2010-12-18 Thread Benny Tsai
This is very cool! Taken together with the following projects, Clojure now has some of the nicest parts of Haskell/ML, IMHO :) Matchure (pattern matching): http://spin.atomicobject.com/2010/04/25/matchure-serious-clojure-pattern-matching Algebraic Data Types:

Re: replace first n items in sequence

2010-12-18 Thread Benny Tsai
-in and it sounded basic enough to be.  thanks! On Dec 18, 5:15 pm, Benny Tsai benny.t...@gmail.com wrote: I didn't see a built-in fn for this, and couldn't restrain myself from trying to write one: (defn replace-first-n [xs ys]   (let [n (count ys)]     (concat ys (drop n xs

Re: Working with maps and vectors

2010-12-21 Thread Benny Tsai
'filter' is for getting a subset of the elements in a collection. For getting the names of the provinces, what you want is to get all the keys from your 'provs' map, which can be done via the 'keys' function. user= (keys provs) (p1 p2 p3 p4) Personally, I find ClojureDocs' Quick Reference

Re: My first Clojure program: request for code review

2010-12-21 Thread Benny Tsai
Hi Marek, Here's my tweaked version: (ns karma (:use [clojure.contrib.duck-streams :only (read-lines)]) (:use [clojure.contrib.generic.functor :only (fmap)])) (def allowed-nickname [A-z]{1,16}) (def upvote-regexp (re-pattern (format (%s)\\+\\+ allowed- nickname))) (def downvote-regexp

Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Hi Marek, - To sort the nicks by karma in descending order, instead of sorting by the negation of the karma, I used (reverse (sort-by ...)); again, just a subjective thing, makes the intent more clear to me. It does, but doesn't that make it less lazy? To reverse something, it needs to

Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Hi Ken, user= (let [[x y more] [1 2 3 4 5]] [x y more]) [1 2 (3 4 5)] user= (let [[x y z] [1 2 3 4 5]] [x y z]) [1 2 3] user= (let [[_ _ a b] [1 2 3 4 5]] [a b]) [3 4] You can grab any fixed position in this way, as well as a rest that is the tail of the sequence past the last of such.

Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Just FYI, it's not applicable here but there is also rseq, which returns a reversed view on a collection in constant time. It only works on vectors and sorted maps, though. Good stuff, thank you Justin :) -- You received this message because you are subscribed to the Google Groups Clojure

Re: My first Clojure program: request for code review

2010-12-23 Thread Benny Tsai
Neat trick! Thanks David :) On Dec 22, 11:23 am, David Nolen dnolen.li...@gmail.com wrote: On Wed, Dec 22, 2010 at 1:22 PM, David Nolen dnolen.li...@gmail.com wrote: On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai benny.t...@gmail.com wrote: Hi Ken, user= (let [[x y more] [1 2 3 4 5]] [x

Re: My first Clojure program: request for code review

2010-12-23 Thread Benny Tsai
On Dec 22, 11:42 am, Ken Wesson kwess...@gmail.com wrote: I don't think Clojure has that. Closest is (let [[f rst] [1 2 3 4 5]       l (last rst)       m (butlast rst)]   [f m l]) Output is [1 (2 3 4) 5] Obviously, using the last element is non-lazy. It may well be that in cases where

Re: My first Clojure program: request for code review

2010-12-23 Thread Benny Tsai
Sure, that would be cool :) Sorry for the hijack, Marek! On Dec 23, 5:09 pm, Ken Wesson kwess...@gmail.com wrote: On Thu, Dec 23, 2010 at 7:08 PM, Benny Tsai benny.t...@gmail.com wrote: On Dec 22, 11:42 am, Ken Wesson kwess...@gmail.com wrote: I don't think Clojure has that. Closest

Re: My first Clojure program: request for code review

2011-01-05 Thread Benny Tsai
kwess...@gmail.com wrote: On Fri, Dec 24, 2010 at 12:06 AM, Benny Tsai benny.t...@gmail.com wrote: You're welcome. Sorry I couldn't be of greater help. If you want, I could throw together a quickie macro for grabbing a few items from either end of a seq. Sure, that would be cool :) OK, here

Re: What am I not getting here?

2011-01-06 Thread Benny Tsai
I was typing up an answer, but Jason answered faster and better :) The only thing I have to add is that 'frequencies' is also in clojure core as of 1.2. On Jan 6, 1:13 pm, Jason Wolfe ja...@w01fe.com wrote: You're not capturing the output of the reduce anywhere; doseq is for side-effects only.

Re: which IDEs are you all using?

2011-01-12 Thread Benny Tsai
Hi Mark, Could you elaborate on this part? On Jan 11, 8:40 pm, Mark Engelberg mark.engelb...@gmail.com wrote: well.  Lots of little things don't work quite right in emacs (at least on Windows), for example, dragging a file onto emacs to edit it, and copying and pasting between apps. I've

Re: which IDEs are you all using?

2011-01-12 Thread Benny Tsai
, 12 Jan 2011 17:38:00 To: clojure@googlegroups.com Reply-To: clojure@googlegroups.com Subject: Re: which IDEs are you all using? On Wed, Jan 12, 2011 at 8:13 AM, Benny Tsai benny.t...@gmail.com wrote: Hi Mark, Could you elaborate on this part? The version number is: GNU Emacs 23.1.1

Re: Question On Implicit Recursion

2011-01-13 Thread Benny Tsai
Armando's suggested change worked fine for me. (use '[clojure.contrib.lazy-seqs :only (primes)]) (defn prime-factors [n] (let [f (some #(if (= 0 (rem n %)) %) primes)] (println n: n , f: f) (if (= f n) (sorted-set f) (conj (prime-factors (/ n f)) f user= (prime-factors

Re: Question On Implicit Recursion

2011-01-13 Thread Benny Tsai
Good to know, thank you Ben :) On Jan 13, 10:49 am, B Smith-Mannschott bsmith.o...@gmail.com wrote: On Thu, Jan 13, 2011 at 17:36, Benny Tsai benny.t...@gmail.com wrote: (conj) will add items to different places in the collection, depending on the type of the collection.  For a set, this can

Re: Clojure regexs

2011-01-13 Thread Benny Tsai
For accessing groups in a match, you can use (re-matches). It will always give the full match as the first element though: user= (re-matches date-regex 2011 1 13) [2011 1 13 2011 1 13] So to replicate the Ruby code's behavior maybe you'll just want (rest (re-matches date-regex line)). For

Re: thinking parallel programming

2011-01-15 Thread Benny Tsai
In the Hacker News discussion about that talk, someone posted a link to another talk by Guy Steele on the same topic: http://vimeo.com/6624203 ... where he covers the material in somewhat greater depth (the downside being that by the 30-minute mark, I was struggling to keep up with the flow of

Re: Clojure Quizzes?

2011-01-16 Thread Benny Tsai
Hi Randy, You can access a seq of the command line args via the *command-line- args* var. On Jan 16, 3:03 pm, Randy J. Ray randy.j@gmail.com wrote: On 01/12/2011 11:50 PM, Robert McIntyre wrote: They seem to allow you to include anything in a lib directory that you'd want. I

Re: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
Combining Ken and David's tips, this version processes a byte-array of sizd 192 in about 13 milliseconds on my machine: (def buffer-size 192) (def array (byte-array buffer-size)) (defn java-like [^bytes cpuArray] (loop [i (int 0)] (if ( i buffer-size) (let [b (aget cpuArray

Re: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
McIntyre On Fri, Jan 28, 2011 at 1:07 PM, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 28, 2011 at 12:55 PM, Benny Tsai benny.t...@gmail.com wrote: It seems that 'unchecked-add' returns a primitive (note that in the first version, 'recur' happily accepts the return from 'unchecked

Re: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
Ah I see. Thank you Ken. On Jan 28, 11:07 am, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 28, 2011 at 12:55 PM, Benny Tsai benny.t...@gmail.com wrote: It seems that 'unchecked-add' returns a primitive (note that in the first version, 'recur' happily accepts the return from 'unchecked

Re: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
Hi Robert, Just out of curiosity, are you running Clojure with the -server option? When I run David's code, -server mode cuts the time for the first run by half, and the time for subsequent runs by a factor of 5. On Jan 28, 12:36 pm, Robert McIntyre r...@mit.edu wrote: David, thanks for your

Re: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
my JVM with: -verbose:gc -Xmn500M -Xms2000M -Xmx2000M -server sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 4:24 PM, Benny Tsai benny.t...@gmail.com wrote: Hi Robert, Just out of curiosity, are you running Clojure with the -server option?  When I run David's code, -server

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Benny Tsai
Nice! That version runs in 6 milliseconds on my machine, fastest of all the code posted so far. One more idea: use 'unchecked-inc' instead of 'unchecked-add'. This takes it under 3 milliseconds in my tests. (defn java-like [^bytes cpu_array] (let [buffer-size (int buffer-size)] (loop [i

Which branch of clojure-hadoop to use?

2011-02-04 Thread Benny Tsai
I have a bunch of older computers sitting at home, and thought I'd put them to use for experimenting with clojure-hadoop and swarmiji. However, I can't figure out which branch of clojure-hadoop to use. Stuart Sierra's branch looks like the canonical one, but hasn't been updated since March 2010.

Re: Which branch of clojure-hadoop to use?

2011-02-07 Thread Benny Tsai
to repository Benny Tsai  at Fri, 4 Feb 2011 20:59:00 -0800 (PST) wrote:  BT I have a bunch of older computers sitting at home, and thought I'd put  BT them to use for experimenting with clojure-hadoop and swarmiji.  BT However, I can't figure out which branch of clojure-hadoop to use.  BT Stuart

Re: Lazy seq from input

2011-02-07 Thread Benny Tsai
The blip.tv video of Tom Faulhaber's Lisp, Functional Programming, and the State of Flow talk from Clojure Conj showed me 'fill-queue', which seems like a good fit here. 'fill-queue' is a way to turn input from any source into a lazy sequence. You give it a one-arg function, 'filler-func', which

Re: Problems with lazy-xml

2011-02-11 Thread Benny Tsai
Can you post a link to a (sanitized, if need be) sample file? On Feb 11, 1:21 am, Marko Topolnik marko.topol...@gmail.com wrote: Right now I'm working with a 300k-record file, but the code must scale into the millions, and, as I mentioned, it is already spewing OutOfMemoy errors. Also, on a

Re: Problems with lazy-xml

2011-02-11 Thread Benny Tsai
I can confirm that the same thing is happening on my end as well. The XML is parsed lazily: user= (time (let [root (parse-trim (reader huge.xml))] (- root :content type))) Elapsed time: 45.57367 msecs clojure.lang.LazySeq ...but as soon as I try to do anything with the struct map for the

Re: Project Euler problem 28

2011-02-15 Thread Benny Tsai
My version follows the same algorithm (and so runs in the same amount of time), just arranged differently: (defn corner-nums [n] (for [i (range 4)] (- (* n n) (* i (dec n) (defn sum-all-corner-nums [max-n] (let [ns (range 3 (inc max-n) 2) all-corner-nums (mapcat corner-nums

Re: Euler 40

2011-02-16 Thread Benny Tsai
Hi Marek, I think the (inc) in (decimal-fraction-digits) and the (dec) in (solution) cancel each other out, so the two functions can be simplified a bit to: (defn decimal-fraction-digits [] Returns the lazy sequence of digits in irrational fraction created by concatenating the positive

Re: Transforming map entries

2011-02-22 Thread Benny Tsai
There is fmap from clojure.contrib.generic.functor, which expects a function of arity 1, for just the value: (use 'clojure.contrib.generic.functor) (require '[clojure.string :as str]) (def my-map {:first john :last smith :age 25}) (defn my-fn [value] (if (string? value) (str/upper-case

Re: Transforming map entries

2011-02-22 Thread Benny Tsai
by the OP.  I had never heard of that one. On Tue, Feb 22, 2011 at 6:56 PM, Benny Tsai benny.t...@gmail.com wrote: There is fmap from clojure.contrib.generic.functor, which expects a function of arity 1, for just the value: (use 'clojure.contrib.generic.functor) (require

Re: Transforming map entries

2011-02-23 Thread Benny Tsai
could use remove-method and then write my own fmap implementation for IPersistentMap.  I'm curious about the design, though. Thanks, Chris On Tue, Feb 22, 2011 at 6:56 PM, Benny Tsai benny.t...@gmail.com wrote: There is fmap from clojure.contrib.generic.functor, which expects

Re: Transforming map entries

2011-02-23 Thread Benny Tsai
That is true. Thank you for the reminder. On Feb 23, 10:18 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2011/2/23 Benny Tsai benny.t...@gmail.com My guess is that Clojure's fmap behaves that way because it is modeled Note that it's not Clojure's fmap. fmap is a function in a clojure

Re: Loading clojure code during runtime

2011-03-11 Thread Benny Tsai
(read-string) converts a string into a Clojure object, which can then be (eval)ed: (let [f (eval (read-string (fn [x] (* x 2] (map f [1 2 3])) user= (2 4 6) So you could do something like: (let [f (eval (read-string (slurp function.txt)))] (map f [1 2 3])) -- You received this

Re: Good choices for a NoSQL database with Clojure?

2011-03-26 Thread Benny Tsai
A Clojure wrapper for neo4j was recently posted: https://github.com/wagjo/borneo There's also Jiraph, another embedded graph database for Clojure: https://github.com/ninjudd/jiraph -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group,

Re: Can I add the contents of seq to a collection without wrapping?

2011-03-28 Thread Benny Tsai
concat should do the trick: (defn load-sources [ sources] (dosync (alter source-queue concat sources))) -- 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

(memoize) and recursive functions (Clojure 1.2)

2011-03-28 Thread Benny Tsai
I was playing with memoize when I ran into some puzzling behavior. A test case: (defn f [n] (println f called with n) (if (zero? n) 0 (min (f (dec n)) (f (dec n) (def f (memoize f)) *The usage of def to rebind a function to its memoized version is taken from

Re: (memoize) and recursive functions (Clojure 1.2)

2011-03-29 Thread Benny Tsai
Andreas, Mark, thank you for your suggestions. Both worked splendidly. Just out of curiosity, does memoize in 1.3 behave like the current 1.2 version or the 1.1 version? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

Re: (memoize) and recursive functions (Clojure 1.2)

2011-03-29 Thread Benny Tsai
Fantastic! Thank you Sean. On Tuesday, March 29, 2011 11:37:06 AM UTC-6, Sean Corfield wrote: On Tue, Mar 29, 2011 at 8:31 AM, Benny Tsai benny...@gmail.com wrote: Just out of curiosity, does memoize in 1.3 behave like the current 1.2 version or the 1.1 version? user= (clojure-version

Re: clj3D, a Clojure 3D Library

2011-04-06 Thread Benny Tsai
Works for me (Chrome 10.0.648.204, Windows XP SP3). -- 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.

Re: clj3D, a Clojure 3D Library

2011-04-06 Thread Benny Tsai
Agreed! I installed Shazam just to learn more about this song. It's Blue Train, by John Coltrane. -- 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

Re: Clojure example code snippets

2011-05-19 Thread Benny Tsai
I think there can be multiple words on each line, so they have to be split into words first. Maybe something like: (ns example (:use [clojure.contrib.duck-streams :only (read-lines)])) (let [lines (read-lines file.txt) words (mapcat #(.split % \\s) lines) ing-words (filter

Re: Aw: Clojure example code snippets

2011-05-19 Thread Benny Tsai
I think line-seq needs a java.io.BufferedReader instead of a java.io.FileReader. clojure.java.io has a reader function that constructs a java.io.BufferedReader from a filename, so this worked for me: (ns example (:use [clojure.java.io :only (reader)])) (with-open [rdr (reader file.txt)]

Re: Aw: Clojure example code snippets

2011-05-19 Thread Benny Tsai
Oops. Just noticed that the original was not quoted in either of my previous emails, which makes things really confusing. My first reply (the one using read-lines) was an extension of odyssomay/Jonathan's code, and the second (with reader) was an extension of Meikel's code. Sorry guys. --

Re: Radically simplified Emacs and SLIME setup

2011-05-21 Thread Benny Tsai
You can grab it here: https://github.com/technomancy/clojure-mode On Saturday, May 21, 2011 6:41:18 PM UTC-6, Tom Hicks wrote: Where does one get clojure-mode 1.9.1? The latest I see on github is 1.7.1. On May 20, 4:06 pm, Phil Hagelberg p@hagelb.org wrote: On May 19, 11:15 pm,

Re: New to Clojure

2011-06-07 Thread Benny Tsai
Mark Volkmann's Clojure introduction ( http://java.ociweb.com/mark/clojure/article.html) helped me out a great deal when I first started. As he noted at the end, the article focused on Clojure 1.0 features, so some parts are superceded (records are recommended over StructMaps now, for

  1   2   >