Re: is PG's imperative outside-in advice any good?

2013-10-17 Thread Benny Tsai
For those who use clojure.tools.logging, there's also the handy spy 
function.

On Tuesday, October 15, 2013 6:41:38 PM UTC-7, dgrnbrg wrote:

 If this is something you do often, spyscope is a library I wrote to 
 simplify this sort of investigation. You can print an expression by writing 
 #spy/d in front of it. For more information, you can read at 
 https://github.com/dgrnbrg/spyscope

 On Tuesday, October 15, 2013 10:13:58 AM UTC-4, Brian Hurt wrote:

 Lifting subexpressions up into lets is actually something I do a lot- for 
 one very important reason: it lets me insert print statements (or logging 
 statements) showing the value of the subexpression.  So I'll do;
 (let [ x (subexpression) ]
 (main-expression))

 because it lets me do:
 (let [ x (subexpression) ]
 (println The value of x is x)
 (main-expression))

 If fact, a lot of times I'll do;
 (let [ x (subexpression)
 res (main-expression) ]
 res)

 because it lets me do:
 (let [ x (subexpression)
 _ (println The value of x is x)
 res (main-expression) ]
 (println The value of the whole expression is res)
 res)

 This is of great value in debugging.

 Brian



 On Tue, Oct 15, 2013 at 9:56 AM, Mikera mike.r.an...@gmail.com wrote:

 I certainly prefer giving names to intermediate results with a let 
 block: having good names and breaking the computation up into logical 
 chunks makes the code much easier to understand and maintain when you come 
 back to it later.

 PG's example though is bad for different reasons - this is actually 
 mutating variables in an imperative style, which is definitely bad style 
 - both in Lisp and Clojure I think. The Clojure equivalent would be to use 
 atoms (or vars) and mutating them.

 let on its own is purely functional, and doesn't have this problem.


 On Tuesday, 15 October 2013 20:29:29 UTC+8, Daniel Higginbotham wrote:

 I've been going through On Lisp by Paul Graham and on page 33 he 
 recommends against performing intermediate bindings. Does this advice 
 hold for Clojure? Here are a couple examples: 

 ;; Common Lisp (from the book) 
 (defun bad (x) 
  (let (y sqr) 
(setq y (car x)) 
(setq sqr (expt y 2)) 
(list 'a sqr))) 

 (defun good (x) 
  (list 'a (expt (car x) 2))) 

 ;; Clojure 
 (defn bad [x] 
  (let [y (first x) 
sqr (expt y 2)] 
(list 'a sqr))) 

 (defn good [x] 
  (list 'a (expt (first x) 2))) 

 Paul Graham explains: 

 The final result is shorter than what we began with, and easier to 
 understand. In the original code, we’re faced with the final expression 
 (list 'a sqr), and it’s not immediately clear where the value of sqr comes 
 from. Now the source of the return value is laid out for us like a road 
 map. 

 The example in this section was a short one, but the technique scales 
 up. Indeed, it becomes more valuable as it is applied to larger 
 functions. 

 In clojure you can't do setq of course but I find myself going against 
 this advice all the time, and I find that it's more important to do so 
 when 
 working with larger functions. I think introducing names makes code 
 clearer. Here's an example from my own code: 

 (defn create-topic 
  [params] 
  (let [params (merge params (db/tempids :topic-id :post-id :watch-id)) 
topic (remove-nils-from-map (c/mapify params mr/topic-txdata)) 
watch (c/mapify params mr/watch-txdata) 
post (c/mapify params mr/post-txdata)] 
{:result (db/t [topic post watch]) 
 :tempid (:topic-id params)})) 

 To my mind, creating bindings for topic, watch, and post makes 
 the code easier to understand. When you get to (db/t [topic post watch]) 
 you don't have to deal with as much visual noise to understand exactly 
 what's going into the transaction. 

 So, is PG's advice any good? 

 Thanks! 
 Daniel

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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: Do you like the Clojure syntax?

2013-08-14 Thread Benny Tsai
On Wednesday, August 14, 2013 10:14:24 AM UTC-7, Rick Moynihan wrote:

 Subjectively I found Erlang's syntax pretty horrible (though I like the 
 language itself), Ruby's is superficially beautiful but in practice 
 ambiguous and not without its warts...


Have you had a chance to check out Elixir (http://elixir-lang.org/)?  It's 
a language with Ruby-inspired syntax (plus goodies like Clojure-style 
protocols and true macros) running on the Erlang VM. 

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Benny Tsai
Does db-transaction work in your case?

Evaluates body in the context of a transaction on the specified database 
connection.

The binding provides the database connection for the transaction and the name 
to which
that is bound for evaluation of the body.
See db-transaction* for more details.

Given a spec, you can use db-transaction like this:

(db-transaction [t-db spec]

  (insert! t-db ...)

  (update! t-db ...)

  ...)


On Wednesday, August 14, 2013 8:02:52 PM UTC-7, Kyle Cordes wrote:

 Hello. I've coded quite a lot of JDBC usage in Java, and enough Clojure to 
 know my way around pretty well; yet I've been unable to figure out the 
 following by reading the source and docs for clojure.java.jdbc. I've read 
 http://clojure.github.io/java.jdbc/ and many pages linked from there.

 The question is:

 How do I get a connection, then run a series of operations on that same 
 connection? All the API I can find (except for the deprecated, pre-0.3 API) 
 seems to work on a model of: give it a DB connection spec, it connects, 
 runs, and disconnects. Great for playing with a command at a time, less so 
 for doing a series of things that need to happen on the same connection.

 -- 
 Kyle Cordes
 http://kylecordes.com



-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: so why it has to be so complicated / Longest Increasing Sub-Seq

2012-06-12 Thread Benny Tsai
This is what I ended up with, which I think is relatively clear and 
straightforward (but then, I'm not entirely unbiased :)

The algorithm is very close to what you described.

- Generate all sub-sequences of length  1
- Filter to keep only increasing subsequences
- Tack on the empty sequence, which is what needs to be returned if there 
are no increasing sub-sequences
- Sort by length in descending order
- Take the first (longest)

(fn [coll]
   (let [increasing? (fn [xs] (apply  xs))
 n (count coll)
 sub-seqs (mapcat #(partition % 1 coll) (range 2 (inc n)))]
 (- sub-seqs
  (filter increasing?)
  (cons [])
  (sort-by count )
  first)))

On Tuesday, June 12, 2012 12:11:07 PM UTC-7, Andy C wrote:

 Hi, 

 First a quick disclaimer. Those are my first steps in Clojure so I am 
 not be super accustomed to the language entire landscape and might 
 miss some basics here. However I was able to solve my first 4clojure 
 hard problem https://www.4clojure.com/problem/53 and have some second 
 thoughts after looking up top contributor's solutions as well as mine. 
 Why it has to be so complicated??? 

 Conceptually, you just reduce the list to list of lists using a simple 
 condition  . Then you filter items longer then 1. And at the same 
 time you reduce the output to a first longest list. In this case, 
 stack for recursion is really not required, although I did use it in 
 my solution since I could figure out the reduction based way to 
 partition the source sequence. 

 It also seems that imperative solution would be quite straightforward 
 although maintaining at least 4 state variables is not compelling at 
 all. Bottom line, I want to have a idiomatic Clojure solution ... Any 
 insight  

 Thx, 
 Andy 


-- 
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: Clojure and the Anti-If Campaign

2012-05-29 Thread Benny Tsai
There's while in clojure.core; would that work?

On Tuesday, May 29, 2012 8:13:24 AM UTC-7, Andrew wrote:

 Thanks for sharing your blog post. Is there an Anti-If alternative to 
 loop/recur in a situation where you have to poll for a condition to be 
 true? (Seems to me that this necessitates some kind of conditional 
 statement)

 On Thursday, May 24, 2012 5:57:47 AM UTC-4, Dominikus wrote:

 Three weeks ago I stumbled across the Anti-If Campaign (
 http://www.antiifcampaign.com/).

 An instant later I realized that one could easily re-implement if in 
 Clojure with maps. More interestingly, polymorphic functions can be easily 
 motivated with the help of maps. And this naturally leads to multimethods.

 If you like, enjoy reading my blogpost on The root of polymorphism: The 
 Anti-If Campaign. It might be an interesting read for Clojure enthusiasts.


 http://denkspuren.blogspot.de/2012/05/root-of-polymorphism-anti-if-campaign.html
  

 Cheers,

 Dominikus




-- 
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: Dealing with dynamic header in log file processing

2012-04-14 Thread Benny Tsai
Hi Cliff,

There are at least 2 approaches you can try:

1. Use an atom to store the fields data, updating it whenever you encounter 
a #Fields row, and referencing it when processing data rows.

2. Use (reduce) to process the rows, using the accumulator to store both 
the current count and fields data.  Something like this:

(reduce (fn [{:keys [count fields] :as acc} row]
  ;; the above de-structuring makes current count and fields 
available
  (cond
   ;; if it's a fields row...
   (fields-row? row) (let [new-fields :compute-new-fields-here]
   (assoc acc :fields new-fields))
   ;; if it's a data row...
   (data-row? row) (let [new-count :compute-new-count-here]
 (assoc acc :count new-count
{:count 0 :fields []}
rows)

I think both approaches are equally valid, it's just a matter of which one 
appeals to you more.  Hope this helps!

On Thursday, April 12, 2012 9:38:31 AM UTC-7, Cliff Mosley wrote:

 Prefacing this with being a complete Clojure novice, my question is more 
 about approach than the actual code required. Like many, I have a few tried 
 and true examples that I like to work through in each language. In my case, 
 I have a set of IIS log files that I want to generate usage statistics on. 
 The hitch in my particular problem is that the log files may or may not 
 have columns redefined within the file.

 As an example 
 #Software: Microsoft Internet Information Services 6.0
 #Version: 1.0
 #Date: 2011-05-02 17:42:15
 #Software: Microsoft Internet Information Services 6.0
 #Version: 1.0
 #Date: 2011-05-02 17:42:15
 #Fields: date time c-ip cs-username s-ip s-port cs-method cs-uri-stem 
 cs-uri-query sc-status cs(User-Agent)
 2011-05-02 17:42:15 172.22.255.255 - 172.30.255.255 80 GET 
 /images/picture2.jpg - 200 
 Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
 2011-05-02 17:43:15 172.22.255.255 - 172.30.255.255 80 GET 
 /images/picture1.jpg - 200 
 Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
 .
 .
 many more lines
 .
 .
 #Same file, s-ip is now removed so ordinal positions are changed
 #Fields: date time c-ip cs-username s-port cs-method cs-uri-stem 
 cs-uri-query sc-status cs(User-Agent)
 2011-05-02 17:48:15 172.22.255.255 - 80 GET /images/picture1.jpg - 200 
 Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)
 2011-05-02 17:49:15 172.22.255.255 - 80 GET /images/picture3.jpg - 200 
 Mozilla/4.0+(compatible;MSIE+5.5;+Windows+2000+Server)

 So with the above data, I am trying to get the count of log file hits from 
 a given cs(User-Agent). In other languages, I would just read in the 
 #Fields row and continue processing merrily given the most recent order I 
 encountered moving through the file sequentially. With Clojure, the 
 immutability of the fields is throwing a wrench for me.

 If anyone could give me a nudge in the right direction, I would appreciate 
 it.
 Cliff



-- 
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: beginner - stuck in dependencies and possibly old versions

2012-03-22 Thread Benny Tsai
Hi Ted,

To answer your last question first, each project.clj determines the clojure 
version used by that project, so you don't really have to worry about old 
versions interfering or anything.

I'm running Lein 1.6.2, which is relatively old, and it defaults new 
project to 1.3.  If yours is using 1.2.1 as the default for new projects, I 
suspect it may be even more outdated, which may be the cause of your 
troubles.  What is the output if you run lein version, and what OS are 
you running on?

On Wednesday, March 21, 2012 3:41:58 AM UTC-7, ted wrote:

 Hi all,
 I am very much a beginner with Clojure and have no experience with Java so 
 please be gentle with me.
 I've been playing around with numerous incarnations of Lisp but would like 
 to settle on Clojure, however I cannot get my environment sorted.
 I've installed Leiningen but when I try to do lein plugin install 
 swank-clojure 1.3.1 or lein plugin install lein-oneoff 0.2.0 I get 
 [INFO] unable to find resource 'swank-clojure:swank-clojure:​jar:1.3.1' in 
 repository central (http://repo1.maven.org/maven2​) (or equivalent for 
 lein-oneoff)
 I'm sure it is something simple but I have no idea where to look and feel 
 like I'm stuck at the first hurdle. Anybody any idea?
 I think Leiningen is installed correctly as I can create new projects. I 
 did notice however that the project.clj file as a default refers to clojure 
 1.2.1 as opposed to clojure 1.3.0. It is very likely that I have old 
 versions of Clojure floating around on my machine as I've played around 
 with Clojure in the past. (I'd like to get rid of the old versions but not 
 sure in which directory(/ies) they have been installed
 Please let me know if I need to provide more info.
 Thanks in advance
 Ted


-- 
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: Print only by clojure code

2012-02-08 Thread Benny Tsai
Piggy-backing off Mark's answer, if it is log4j that's being used, you can 
also use log4j.properties to set different logging levels for your Java 
code vs. your Clojure code (assuming the code are in different packages):

http://stackoverflow.com/questions/3569395/filtering-out-log4j-messages-from-third-party-frameworks

On Wednesday, February 8, 2012 11:40:45 AM UTC-8, Mark Rathwell wrote:

 It's logging, and assuming the logging implementation it is using
 log4j, you can specify the logging properties in a properties file, as
 system properties, or set the properties in code.  The easiest way is
 to place a file called log4j.properties on the classpath (in the
 resources directory of your project) containing the following:

 # set root logger level to OFF (OFF, FATAL, ERROR, WARN, INFO, DEBUG,
 TRACE, ALL)
 log4j.rootLogger=OFF


 On Wed, Feb 8, 2012 at 1:49 PM, Simone Mosciatti mweb@gmail.com 
 wrote:
  Hi guys,
 
  I have developed a very very little application in clojure that use an
  external lib in java that i prefer do not touch.
 
  The problem is that this lib for some weird reason (debug i guess)
  print at video a bunch of information useless for me, there is any way
  to avoid this problem, i mean can i just print what the clojure code
  actually print and not what also the lib in java print ?
 
  I'm sorry for my English...
 
  --
  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: How to start using clojureCLR?

2011-12-29 Thread Benny Tsai
Hi Erlis,

This is the most recent blog entry I've found w.r.t. getting up and running 
with Clojure CLR:

http://www.myclojureadventure.com/2011/10/getting-started-with-clojure-clr.html

What I really like about this particular blog is that the author has also 
written follow-up articles (in Nov. and Dec. of 2011) on how to do things 
like talk to SQL Server from Clojure CLR and how to call into Clojure CLR 
from C#.  Hope this helps!

On Tuesday, December 27, 2011 9:59:09 AM UTC-8, Erlis Vidal wrote:

 Hi group, 

 I just joined the group and I'm really hypnotized with the Clojure 
 language. Most of the time in my day job I do .Net development but outside 
 of the job I'm always trying to learn and apply other languages and 
 technologies. The curse of the mainstream. 

 I've just finished Stuart's book  Programming Clojure and I would like 
 to start introducing some fun in my day to day programming, and when I saw 
 ClojureCLR I was really happy. 

 The point is that I don't know where to start, I haven't found anything 
 that explain how to start working with it. Any blog on how to prepare the 
 environment and start using introducing clojure on my .Net projects ? 

 I'm also curious about ClojureScript, I've been looking CoffeeScript and 
 there are some tools that even integrate with Visual Studio allowing to 
 generate the JavaScript file associate with the CoffeeScript, is there 
 anything like that for ClojureScript? Is it recommended to use 
 ClojureScript in the same scenarios as CoffeeScript or they should serve 
 different purposes? 

 I probably should have two questions, but I see so many opportunities to 
 use Clojure right now that I don't want to miss anything. 

 Thanks in advance and let me know where can I find some information, even 
 if you feel is irrelevant maybe for me is a gold mine. 
 Erlis 


-- 
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: How to start using clojureCLR?

2011-12-29 Thread Benny Tsai
For VS integration, there is the following plugin.  I haven't used it 
myself, so can't offer much help beyond this.  Good luck!

http://visualstudiogallery.msdn.microsoft.com/fb895809-2ae0-48aa-8a96-3c0d5b8e1fdc/

On Thursday, December 29, 2011 11:17:28 AM UTC-8, Erlis Vidal wrote:

 Hi!

 Thanks for the link. I really appreciate it.

 It looks like the CLR project is really in it first stage. Is someone 
 working on the tools? Any plans to integrate it with VS? 

 thanks! and thanks for the CLR version!

 On Thu, Dec 29, 2011 at 2:04 PM, Benny Tsai benny...@gmail.com wrote:

 Hi Erlis,

 This is the most recent blog entry I've found w.r.t. getting up and 
 running with Clojure CLR:


 http://www.myclojureadventure.com/2011/10/getting-started-with-clojure-clr.html

 What I really like about this particular blog is that the author has also 
 written follow-up articles (in Nov. and Dec. of 2011) on how to do things 
 like talk to SQL Server from Clojure CLR and how to call into Clojure CLR 
 from C#.  Hope this helps!


 On Tuesday, December 27, 2011 9:59:09 AM UTC-8, Erlis Vidal wrote:

 Hi group, 

 I just joined the group and I'm really hypnotized with the Clojure 
 language. Most of the time in my day job I do .Net development but outside 
 of the job I'm always trying to learn and apply other languages and 
 technologies. The curse of the mainstream. 

 I've just finished Stuart's book  Programming Clojure and I would like 
 to start introducing some fun in my day to day programming, and when I saw 
 ClojureCLR I was really happy. 

 The point is that I don't know where to start, I haven't found anything 
 that explain how to start working with it. Any blog on how to prepare the 
 environment and start using introducing clojure on my .Net projects ? 

 I'm also curious about ClojureScript, I've been looking CoffeeScript and 
 there are some tools that even integrate with Visual Studio allowing to 
 generate the JavaScript file associate with the CoffeeScript, is there 
 anything like that for ClojureScript? Is it recommended to use 
 ClojureScript in the same scenarios as CoffeeScript or they should serve 
 different purposes? 

 I probably should have two questions, but I see so many opportunities to 
 use Clojure right now that I don't want to miss anything. 

 Thanks in advance and let me know where can I find some information, 
 even if you feel is irrelevant maybe for me is a gold mine. 
 Erlis 

  -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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

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

user= (f [:a])
a
user= (f [:b 1])
1
user= (f [:c])
problem!

I'm using Clojure 1.3 and core.match 0.2.0-alpha8.

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

 user= (f [:a])
 a
 user= (f [:b 1])
 1
 user= (f [:c])
 problem!

 I'm using Clojure 1.3 and core.match 0.2.0-alpha8.
  
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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: 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 respective efforts, I see a lot of room for improvement in 
mine :)  I like how your actors send messages containing the address of the 
recipient, which seems truer to the actor model.  Also, you raise a great 
point regarding pattern matching; I think that can greatly simplify the 
message handlers in my code.  Looks like it's time for me to get acquainted 
with core.match :)

Thanks for the food for thought!

*https://github.com/bitsai/clojure-actors

On Friday, December 2, 2011 1:17:43 PM UTC-7, Nils Bertschinger wrote:

 Hi,

 how do Clojure agents relate to Erlang actors?
 To gain some insights, I tried to implement Erlang style message
 passing between agents. The first version is just a very incomplete
 sketch (no mailbox, case instead of pattern matching ...), but already
 shows that it is quite easily doable:
 https://github.com/bertschi/clojure-stuff/blob/master/src/stuff/actors.clj

 The idea is that the agent holds a dispatch function which is then
 called by ! (send) with the message to be send. Somehow it resembles
 the way closures can be used to implement an object system. Thus,
 agents seem to be the functional analog of agents:
 Functional programming Object-oriented
 programming
 sequential  closure
 object
 concurrent   agent
 actors

 Another great design from Rich Hickey! Clojure is fun and gets better
 every day ...

 Thanks,

 Nils



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

 I am currently considering an approach similar to the following for
 periodically sending an update to an agent and I'm looking for
 feedback on whether there is anything wrong with it, whether it's
 idiomatic clojure (sorry I'm in the pro-that-term camp) and whether
 there are other pure-clojure alternatives I should consider (I also
 realize there are java-based periodic timers I could use as well):

 (def *timer* (agent nil)) ; perhaps an atom instead?
 (defn start-timer [ms a f]
 (letfn [(tfn [m] (future (do (Thread/sleep ms) (send a f) (send
 *timer* tfn]
 (send *timer* tfn)))

 given an agent:
 (def data (agent 0))

 we could kick off an update every 3 seconds thusly:
 (start-timer 3000 data #(inc %))

 A real implementation would likely have to address further
 considerations like stopping/cancelling the timer, not using a global
 for the timer, and what happens if start-timer is called twice, but
 this is the basic idea I'm considering...

 feedback welcome,

 thanks,
 bill



-- 
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: 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 - 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: 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) x))) (take (count a1) 
 (repeat a1))) 
 ([a] [a b] [a b c] [a b c d]) 


-- 
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: 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 intermediate results)
 On Nov 9, 2011 5:57 PM, Linus Ericsson oscarlinu...@gmail.com wrote:

 (map #(vec (take (inc %) a1)) (range (count a1)))

 does it the lovely map.

 /Linus

 2011/11/9 Shoeb Bhinderwala shoeb.bh...@gmail.com

 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) x))) (take (count a1)
 (repeat a1)))
 ([a] [a b] [a b c] [a b c d])

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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 clo...@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+u...@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: 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 #()
 bounds-check #()
 contact #()
 full-test (fn [element] (and (type-pred element) (bounds-check
 element) (contact element)))]
   (filter full-test (:game-elements @world-atom))

 is there a way to write the full-test in a way that doesn't force me
 to repeat the function constant text pattern inside the and?


 -BEGIN PGP SIGNATURE-
 Version: GnuPG v2.0.14 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

 iQIcBAEBAgAGBQJOtBgfAAoJENRtux+h35aGDTAP/RM2mXcu7+HlH0gVHPcZ2bH0
 31MEGk5ysup06vgntmxOClaNV9PcxQ1g3bu44YTWDKy3S5RWiD+yB+LkAV0e8xvM
 p8A64giicfaxI2qncmEpgjodrUn8Yg4vde9X5pQRRaQaWTG56jlLUClorOy62W2q
 gsvNaehEZa6MZiG6yQOEQ1j0sS438bkmCsqxmHAs2ZmAkb9osTatKECK4sAZRx6l
 31KHRFEWx8piiND5vxUGeqlf/CHC3r9VCgBc86q/nnH2CL4cofrkv6mXUYxHikPS
 AVbT8Qtuonh+twoGLH6t+TYCrVIgiAmnO9IOWFqpdkcX+us3V+ETvXSAVfuf6mCM
 +pS3Ps0+VndU31/ufZ0pdki/DxlMJiMVPSS1l/Z76671rCQe+dBjFDSU4e+4y9du
 sj0h1VNQ/tKzQ0jCGb9AF6MHoy51b4dpaqjwuJ4HQscH3L9ruG46dTZs5+IvWb5v
 2htp5jQNY25e05qbT2tjPVTKT7C6kZ5S3dMlAfQnQxIaHrIm92IHzq3bhF3xMbgy
 Yh5sC66y/O4BPZnCvcKY6RF6wBlSZ/vLVOYAasvV89bWanUvv5vgFlNWysNoNF0o
 eCFhm1NQmvDoqTa0okx3kN5LeoVgGZdfmkEcVNIvVNUFYzht6ffGNaESb3YWFMlO
 buElt55CDSzWlvkBwqPU
 =A6jg
 -END PGP SIGNATURE-



-- 
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: 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 d.ha...@googlemail.com wrote: 
(let [type-pred #() 
  bounds-check #() 
  contact #() 
  full-test (fn [element] (and (type-pred element) (bounds-check 
  element) (contact element)))] 
(filter full-test (:game-elements @world-atom)) 
  
  is there a way to write the full-test in a way that doesn't force me 
  to repeat the function constant text pattern inside the and? 


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

2011-11-02 Thread Benny Tsai
Quite right.  Thank you for the reminder.

On Wednesday, November 2, 2011 2:51:06 AM UTC-6, Alan Malloy wrote:

 The call to (set day-nums) should really be pulled out of the inner 
 function to avoid rebuilding the set over and over: 

 (defn day-of-week-stream [ day-nums] 
   (let [day-set (set 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 
 this 
   maybe? 
  
   (defn day-of-week-stream [ day-nums] 
 (filter #((set day-nums) (.. % dayOfWeek get)) 
 (today+all-future-dates))) 
  
  This one is a good solution. No need to interleave two streams when 
  you can generate one directly. 
  
  Regards, 
  BG 
  
  -- 
  Baishampayan Ghose 
  b.ghose at gmail.com

-- 
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: 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 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: 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 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: 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 4}})

I wanted to use clojure.walk to do this, but couldn't figure out how, so 
this is what I ended up with instead.  'excluded' should be a set of keys 
you want to exclude on the walk.

(defn walk-tree
  [tree excluded]
  (let [f (fn f [m path]
(apply concat (for [[k v] m]
(cond
 (excluded k) nil
 (map? v) (f v (conj path k))
 :else (list (conj path k))]
(f tree [])))

user= (walk-tree tree #{:_meta})
([:parent1 :relationship1 :child1] [:parent1 :relationship1 :child2] 
[:parent1 :relationship2 :child3])

Note that if a path ends with an empty map, that path will not be printed. 
 Don't know if this is acceptable or not.

(def tree2 {:parent1
{:relationship1
 {:child1 {}
  :child2 2}
 :relationship2
 {:child3 3}
 :_meta 4}})

user= (walk-tree tree2 #{:_meta})
([:parent1 :relationship1 :child2] [:parent1 :relationship2 :child3])

-- 
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: 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 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: 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 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: 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 still be worth it to pay the cost of 
vectorizing the set once in exchange for faster subsequent random 
selections.  But if not, then I guess not so much.

-- 
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: 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 UTC-6, melipone wrote:

 I do like lein repl on the command line. How can I have that in emacs? 
 Basically, if I have a project in Lein, how can I do a (require 
 'projectname) and have all the libraries loaded in emacs? 
 I'm just using M-x inferior-lisp at this point. I find swank-clojure too 
 complex for right now. Maybe later. 

 TIA
 melipone

-- 
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: clojure and emacs

2011-09-03 Thread Benny Tsai
Sorry, what I meant to say in the last line is:

And as long as you start emacs somewhere in your lein project directory (or 
M-x cd to it), you'll automatically be dropped into the main namespace (if 
you have one defined via :main in project.clj), and the other project 
namespaces 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 cd to it), you'll have all the libraries loaded in your REPL buffer.

 On Thursday, September 1, 2011 11:03:13 AM UTC-6, melipone wrote:

 I do like lein repl on the command line. How can I have that in emacs? 
 Basically, if I have a project in Lein, how can I do a (require 
 'projectname) and have all the libraries loaded in emacs? 
 I'm just using M-x inferior-lisp at this point. I find swank-clojure too 
 complex for right now. Maybe later. 

 TIA
 melipone



-- 
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: 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 f [0]) (lazy-mapcat identity) (take 1))
(0)
user= (defn g [x y]
(println computing x + y: (+ x y))
[(+ x y)])
#'user/g
user= (take 1 (mapcat g (range) (range)))
computing x + y: 0
computing x + y: 2
computing x + y: 4
computing x + y: 6
(0)
user= (take 1 (lazy-mapcat g (range) (range)))
(computing x + y: 0
0)

-- 
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: 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 neighbors))]
(recur new-visited
   new-queue)

-- 
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: 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 been fixed and ClojureScript 
 now has batch files for cljsc, repl, and repljs. There is also a page 
 in the wiki to help Windows users get started. 

 https://github.com/clojure/clojurescript/wiki/Windows-Setup 

 Support for Windows will come from the community so if you care about 
 this then please do pitch in and help. 


-- 
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: 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: 
 https://groups.google.com/d/topic/clojure/ZyVrCxmOFTM/discussion

 I've also filed a bug here: http://dev.clojure.org/jira/browse/CLJS-43

 Sorry. :)

 On Thursday, July 28, 2011 6:40:39 PM UTC-5, Rich Hickey wrote:

 Could you please use quoting in your messages? Otherwise they have no  
 context.

 Thanks,

 Rich

 On Jul 28, 2011, at 7:10 PM, Anthony Grimes wrote:

  Actually, it seems to be caused by this commit: 
 https://github.com/clojure/clojurescript/commit/954e8529b1ec814f40af77d6035f90e93a9126ea
 
  If I checkout before that, everything is peachy. I guess I'll submit  
  a bug report.
 



-- 
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: 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 here as well. 
 Hope this helps.

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

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, when I tried to run the resulting .js 
file using Node, I got the following error:

node.js:195
throw e; // process.nextTick error, or 'error' event on first tick
  ^
GetConsoleTitleW: The access code is invalid.
TypeError: Cannot read property 'prototype' of undefined
at Object.anonymous (C:\clojurescript\nodehello.js:14:382)
at Module._compile (module.js:420:26)
at Object..js (module.js:459:10)
at Module.load (module.js:335:31)
at Function._load (module.js:294:12)
at Array.anonymous (module.js:479:10)
at EventEmitter._tickCallback (node.js:187:26)

The same error was encountered with both the 0.5.2 and 0.5.1 Windows 
binaries from http://nodejs.org/dist/.  A similar error was thrown when I 
tried the 0.4.9 and 0.4.8 binaries from http://node-js.prcn.co.cc/:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
WideCharToMultiByte: The data area passed to a system call is too small.
TypeError: Cannot read property 'prototype' of undefined
at Object.anonymous (/cygdrive/c/clojurescript/nodehello.js:14:382)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.anonymous (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)

Has anyone had success using ClojureScript with Node.js, either on Windows 
or otherwise?

-- 
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: 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 would be any more stable? :(

 Thank you for replying, Sean :)  It's probably time for me to go back to 
Ubuntu as my development environment and save myself some pain...

-- 
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: 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 
instructions at https://github.com/joyent/node/wiki/Installation 
and building Node 0.4.11-pre from source.  Perhaps that might work for you 
as well?

If anyone else has experienced this problem, please feel free to chime 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 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

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, or 'error' event on first tick
  ^
GetConsoleTitleW: The access code is invalid.
TypeError: Cannot read property 'prototype' of undefined
at Object.anonymous (C:\clojurescript\nodehello.js:13:382)
at Module._compile (module.js:420:26)
at Object..js (module.js:459:10)
at Module.load (module.js:335:31)
at Function._load (module.js:294:12)
at Array.anonymous (module.js:479:10)
at EventEmitter._tickCallback (node.js:187:26)

I get that error with both 0.5.2 and 0.5.1 binaries from nodejs.org/dist/, 
and a similar error with the 0.4.9 and 0.4.8 binaries 
from node-js.prcn.co.cc/:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
WideCharToMultiByte: The data area passed to a system call is too small.
TypeError: Cannot read property 'prototype' of undefined
at Object.anonymous (/cygdrive/c/clojurescript/nodehello.js:13:382)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.anonymous (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)

Has anyone had success with ClojureScript + Node.js, on Windows or 
otherwise?

-- 
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: 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 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: 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) - (drop-while #(= % 3) [1 2 3 4])
(subseq (sorted-set 1 2 3 4) = 3) - (drop-while #( % 3) [1 2 3 4])

-- 
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: 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 subseq to 
get to the elements of interest in O(log n) steps, whereas drop-while needs 
O(n) steps to do the same.

On the other hand, it looks like when the elements of interest are at the 
beginning of the collection (using  or = as comparison operation), subseq 
and take-while should perform the same, since subseq simply uses take-while 
to iterate through the elements of interest in this case.

To make a long story short, when using  or =, use subseq instead of 
drop-while, especially if the elements of interest are deep in the 
collection or the same collection will be accessed multiple times.  When 
using  or =, subseq and take-while should have the same performance.  Does 
that sound about right?

-- 
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: 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 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: 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 defined like this:

  (def alist '(1 (fn [x y] (+ x y

Also, it seems that the definition of the function needs to be eval'ed first 
to become an apply-able function.  The following returns 4 in my REPL:

  (apply (eval (second alist)) '(1 3))

-- 
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: 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 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: 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 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 defined like this:

   (def alist '(1 (fn [x y] (+ x y

 Also, it seems that the definition of the function needs to be eval'ed 
 first to become an apply-able function.  The following returns 4 in my REPL:

   (apply (eval (second alist)) '(1 3))
  
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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: 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 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: 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: http://clojure.github.com/clojure-contrib/graph-api.html
Source: 
https://github.com/clojure/clojure-contrib/blob/master/modules/graph/src/main/clojure/clojure/contrib/graph.clj

Note that in the library, graphs are represented by a directed-graph struct 
(defined at the top of the source file) with two fields:

- nodes: a collection of the nodes in the graph
- neighbors: a function that takes a node and returns a collection of that 
node's neighbors

Since Clojure maps are also functions that will return the value associated 
with a key when called with the key, neighbors can simply be a map of nodes 
to collections of neighbors.

records are now recommended over structs, so it may be better to define a 
directed-graph record:

  (defrecord directed-graph [nodes neighbors])

A graph (for example, a graph of two nodes :a and :b that are connected to 
each other) can then created via:

  (def my-graph (directed-graph. [:a :b] {:a [:b], :b [:a]}))

records can be used in exactly the same way as structs, so this can be used 
right away with all the functions defined in the library.

Hope this helps!

-- 
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: 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 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: 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 #\s+)]
  (println (str word \t1)

(time (mapper (line-seq (reader *in*

Processing a file that contained 1 copy of the Hound of Baskerville text 
took 1.9 seconds.
Processing a file that contained 2 copies of the text took 2.8 seconds.
Processing a file that contained 4 copies of the text took 3.8 seconds.

I did not use cake, but ran mapper.clj via a direct call to the java 
executable.  So I think the times you're seeing is due to either Cake or the 
way the timing is done.

-- 
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: 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) (= country US)) 9.75
  :else 10.0)

*See: http://dev.clojure.org/display/design/Library+Coding+Standards

-- 
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: 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 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: 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 mystery character 
between the 0 at the end of the second condition and the :else at the start 
of the default condition.  Once I removed that character (and fixed a 
spurious newline in the last line), the code evaluated with no problems.

-- 
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: 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 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: 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
{:1
 english person
 
 [{:2 Andrew D
   [{:3 father Andrew D
 :3 mother Lisa D}]
   :2 Justin M
   [{:3 Elisa M}]}]
 :1
 
 chinese person
 [{:2 Chi chi}]
 })

In the first pair, :1 is the key, english person is the value.  In the 
second pair, the nested vector/map thing is the key, :1 is the value.  In 
the last pair, chinese person is the key, the vector containing a map is 
the value.

With all due respect, the questions you've posted to the list contain some 
misunderstandings about certain Clojure fundamentals.  May I suggest taking 
the time to work through a tutorial or book?  It will make life easier going 
forward.  There are many good choices to pick from, but this is one of my 
personal favorites:

http://java.ociweb.com/mark/clojure/article.html

-- 
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: 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 be used as a function. 
 Check the code to see if a com.vaadin.ui.Table object is the first thing in 
an unquoted list, or passed to a higher-order function in a position where 
the higher-order function is expecting a function argument.

-- 
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: 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]}

-- 
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: Properly including clojure-contrib

2011-06-16 Thread Benny Tsai
Hi cmn,

A few things:

1. The warnings you see are because the clojure.contrib.string namespace 
defines several functions that have the same name as core functions (repeat, 
reverse, etc.).  The recommended way to pull in namespaces like that is to 
do (:require [clojure.contrib.string :as str]), and then the functions can 
be used via (str/repeat ...), (str/reverse ...), etc.
2. As of 1.2, split is incorporated into clojure.string, so no need to 
grab clojure.contrib.string just for that function.  clojure.string also 
defines functions with the same name as core functions, so it should be 
pulled in via (:require [clojure.string :as str]), and split can then be 
used via (str/split ...).
3. That EOF error is because process-file needs one more closing paren.

-- 
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: clojure-contrib.jar file

2011-06-09 Thread Benny Tsai
I've never built contrib from source, but I believe the repository you'll 
want to clone from is this one:

git://github.com/clojure/clojure-contrib.git

-- 
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: 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 example), and some newer features (such as 
protocols) are not covered.  Nonetheless, I think it's still a great 
starting point.

-- 
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: 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, Tassilo Horn tas...@member.fsf.org wrote: 
  
   Do I get you right that the output is the problem that prevents me to 
   get to the SLIME REPL, since you didn't say anything at all about that 
   IllegalArgumentException? 
  
  I'm not sure what's going on with the IllegalArgumentException. Do you 
  have more than one version of swank in ~/.lein/plugins? If so it's due 
  to a separate bug in Leiningen. But I've fixed the output bug in 
  clojure-mode 1.9.1; see if that helps. 
  
  -Phil

-- 
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: 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 (partial re-matches #.*ing) words)]
  (doseq [ing-word ing-words]
(println ing-word)))

-- 
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: 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)]
  (doseq [line (line-seq rdr)
  word (.split line \\s)]
(when (.endsWith word ing)
  (println word

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

-- 
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: 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.
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: 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 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: (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 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: (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)
 1.3.0-alpha4
 user= (defn f [n]
   (println f called with n)
   (if (zero? n)
 0
 (min (f (dec n))
  (f (dec n)

 (def f (memoize f))#'user/f
 user= user= (f 2)
 #'user/f
 f called with 2
 f called with 1
 f called with 0
 0
 user= (f 2)
 0
 user= (f 3)
 f called with 3
 0
 user=

 (so it works the way you expect)
 -- 
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)



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

(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 Programming Clojure.

The output when I call f with 2:

user= (f 2)
f called with 2
f called with 1
f called with 0
f called with 0
f called with 1
f called with 0
f called with 0
0

Since f is memoized, my expectation was that I would see f called with 2, 
f called with 1, f called with 0 each printed just once.  Instead, it's 
as though I didn't memoize f at all.  I know I did, because if I call f with 
2 again, I get 0 back right away.

user= (f 2)
0

This leads me to the second issue: Having evaluated (f 2), I assumed that 
the results for (f 2), (f 1), and (f 0) are all now available for immediate 
retrieval.  If I call (f 3), I thought I would only see f called with 3 
printed and then the result.  Instead, this is what I saw:

user= (f 3)
f called with 3
f called with 2
f called with 1
f called with 0
f called with 0
f called with 1
f called with 0
f called with 0
f called with 2
f called with 1
f called with 0
f called with 0
f called with 1
f called with 0
f called with 0
0

It's as though the recursive calls go to the unmemoized version of the 
function instead of the memoized one.

I did find a way to get the expected behavior:

(def g
  (memoize
   (fn [n]
 (println g called with n)
 (if (zero? n)
   0
   (min (g (dec n))
(g (dec n)))

user= (g 2)
g called with 2
g called with 1
g called with 0
0
user= (g 3)
g called with 3
0

Up until now, I assumed the first formulation would work with recursive 
functions as well.  Was that incorrect?  Is something like the second 
formulation the only way to memoize recursive functions?

-- 
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: 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, 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: 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 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: Transforming map entries

2011-02-23 Thread Benny Tsai
My guess is that Clojure's fmap behaves that way because it is modeled
after Haskell's fmap, which only accepts functions that operate only
on the values due to the way fmap (and the Functor typeclass that fmap
belongs to) is modeled in Haskell's type system.

To pass both keys and values to your transforming function, I think
Alan's idea of using 'walk' is the best:

(use '[clojure.walk :only (walk)])

(def my-map  {:first john :last smith :age 25})

(defn my-fn [[key value]]
  (if (string? value)
[key (.toUpperCase value)]
[key value]))

user= (walk my-fn identity my-map)
{:first JOHN, :last SMITH, :age 25}

On Feb 23, 6:27 am, Chris Maier christopher.ma...@gmail.com wrote:
 Can anybody explain why fmap, when operating on an IPersistentMap,
 only passes the function the value of the map entry, instead of the
 entire map entry (i.e., the key and value pair)?  It seems a bit odd
 in that all the other implementations of fmap operate on the entire
 item in the sequence.  Also, I can imagine cases where you'd want to
 do some map transformation that also depends on the key (do something
 for entries A, B, and C, but something else for entries X, Y, and Z).

 I suppose I 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 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 value)
     value))

  user= (fmap my-fn my-map)
  {:first JOHN, :last SMITH, :age 25}

  On Feb 22, 4:23 pm, rob levy r.p.l...@gmail.com wrote:
  The usual intuitive options for this are reduce, zipmap, or into.  You can
  also write a lazily recursive solution.  I wonder why there's no function 
  in
  core that lazily re-constructs the map with the results of the function?  
  It
  seems to have been discussed on the list at least once or twice.  It seems
  like there would have to be two versions of it, one expecting a function
  with an arity of one (for just the value) and another expecting an arity of
  two (key and value).

  On Mon, Feb 21, 2011 at 10:08 PM, yair yair@gmail.com wrote:
   I'm hoping this is a dumb question and I've missed something obvious.
   I have a map with various key-value pairs and I want to transform some
   of the values, e.g.

   (def mymap {:first john :last smith :age 25}) and say I want to
   change the strings to be upper case.
   Right now all I can think of doing is using reduce and passing in an
   empty map and the re-associating each key with the (possibly)
   transformed value.  Is there something like the map function that
   takes two parameters, one a function that receives a pair and returns
   a new pair, and the other a map, and returns a map that's
   reconstituted from those pairs?

   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

  --
  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: 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 contrib namespace.

 The distinction may be important.

-- 
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: 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 value)
value))

user= (fmap my-fn my-map)
{:first JOHN, :last SMITH, :age 25}

On Feb 22, 4:23 pm, rob levy r.p.l...@gmail.com wrote:
 The usual intuitive options for this are reduce, zipmap, or into.  You can
 also write a lazily recursive solution.  I wonder why there's no function in
 core that lazily re-constructs the map with the results of the function?  It
 seems to have been discussed on the list at least once or twice.  It seems
 like there would have to be two versions of it, one expecting a function
 with an arity of one (for just the value) and another expecting an arity of
 two (key and value).







 On Mon, Feb 21, 2011 at 10:08 PM, yair yair@gmail.com wrote:
  I'm hoping this is a dumb question and I've missed something obvious.
  I have a map with various key-value pairs and I want to transform some
  of the values, e.g.

  (def mymap {:first john :last smith :age 25}) and say I want to
  change the strings to be upper case.
  Right now all I can think of doing is using reduce and passing in an
  empty map and the re-associating each key with the (possibly)
  transformed value.  Is there something like the map function that
  takes two parameters, one a function that receives a pair and returns
  a new pair, and the other a map, and returns a map that's
  reconstituted from those pairs?

  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

-- 
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: Transforming map entries

2011-02-22 Thread Benny Tsai
I was introduced to fmap by Haskell.  Specifically, the (IMHO) most
excellent Learn You a Haskell for Great Good! online tutorial.
Highly recommended!

On Feb 22, 5:04 pm, rob levy r.p.l...@gmail.com wrote:
 Yeah, fmap is perfect and definitely the most elegant for the specific
 problem described 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 '[clojure.string :as str])

  (def my-map {:first john :last smith :age 25})

  (defn my-fn [value]
   (if (string? value)
     (str/upper-case value)
     value))

  user= (fmap my-fn my-map)
  {:first JOHN, :last SMITH, :age 25}

  On Feb 22, 4:23 pm, rob levy r.p.l...@gmail.com wrote:
   The usual intuitive options for this are reduce, zipmap, or into.  You
  can
   also write a lazily recursive solution.  I wonder why there's no function
  in
   core that lazily re-constructs the map with the results of the function?
   It
   seems to have been discussed on the list at least once or twice.  It
  seems
   like there would have to be two versions of it, one expecting a function
   with an arity of one (for just the value) and another expecting an arity
  of
   two (key and value).

   On Mon, Feb 21, 2011 at 10:08 PM, yair yair@gmail.com wrote:
I'm hoping this is a dumb question and I've missed something obvious.
I have a map with various key-value pairs and I want to transform some
of the values, e.g.

(def mymap {:first john :last smith :age 25}) and say I want to
change the strings to be upper case.
Right now all I can think of doing is using reduce and passing in an
empty map and the re-associating each key with the (possibly)
transformed value.  Is there something like the map function that
takes two parameters, one a function that receives a pair and returns
a new pair, and the other a map, and returns a map that's
reconstituted from those pairs?

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

  --
  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: 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 integers
  (mapcat digits (range)))

(defn solution []
  (reduce * (take 7 (map #(nth (decimal-fraction-digits) %) (iterate
#(* 10 %) 1)

On Feb 16, 7:17 am, Marek Stępniowski mstepniow...@gmail.com wrote:
 On Wed, Feb 16, 2011 at 9:15 AM, Andreas Kostler

 andreas.koestler.le...@gmail.com wrote:
  Thanks for everyone who commented on my solution for Euler 28 yesterday.
  Euler 40 is a bit easier, even more so I'm disappointed with the 
  performance of my solution:(defn euler-40 [n-max]

  (reduce #(* (Integer/valueOf (str %1)) (Integer/valueOf (str %2)))
         (let [r (range (inc n-max))]
                 (for [n (iterate #(* % 10) 1) :while ( n n-max)] (nth 
  (apply str r) n)

  It takes about 4s to find the solution.

  First of all, I guess the whole Integer/valueOf ceremony doesn't affect 
  performance but could probably be dealt with in a more idiomatic way.
  Other than that, how could I optimise the presented solution. Hints to 
  other solutions (as long as they're pretty ;)) are also welcome :)

 My 
 solutionhttps://github.com/zuber/project-euler/blob/master/src/com/stepniowsk...
 takes ~800 ms on my computer. It's basically the same, but I believe
 it minimalizes the number of conversions from int to string.

 Cheers,
 --
 Marek Stępniowskihttp://stepniowski.com

-- 
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: 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 ns)]
(apply + 1 all-corner-nums)))

Tidbits of interest:

* I suck at reading nested code, so I move all but the most trivial
lambdas into separate functions, and use (let) liberally to name
things.  Consequently, my code tends to be more verbose, but I think
it makes life easier when revisiting code.
* (range) takes an optional step size argument, so generating all odd
numbers from 3 to max-n (inclusive) can be done via (range 3 (inc max-
n) 2).
* (+ 1 (reduce + collection)) can also be written as (apply + 1
collection).
* (mapcat) performs a map, then concatenates the results into a single
list.  I find this quite handy.
* It's a purely subjective thing, but I like using (inc x) and (dec x)
when incrementing and decrementing x by 1, respectively.

On Feb 14, 11:13 pm, Andreas Kostler
andreas.koestler.le...@gmail.com wrote:
 Hi all,
 Does anyone wanna have a look at my solution for Project Euler Problem 28?

 (defn diagonal-sum [n-max]
         (+ 1 (reduce +
                 (map (fn[n]
                       (reduce + (map #(- (* n n) (* % (- n 1))) (range 4
                      (take-nth 2 (range 3 (+ 2 n-max)))

 The function does the job. The solution takes about 1.5msec on my machine to 
 compute.
 I'd like to discuss more performant and/or more idiomatic solutions to that 
 problem :)

 The parts I'm not quite happy with are the take-nth and range constructs with 
 all the magic numbers in there...

 Cheers
 Andreas

 --
 Programs must be written for people to read, and only incidentally for 
 machines to execute.
 - Abelson  Sussman, SICP
 --
 **
 Andreas Koestler, Software Engineer
 Leica Geosystems Pty Ltd
 270 Gladstone Road, Dutton Park QLD 4102
 Main: +61 7 3891 9772     Direct: +61 7 3117 8808
 Fax: +61 7 3891 9336
 Email: andreas.koest...@leica-geosystems.com

 www.leica-geosystems.com*

 when it has to be right, Leica Geosystems

 Please  consider the environment before printing this email.

-- 
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 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 more abstract level, it's just not right
 to thrash the memory of a concurrent server-side component for
 absolutely no good reason.

-- 
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 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
DataArea element (second element in root's content), the entire
element appears to be parsed eagerly.

user= (time (let [root (parse-trim (reader huge.xml))] (-
root :content second type)))
Elapsed time: 884.905205 msecs
clojure.lang.PersistentStructMap

I spent some time looking at the source for lazy-xml as well, but
wasn't able to locate where the problem lies :(

On Feb 11, 3:07 am, Marko Topolnik marko.topol...@gmail.com wrote:
 http://db.tt/iqTo1Q4

 This is a sample XML file with 1000 records -- enough to notice a
 significant delay when evaluating the code from the original post.

 Chouser, could you spare a second here? I've been looking and looking
 at mktree and siblings for two days now and can't for the life of me
 find out why it would eagerly parse the whole contents of an element
 as soon as I acces its struct! The code looks perfectly correct.

-- 
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: Which branch of clojure-hadoop to use?

2011-02-07 Thread Benny Tsai
Thank you, Alex, for the response and your work on the code.  And
thank you for getting the ball rolling on coordinating clojure-hadoop
dev work as well.

On Feb 6, 3:58 am, Alex Ott alex...@gmail.com wrote:
 Hello

 I'm not working actively on clojure-hadoop, so maybe eslick's and clizzin's
 forks could be more advanced (although I hadn't looked onto changes).

 I think, that fragmentation of libraries is not so good thing, so I invite
 everybody who wants to participate in development to join mailing 
 listhttps://groups.google.com/group/clojure-hadoopand I can give commit rights
 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 Sierra's branch looks like the canonical one, but hasn't been
  BT updated since March 2010.  alexott's branch looks to be the most
  BT frequently updated, but there are also more recent branches from
  BT eslick and clizzin.  If someone could shed light on this situation,
  BT that'd be greatly appreciated!

 --
 With best wishes, Alex Ott, MBAhttp://alexott.blogspot.com/       
 http://alexott.net/http://alexott-ru.blogspot.com/
 Skype: alex.ott

-- 
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: 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 will
be called with an argument 'fill' in a separate thread.  'filler-func'
is expected to use 'fill' to push input onto a queue.  'fill-queue'
returns a lazy sequence of inputs pushed by 'filler-func', and will
block when needed.

Probably easier to just show it in action:

(use '[clojure.contrib.seq-utils :only (fill-queue)])

(defn read-until [prompt input-stream]
  (let [filler-func (fn [fill]
  (let [x (.read input-stream)]
(when-not (= x -1)
  (fill (char x))
  (recur fill
input (fill-queue filler-func)]
(take-while #(not= % prompt) input)))

Here, 'filler-func' repeatedly reads a char from input-stream and
pushes the char onto the queue by calling 'fill' on the char, stopping
when -1 is read (signaling end of stream).  'fill-queue' returns a
lazy seq of the read chars.  'read-until' then just uses 'take-while'
to take the chars up to the prompt (here assuming prompt is a single
char).

Using me typing in the REPL as the input source:

user= (println (read-until \x *in*))
abcdefgx
(a b c d e f g)
nil

You should be able to use this with telnet by passing in the
InputStream from the TelnetClient.  And if you wish to use a string
prompt instead, just replace the call to 'take-while' in 'read-until'
with a call to Ken's nifty 'take-until-subseq'.

(defn read-until [prompt input-stream]
  (let [filler-func (fn [fill]
  (let [input (.read input-stream)]
(when-not (= input -1)
  (fill (char input))
  (recur fill
input-seq (fill-queue filler-func)]
(take-until-subseq input-seq prompt)))

user= (println (read-until hey *in*))
abcdefghey
(a b c d e f g)
nil

On Feb 7, 6:09 pm, Andreas Kostler andreas.koestler.le...@gmail.com
wrote:
 Hi all,
 Is it possible to read from a lazy input sequence? I have a telnet
 connection using commons.telnet and I want to do something like:
 (def telnet (TelnetClient.))
 (def in (. telnet getInputStream))

 ; How do I do this?
 (def read-until
  ; read from a lazy input sequence UNTIL prompt is matched and return
 what's been read
  [prompt input-stream]
 ...)

 Every idea is appreciated :)
 Cheers
 Andreas

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


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.  alexott's branch looks to be the most
frequently updated, but there are also more recent branches from
eslick and clizzin.  If someone could shed light on this situation,
that'd be greatly appreciated!

-- 
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: 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 (int 0)]
  (if ( i buffer-size)
(let [i2 (unchecked-inc i)
  i3 (unchecked-inc i2)
  i4 (unchecked-inc i3)
  a (aget cpu_array i4)]
  (amove cpu_array i3 i4)
  (amove cpu_array i2 i3)
  (amove cpu_array i i2)
  (aset cpu_array i a)
  (recur (unchecked-inc i4)))

On Jan 30, 8:15 am, Bill James w_a_x_...@yahoo.com wrote:
 GrumpyLittleTed wrote:
  Part of the difference (under 1.2) is due to the (substantial)
  overhead of accessing the buffer-size var on every iteration.

  I ran a quick check and using David's version of the code result
  averaged 17.2ms. Just changing buffer-size to a local with using (let
  [buffer-size (int 192)]...) the time dropped to an average 3.4ms.

 Great!  Now I remember that that same technique is used in Lua.
 See long this version takes.

 (set! *warn-on-reflection* true)

 (def buffer-size 192)
 (def array (byte-array buffer-size))

 (defmacro add [m n] `(unchecked-add (int ~m) (int ~n)))
 (defmacro amove[a i j] `(aset ~a ~j (aget ~a ~i)))

 (defn java-like [^bytes cpu_array]
   (let [buffer-size (int buffer-size)]
     (loop [i (int 0)]
       (if ( i buffer-size)
         (let [ i2 (add i 1)
                i3 (add i 2)
                i4 (add i 3)
                a (aget cpu_array i4)
              ]
           (amove cpu_array i3 i4)
           (amove cpu_array i2 i3)
           (amove cpu_array i i2)
           (aset cpu_array i a)
           (recur (add i 4)))

 (dotimes [_ 10]
   (time
    (dotimes [_ 1]
      (java-like array

-- 
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: 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 i)
g (aget cpuArray (unchecked-add i (int 1)))
r (aget cpuArray (unchecked-add i (int 2)))
a (aget cpuArray (unchecked-add i (int 3)))]
(aset cpuArray i a)
(aset cpuArray (unchecked-add i (int 1)) b)
(aset cpuArray (unchecked-add i (int 2)) g)
(aset cpuArray (unchecked-add i (int 3)) r)
(recur (unchecked-add i (int 4)))

user= (time (java-like array))
Elapsed time: 13.648662 msecs

Found something interesting when I tried to emulate how Robert's
version aliased 'unchecked-add' as '+':

(defn java-like [^bytes cpuArray]
  (loop [i (int 0)]
(if ( i buffer-size)
  (let [+ unchecked-add
b (aget cpuArray i)
g (aget cpuArray (+ i (int 1)))
r (aget cpuArray (+ i (int 2)))
a (aget cpuArray (+ i (int 3)))]
(aset cpuArray i a)
(aset cpuArray (+ i (int 1)) b)
(aset cpuArray (+ i (int 2)) g)
(aset cpuArray (+ i (int 3)) r)
(recur (+ i (int 4)))

When I try to compile this, Clojure complains that I'm trying to
rebind i, a primitive local, with a value of the wront type in
'recur'.

It seems that 'unchecked-add' returns a primitive (note that in the
first version, 'recur' happily accepts the return from 'unchecked-add'
without coercion), but when 'unchecked-add' is bound to a new name,
the return gets boxed.

Is this the correct interpretation, or am I missing something?

On Jan 28, 9:06 am, David Nolen dnolen.li...@gmail.com wrote:
 On Fri, Jan 28, 2011 at 10:48 AM, Robert McIntyre r...@mit.edu wrote:
  I tried to convert this java code line for line to clojure to compare
  the speed differences, and boy was I surprised!

         public static void ConvertToAWT(byte[] cpuArray){
                 // Given an array of bytes representing a c-style bgra
  image,
                 // converts to a java style abgr image
                 int len = java.lang.reflect.Array.getLength(cpuArray);
                 for (int i = 0; i  len; i+=4){
                         byte b = cpuArray[i+0];
                         byte g = cpuArray[i+1];
                         byte r = cpuArray[i+2];
                         byte a = cpuArray[i+3];
                         cpuArray[i+0] = a;
                         cpuArray[i+1] = b;
                         cpuArray[i+2] = g;
                         cpuArray[i+3] = r;  }}

  (defn java-like []
   (loop [i (int 0)] (if ( i buffer-size)
                       (let [ + clojure.core/unchecked-add
                             b (aget cpuArray i)
                             g (aget cpuArray (+ 1 i))
                             r (aget cpuArray (+ 2 i))
                             a (aget cpuArray (+ 3 i))]
                         (aset-byte cpuArray i a)
                         (aset-byte cpuArray (+ 1 i) b)
                         (aset-byte cpuArray (+ 2 i) g)
                         (aset-byte cpuArray (+ 3 i) r)
                         (recur (int (+ i 4)))

  (defn clojure-like []
   (doall (flatten (map (fn [[b g r a]] [a b g r]) (partition 4 4
  cpuArray)

 I'm assuming you're using 1.2.0. cpuArray needs to be hinted. All the
 literals also need to be hinted. Don't use aset-byte, use aset.

 In 1.3.0 you no longer have to hint the literals and you can use the
 *unchecked-math* compiler flag instead of redefining unchecked-add as a
 local.

 David

-- 
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: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
Try replacing 'aset-byte' with 'aset' and hinting all literals (change
1 to (int 1), etc.) as per David's suggestions.  That should reduce
the gap even further.

On Jan 28, 11:31 am, Robert McIntyre r...@mit.edu wrote:
 And the plot thickens:

 This:

 (defn convert-image [#^bytes cpuArray]
   (let [unchecked-add clojure.core/unchecked-add
         len (int (count cpuArray))]
     (loop [i (int 0)] (if ( i len)
                         (let [
                               b (byte (aget cpuArray i))
                               g (byte (aget cpuArray (unchecked-add 1
 i)))
                               r (byte (aget cpuArray (unchecked-add 2
 i)))
                               a (byte (aget cpuArray (unchecked-add 3
 i)))]
                           (aset-byte cpuArray i a)
                           (aset-byte cpuArray (unchecked-add 1 i) b)
                           (aset-byte cpuArray (unchecked-add 2 i) g)
                           (aset-byte cpuArray (unchecked-add 3 i) r)
                         (recur (int (unchecked-add i 4

 vs this.

 (defn convert-image [#^bytes cpuArray]
   (let [len (java.lang.reflect.Array/getLength cpuArray)]
     (loop [i (int 0)] (if ( i len)
                         (let [i2 (unchecked-add 1 i)
                               i3 (unchecked-add 2 i)
                               i4 (unchecked-add 3 i)
                               b (byte (aget cpuArray i))
                               g (byte (aget cpuArray i2))
                               r (byte (aget cpuArray i3))
                               a (byte (aget cpuArray i4))]
                           (aset-byte cpuArray i a)
                           (aset-byte cpuArray i2 b)
                           (aset-byte cpuArray i3 g)
                           (aset-byte cpuArray i4 r)
                         (recur (unchecked-add i 4)))

 The first function takes forever; the second MUCH faster.
 Upon disassembling the byte-code of the two compiled functions, it
 does seem like the + was not being inlined.
 Since the method of reassignment doesn't preserve the metadata, this
 makes sense.

 However, my new, modified function is still around 20 times slower
 than the java version :(

 I still don't understand what's slowing me down, but I'm much happier
 that I can get within 20x of java instead of 2x

 thanks everyone.

 sincerely,
 --Robert 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-add'
  without coercion), but when 'unchecked-add' is bound to a new name,
  the return gets boxed.

  Is this the correct interpretation, or am I missing something?

  It's correct. Clojure's compiler inlines certain functions, including
  clojure.core/unchecked-foo and, when the arity is 2, clojure.core/+ --
  but not a bare, un-qualified +, which might (or might not) at runtime
  refer to clojure.core/+ or clojure.core/unchecked-add or whatever.

  --
  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: 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-add'
  without coercion), but when 'unchecked-add' is bound to a new name,
  the return gets boxed.

  Is this the correct interpretation, or am I missing something?

 It's correct. Clojure's compiler inlines certain functions, including
 clojure.core/unchecked-foo and, when the arity is 2, clojure.core/+ --
 but not a bare, un-qualified +, which might (or might not) at runtime
 refer to clojure.core/+ or clojure.core/unchecked-add or whatever.

-- 
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: 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 suggestions.

 I copied your code and tested it out, but on my machine it takes 230
 milliseconds while the java version takes about 3.

 If it's not too much trouble, how long does the java implementation
 take on your machine?

 sincerely,
 --Robert McIntyre







 On Fri, Jan 28, 2011 at 2:11 PM, David Nolen dnolen.li...@gmail.com wrote:
  On Fri, Jan 28, 2011 at 2:01 PM, Aaron Cohen aa...@assonance.org wrote:

  On Fri, Jan 28, 2011 at 1:55 PM, David Nolen dnolen.li...@gmail.com
  wrote:
   As a comparison, the following accomplishes the same thing in 1.3.0.
   (ns test)
   (set! *unchecked-math* true)
   (set! *warn-on-reflection* true)
   (def buffer-size 192)
   (def array (byte-array buffer-size))
   (defn java-like [^bytes cpuArray]
    (loop [i (int 0)]

  Is this hint still necessary on 1.3.0?

  The int cast on 0 was an oversight on my part. It's not necessary.
  David

  --
  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: Ridiculously massive slowdown when working with images

2011-01-28 Thread Benny Tsai
On my home computer, using the same options, the java version runs in
1.5 milliseconds, and David's 1.2 Clojure version in 16 milliseconds.
I'm at a loss as to why you're still seeing such a large gap between
the two versions.

On Jan 28, 6:16 pm, Robert McIntyre r...@mit.edu wrote:
 I'm running 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 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 suggestions.

  I copied your code and tested it out, but on my machine it takes 230
  milliseconds while the java version takes about 3.

  If it's not too much trouble, how long does the java implementation
  take on your machine?

  sincerely,
  --Robert McIntyre

  On Fri, Jan 28, 2011 at 2:11 PM, David Nolen dnolen.li...@gmail.com 
  wrote:
   On Fri, Jan 28, 2011 at 2:01 PM, Aaron Cohen aa...@assonance.org wrote:

   On Fri, Jan 28, 2011 at 1:55 PM, David Nolen dnolen.li...@gmail.com
   wrote:
As a comparison, the following accomplishes the same thing in 1.3.0.
(ns test)
(set! *unchecked-math* true)
(set! *warn-on-reflection* true)
(def buffer-size 192)
(def array (byte-array buffer-size))
(defn java-like [^bytes cpuArray]
 (loop [i (int 0)]

   Is this hint still necessary on 1.3.0?

   The int cast on 0 was an oversight on my part. It's not necessary.
   David

   --
   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: 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 sometimes include apache commons-io and clojure-contrib1.2 without
  any problems.
  I also included a sql connection library for one of the problems, so
  it seems fine :)

 For those puzzles that require command-line processing, have you used a 
 library
 to do it? Looking in both Programming Clojure and Practical Clojure, the
 only instruction I can find on handling command-line args involves AOT
 compilation of your class and definition of a -main method. I'm not sure how
 well this would work with the submission model that Coderloop uses.

 I'm afraid I'm still *very* new to Clojure, and while it would be easy (for 
 me)
 to solve the problems in other languages, the point of the exercise (for me) 
 is
 to use Coderloop's problems to help myself in learning Clojure...

 Randy

 --
  
 
 Randy J. Ray                 Sunnyvale, CA                http://www.rjray.org
 rj...@blackperl.com                                        http://www.svsm.org
 randy.j@gmail.com                                  
 http://twitter.com/rjray

-- 
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: 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 ideas).  I found it to be a nice complement to the
talk at infoq.  Also, some interesting questions were fielded at the
end.

On Jan 15, 4:50 pm, Tim Daly d...@axiom-developer.org wrote:
   Guy Steele recently gave a talk about thinking about parallel programming.

 For those of us who are looking at Clojure in a parallel setting (e.g.
 MPI, Hadoop)
 this might be of interest:

 http://www.infoq.com/presentations/Thinking-Parallel-Programming

-- 
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: 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 600851475143)
n: 600851475143 , f: 71
n: 8462696833 , f: 839
n: 10086647 , f: 1471
n: 6857 , f: 6857
#{71 839 1471 6857}

On Jan 13, 10:01 am, Vitaly Peressada vit...@ufairsoft.com wrote:
 Armando, thanks for a plausible explanation. Here is what happened
 after I made the suggested change:

 user= (prime-factors 600851475143)
 n: 600851475143 , f: 71
 n: 8462696833 , f: 839
 n: 10086647 , f: 1471
 n: 6857 , f: 6857
 #CompilerException java.lang.ClassCastException: java.lang.Integer
 cannot be cast to clojure.lang.IFn (REPL:91)

 I guess this something subtle with unordered vs. sorted-set as
 implicit factors accumulator. May be that is why the author of the
 solution had to use unordered set followed by (apply max ...).

 On Jan 13, 11:23 am, Armando Blancas armando_blan...@yahoo.com
 wrote:







  A literal set is a unordered hash-set. To get the factors in order
  change #{f} for (sorted-set f).

  On Jan 13, 7:09 am, Vitaly Peressada vit...@ufairsoft.com wrote:

   The following solution by bmtgred/b for a href=http://clojure-
   euler.wikispaces.com/Project Euler Clojure/a problem 003 uses
   implicit recursion.

   pre
   (use '[clojure.contrib.lazy-seqs :only (primes)])
   (defn prime-factors [n]
     (let [f (some #(if (= 0 (rem n %)) %) primes)]
       (if (= f n) #{f} (conj (prime-factors (/ n f)) f
   (apply max (prime-factors 600851475143))
   /pre

   Here is above with added println

   (defn prime-factors [n]
     (let [f (some #(if (= 0 (rem n %)) %) primes)]
       (println n: n , f: f)
       (if (= f n)
         #{f}
         (conj (prime-factors (/ n f)) f

   Which produces

   n: 600851475143 , f: 71
   n: 8462696833 , f: 839
   n: 10086647 , f: 1471
   n: 6857 , f: 6857
   #{71 839 6857 1471}

   Can anybody explain why 6857 comes 3rd? I would expect to be the last.

-- 
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: 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 be at either the
  end OR the beginning.

 For a (hashed) set, this can be *anywhere* (between existing elements too).

 FTFY

 // Ben







  For this problem, the output is built by:

  (conj (conj (conj #{6857} 1471) 839) 71)

  which is equivalent to:

  (- #{6857} (conj 1471) (conj 839) (conj 71))

  The innermost/first conj, (conj #{6857} 1471), sticks 1471 at the end
  and produces #{6857 1471}.  The next conj sticks 839 at the beginning
  and produces #{839 6857 1471}.  The final conj sticks 71 at the
  beginning and produces the final result of #{71 839 6857 1471}.

  When ordering matters, I usually use either (cons), which will always
  add to the beginning regardless of the collection type, or use (conj)
  with a list (will always add to the beginning) or vector (will always
  add to the end).

  user= (- '(6857) (conj 1471) (conj 839) (conj 71))
  (71 839 1471 6857)
  user= (- [6857] (conj 1471) (conj 839) (conj 71))
  [6857 1471 839 71]

  On Jan 13, 8:09 am, Vitaly Peressada vit...@ufairsoft.com wrote:
  The following solution by bmtgred/b for a href=http://clojure-
  euler.wikispaces.com/Project Euler Clojure/a problem 003 uses
  implicit recursion.

  pre
  (use '[clojure.contrib.lazy-seqs :only (primes)])
  (defn prime-factors [n]
    (let [f (some #(if (= 0 (rem n %)) %) primes)]
      (if (= f n) #{f} (conj (prime-factors (/ n f)) f
  (apply max (prime-factors 600851475143))
  /pre

  Here is above with added println

  (defn prime-factors [n]
    (let [f (some #(if (= 0 (rem n %)) %) primes)]
      (println n: n , f: f)
      (if (= f n)
        #{f}
        (conj (prime-factors (/ n f)) f

  Which produces

  n: 600851475143 , f: 71
  n: 8462696833 , f: 839
  n: 10086647 , f: 1471
  n: 6857 , f: 6857
  #{71 839 6857 1471}

  Can anybody explain why 6857 comes 3rd? I would expect to be the last.

  --
  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: 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 ignoring case, putting (?i) at the beginning of the regex worked
for me.  (re-find) should give you $1 just fine.

user= (require '[clojure.string :as str])
nil
user= (str/lower-case (re-find #(?i)mon|tue|wed|thu|fri|sat|sun
asdf MON tue))
mon

Hope this helps!

On Jan 13, 7:35 pm, Alex Baranosky alexander.barano...@gmail.com
wrote:
 So I am converting some Ruby code I have into CLojure for practice/fun and I
 am having trouble finding info via Google.

 I want to take something like this from Ruby and do it in Clojure:

 DATE_REGEX = /^\s*(\d{4})\s+(\d{1,2})\s+(\d{1,2})/

 token =~ DATE_REGEX
 [$1, $2, $3]

 So far my best guess has been:

 (defonce date-regex #^\s*(\d{4})\s+(\d{1,2})\s+(\d{1,2}))
 (re-find date-regex line)

 but I'm not sure how to access $1, $2, and $3

 Another example I'd like to convert is this:

 DAYS_OF_WEEK_REGEX = /^\s*(#{Date::DAYS_OF_WEEK.join('|')})/i

 token =~ DAYS_OF_WEEK_REGEX
 $1.downcase.to_sym

 Best attempt is:

 (defonce days-of-week-regex #mon|tue|wed|thu|fri|sat|sun(?i))
 (re-find days-of-week-regex line)

 Here I'd love to know the syntax for ignore-case, along with how to access $1.

 Thanks,
 Alex

-- 
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: 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 been using Emacs on Windows for a while now, and haven't run into
issues with either of these (yet).  With more detail about the issues
you faced, perhaps I could offer some help.

-- 
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: which IDEs are you all using?

2011-01-12 Thread Benny Tsai
Hi Mark,

I don't know much about the error msg you encountered, but I think
Peter's onto something with the recommendation to set %HOME% yourself
to help emacs find your init file(s).  This page has good info on how
emacs goes about determining your %HOME% directory:

http://www.gnu.org/software/emacs/windows/Installing-Emacs.html

I believe 23.2 is the latest stable release.  With any luck, the
intermittent copy/paste problems won't follow you into the newer
version :)

On Jan 12, 6:49 pm, buckmeist...@gmail.com wrote:
 Try setting %HOME% to something like c:\home, create the dir if needed, and 
 put your .emacs etc in that folder.

 I've found that spaces in paths are still often to blame for issues with 
 command line and gnu-esque tools.

 Thanks,
 Peter







 -Original Message-
 From: Mark Engelberg mark.engelb...@gmail.com

 Sender: clojure@googlegroups.com
 Date: Wed, 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 (i386-mingw-nt5.1.2600)
 When I drag a file onto the emacs icon, it starts up, but instead of
 showing me the file, it says:
 command-line-1: Cannot open load file: %userprofile%/Application
 Data/.emacs.d/init.el

 The cut-and-paste problems are intermittent; I haven't figured out
 when or why it happens.

 Thanks for your interest,

 Mark

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

 If you wrapped the doseq in a (def dictionary ...) it would work,
 but this is not recommended.
 Instead, you should either use nested reductions, or produce a simple
 list of tokens first (simpler):

 (defn process-file [file-name]
   (with-open [rdr (BufferedReader. (FileReader. file-name))]
     (reduce #(assoc %1 %2 (inc (get %1 %2 1))) {}
        (mapcat #(re-seq #[a-z]+ (.toLowerCase %))
                     (line-seq rdr)

 (def dictionary (process-file src/SpellChecker.clj))

 (Untested).  Or, using clojure-contrib functions:

 (defn process-file [file-name]
  (- (clojure.contrib.duck-streams/read-lines file-name)
         (mapcat #(re-seq #[a-z]+ (.toLowerCase %)))
         clojure.contrib.seq/frequencies))

 (also untested).

 Cheers, Jason

 On Jan 6, 10:49 am, new2clojure miguel.arre...@gmail.com wrote:







  Hi,

  I am trying to store into a map the frequency of each [a-z]+ word in a
  file. When I run this code in the repl the resulting dictionary is
  empty. How should I adapt my code to get this functionality right?.

  Thank you in advance

  (import (java.io BufferedReader FileReader))

  (def dictionary {})

  (defn process-file [file-name]
    (with-open
      [rdr (BufferedReader. (FileReader. file-name))]
      (doseq
        [line (line-seq rdr)]
        (reduce #(assoc %1 %2 (inc (get %1 %2 1))) dictionary (re-seq
  #[a-z]+ (.toLowerCase line))

  (process-file src/SpellChecker.clj)

-- 
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: My first Clojure program: request for code review

2011-01-05 Thread Benny Tsai
Hi Ken,

Sorry for the very late response; I've been away for a friend's
wedding.  Though I'm not sure if I will end up using this macro
frequently, it was highly educational to step through its inner
workings.  Thank you very much for putting it together.

On Dec 23 2010, 11:07 pm, Ken Wesson 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 goes ...

 (defmacro ends [[[firsts mid lasts] sequence]  body]
   (let [nl (count lasts)]
     `(let [s# (seq ~sequence)
           �...@firsts  ~mid] (drop-last ~nl s#)
            ~lasts (drop (- (count s#) ~nl) s#)]
       �...@body)))

 user= (ends [[[a b c] d [e f]] (range 10)] [a b c d e f])
 [0
  1
  2
  (3 4 5 6 7)
  8
  9]

 As you can see, it expects a binding vector of two items, the second a
 seqable and the first a vector of first, mid, lasts. Firsts and lasts
 are vectors of symbols, and mid is a symbol. The first items of the
 seq are assigned to the firsts symbols, in order; the last items to
 the lasts, in order; and whatever's left over in the middle to mid.

 If the sequence is short enough, odd things happen:

 user= (ends [[[a b c] d [e f]] (range 5)] [a b c d e f])
 [0 1 2 nil 3 4]

 Here the firsts and lasts exhaust the seq; mid ends up nil. Since nil
 can generally stand in for an empty seq this is OK.

 user= (ends [[[a b c] d [e f]] (range 4)] [a b c d e f])
 [0 1 nil nil 2 3]

 This is a bit more bothersome. [0 1 2 nil 2 3] might be preferred
 here. If so the macro needs a slight modification. What do you say?

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

  Right, that's true.  However, Marek had given two examples of Python
  tuple unpacking, the first being:

   first, *middle, last = sequence(...)

  Which I believe in Python 3 will bind 'first' to the first element,
  'last' to the last element, and 'middle' to a sequence of all the
  elements in the middle.  That last part is what I don't know how to do
  in Clojure.

  One way:

  (let [[[f  m] l] ((juxt drop-last last) '[a b c d])] [f m l]) ;; [a (b c)
  c]

  David

 Oops typo, ;; [a (b c) d]

 David

-- 
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: 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 you'd want to do this you might prefer another data
 representation.

I can imagine some scenarios where it would be nice to do this to
sequences.  I guess for now, if those should come up in Clojure, we'll
just have to jump through a few more hoops.  Thank you Ken.

-- 
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: 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 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 you'd want to do this you might prefer another data
  representation.

  I can imagine some scenarios where it would be nice to do this to
  sequences.  I guess for now, if those should come up in Clojure, we'll
  just have to jump through a few more hoops.  Thank you Ken.

 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.

-- 
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: 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 evaluate the whole sequence. I yet have to learn how to
 deal with lazyness.

You're right, I hadn't realized 'reverse' is not lazy (I have a lot to
learn about lazyness management myself :)).  In this case, though, I
don't think it has too much impact, since:

1) The reversing is done just before we evaluate and print everything
anyway.
2) 'sort-by' is not lazy either; has to evaluate everything in order
to find the first item.

FYI, 'reduce' is also not lazy.

 Great! I was wondering whether Clojure supports something like
 tuple-unpacking in Python. Does it also support patterned
 destructuring like:

 first, *middle, last = sequence(...)
 -or-
 first, rest = sequence(...)

 The latter could be achived by something like `first+rest', I suppose,
 but don't know the Clojure name for it.

The latter is definitely supported; the name after a '' will be bound
to the remainder of a sequence:

user= (let [[fst  rst] [1 2 3]] (println first: fst rest: rst))
first: 1 rest: (2 3)

But I don't know of a way to bind the 'middle' elements of a sequence
to something.

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


  1   2   >