splicing and anonymous functions

2011-01-30 Thread Phillip Calçado
Hi all, I've stumbled upon some interesting behaviour regarding macros and anonymous functions. I couldn't find doco anywhere on this so if you have any pointers please let me know. Considering the macro: (defmacro splicer [a] `(list ~@ a)) What's the expected result of: (macroexpand-1 '(splic

Re: splicing and anonymous functions

2011-01-30 Thread B Smith-Mannschott
(1) #( ... ) is tanslated to (fn* [ ARGS ] ( ... )) before any macros are expanded because it is a *reader macro*. (2) The contents of #() are taken to be a function application. That's why you can write #(+ 1 %) and have + applied to 1 and %. By the same token, you can't write #(true) and expect

Re: splicing and anonymous functions

2011-01-30 Thread Phillip Calçado
Thanks, Ben, I think that while simplifying the example to create a small failing test case I made some confusion about the root cause of the problems I was having. Cheers -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send e

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Alexander Yakushev
Why not use a constraint? It looks much cleaner. (defn hello [& {:keys [a b] :as input}] {:pre [(= (set (keys input)) #{:a :b})]} "hello") You can learn more about constraints here: http://vimeo.com/channels/fulldisclojure#8399758 -- You received this message because you are

Re: Getting http-agent to throw an exception if url doesn't exist?

2011-01-30 Thread Michael Ossareh
On Sat, Jan 29, 2011 at 01:58, Max Weber wrote: > Give clj-http a try (https://github.com/getwoven/clj-http). It has an > architecture similar to the one of Ring. Especially the Ring-style > middleware helps a lot, if you want to add custom behaviour like error > handling to clj-http. > > Looks gr

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Shantanu Kumar
On Jan 30, 2:17 pm, Alexander Yakushev wrote: > Why not use a constraint? It looks much cleaner. > > (defn hello [& {:keys [a b] :as input}] >          {:pre [(= (set (keys input)) #{:a :b})]} >          "hello") This is not the use case I was looking for (I listed it in a post above). Constrai

locals clearing

2011-01-30 Thread Daniel Janus
Hi, I've recently heard about the locals clearing feature of Clojure 1.2 (from a recent post by Ken Wesson), and decided to test-drive it. Here is a contrived example: (defn garbage [] (make-array Byte/TYPE 10485760)) (defn -main [& args] (let [a (garbage) b (garbage) c (ga

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Bill James
On Jan 28, 12:55 pm, David Nolen wrote: > (ns atest) > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] >   (loop [i (int 0)] >     (if (< i (int buffer-size)) >       (let [b (byte (aget cpuArray i)) >  

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread GrumpyLittleTed
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 ti

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Bill James
On Jan 28, 12:55 pm, David Nolen wrote: > (ns atest) > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] >   (loop [i (int 0)] >     (if (< i (int buffer-size)) >       (let [b (byte (aget cpuArray i)) >  

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Bill James
David Nolen wrote: > (ns atest) > > (set! *warn-on-reflection* true) > > (def buffer-size 192) > (def array (byte-array buffer-size)) > (defn java-like [^bytes cpuArray] > (loop [i (int 0)] > (if (< i (int buffer-size)) > (let [b (byte (aget cpuArray i)) > g (byte (aget

Re: locals clearing

2011-01-30 Thread Rich Hickey
On Jan 30, 6:08 am, Daniel Janus wrote: > Hi, > > I've recently heard about the locals clearing feature of Clojure 1.2 (from a > recent post by Ken Wesson), and decided to test-drive it. Here is a > contrived example: > > (defn garbage [] >   (make-array Byte/TYPE 10485760)) > > (defn -main [& a

Re: locals clearing

2011-01-30 Thread .Bill Smith
Am I correct in assuming that if those allocations had been smaller (i.e. if the JVM had not run out of memory), the GC would have eventually detected the dead references and freed them once the locals went out of scope? Bill Smith On Sunday, January 30, 2011 7:41:44 AM UTC-6, Rich Hickey wrote

proxy and java.io.Writer

2011-01-30 Thread Jonas Enlund
Hi. I'm trying to create a java.io.Writer proxy (which writes to a JTextArea) but I can't get it to work. Here is my clojure code so far: (def text-area (javax.swing.JTextArea.)) (def frame      (let [f (javax.swing.JFrame.)]        (.. f getContentPane (add text-area))        (.setMinimumSize f

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Bill James
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 > [buf

Debugging with 1.3 and CDT

2011-01-30 Thread Daniel Renfer
I'm trying to set up debugging for my application using the Clojure Debugging Toolkit. I'm fairly certain I have everything set up properly, but I can't seem to get it to "reval" appropriately. I am using the Clojure maven plugin to launch a swank server. (with the debugging args from George's

Re: locals clearing

2011-01-30 Thread Michael Wood
Hi On 30 January 2011 15:49, .Bill Smith wrote: > Am I correct in assuming that if those allocations had been smaller (i.e. if > the JVM had not run out of memory), the GC would have eventually detected > the dead references and freed them once the locals went out of scope? Yes, once they are ou

Re: proxy and java.io.Writer

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund wrote: > Hi. > I'm trying to create a java.io.Writer proxy (which writes to a > JTextArea) but I can't get it to work. > Here is my clojure code so far: > > (def text-area (javax.swing.JTextArea.)) > > (def frame >      (let [f (javax.swing.JFrame.)] >

Re: Getting started with Counterclockwise

2011-01-30 Thread Mike Meyer
"Ken Wesson" wrote: >On Sat, Jan 29, 2011 at 1:46 PM, Mike Meyer > wrote: >> Ditto.  Most often, the "code" site is the sole project site, and >everything is there. Some larger projects may have a separate "home" >page, but it's always prominently mentioned on the "code" site. In >either case, th

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar wrote: > On Jan 30, 2:17 pm, Alexander Yakushev > wrote: >> Why not use a constraint? It looks much cleaner. >> >> (defn hello [& {:keys [a b] :as input}] >>          {:pre [(= (set (keys input)) #{:a :b})]} >>          "hello") Where is this docum

Re: Getting started with Counterclockwise

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 12:07 PM, Mike Meyer wrote: > Sure, Sturgeon's law is closer to 99% than 90% for the web.  But if you don't > even look at the right page to start with That is why I say it behooves projects that wish to grow a large user-base to have a highly-ranked google result be clea

Re: Getting started with Counterclockwise

2011-01-30 Thread Mike Meyer
"Ken Wesson" wrote: >On Sun, Jan 30, 2011 at 12:07 PM, Mike Meyer > wrote: >> Sure, Sturgeon's law is closer to 99% than 90% for the web.  But if >you don't even look at the right page to start with > >That is why I say it behooves projects that wish to grow a large >user-base to have a highly-ra

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread David Nolen
On Sat, Jan 29, 2011 at 10:37 AM, 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-si

Re: Getting started with Counterclockwise

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer wrote: > "Ken Wesson" wrote: >>That is why I say it behooves projects that wish to grow a large >>user-base to have a highly-ranked google result be clearly the place >>for prospective end-users to go for further information, >>documentation, friendly

Re: Getting started with Counterclockwise

2011-01-30 Thread Mike Meyer
"Ken Wesson" wrote: >On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer > wrote: >> "Ken Wesson" wrote: >>>That is why I say it behooves projects that wish to grow a large >>>user-base to have a highly-ranked google result be clearly the place >>>for prospective end-users to go for further information

Re: proxy and java.io.Writer

2011-01-30 Thread Jonas Enlund
On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund wrote: >> Hi. >> I'm trying to create a java.io.Writer proxy (which writes to a >> JTextArea) but I can't get it to work. >> Here is my clojure code so far: >> >> (def text-area (javax.swing.JTextAr

Re: Getting started with Counterclockwise

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 1:24 PM, Mike Meyer wrote: > "Ken Wesson" wrote: > >>On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer >> wrote: >>> "Ken Wesson" wrote: That is why I say it behooves projects that wish to grow a large user-base to have a highly-ranked google result be clearly the plac

Re: proxy and java.io.Writer

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 1:35 PM, Jonas Enlund wrote: > On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson wrote: >> On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund wrote: >>> Hi. >>> I'm trying to create a java.io.Writer proxy (which writes to a >>> JTextArea) but I can't get it to work. >>> Here is my c

Re: Getting started with Counterclockwise

2011-01-30 Thread Mike Meyer
On Sun, 30 Jan 2011 13:38:24 -0500 Ken Wesson wrote: > On Sun, Jan 30, 2011 at 1:24 PM, Mike Meyer > wrote: > > "Ken Wesson" wrote: > > > >>On Sun, Jan 30, 2011 at 12:31 PM, Mike Meyer > >> wrote: > >>> "Ken Wesson" wrote: > That is why I say it behooves projects that wish to grow a large

Re: proxy and java.io.Writer

2011-01-30 Thread Jonas Enlund
On Sun, Jan 30, 2011 at 8:39 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 1:35 PM, Jonas Enlund wrote: >> On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson wrote: >>> On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund >>> wrote: Hi. I'm trying to create a java.io.Writer proxy (which writes t

Re: Getting started with Counterclockwise

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 1:45 PM, Mike Meyer wrote: >> Not until after they go there once or twice, find confusing project >> pages with no clear starting point for prospective end users, and form >> an opinion of the site. :) > > Yup. Those pages are about as well organized as every other page one

Re: Debugging with 1.3 and CDT

2011-01-30 Thread George Jahad
Hey Daniel: I'm embarrassed to say I've never tried it before on 1.3. You've found a real bug. I'll try to get a proper patch out later today, but if you're in a hurry, you might try changing this line in cdt.clj: (def ge (memoize #(first (find-methods (va) #"get" to this: (def ge (memoiz

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Robert McIntyre
That's excellent. Thank you everyone. Maybe someone could compile all these "let's speed up this clojure code" threads and put it somewhere as a valuable resource we could point to when things like this come up again? sincerely, --Robert McIntyre On Sun, Jan 30, 2011 at 1:01 PM, David Nolen wr

Re: proxy and java.io.Writer

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 1:47 PM, Jonas Enlund wrote: > user=> (.write text-area-writer "Hello, World!") > ArityException Wrong number of args (2) passed to: user$fn--38$fn > clojure.lang.AFn.throwArity (AFn.java\ > :439) > user=> (pst) > ArityException Wrong number of args (2) passed to: user$fn--

Re: Getting started with Counterclockwise

2011-01-30 Thread Mike Meyer
On Sun, 30 Jan 2011 13:51:40 -0500 Ken Wesson wrote: > On Sun, Jan 30, 2011 at 1:45 PM, Mike Meyer > wrote: > >> Not until after they go there once or twice, find confusing project > >> pages with no clear starting point for prospective end users, and form > >> an opinion of the site. :) > > > >

Re: Getting started with Counterclockwise

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 2:58 PM, Mike Meyer wrote: > On Sun, 30 Jan 2011 13:51:40 -0500 > Ken Wesson wrote: >> But that's neglecting a crucial biasing factor: with project-hosting >> sites it's very easy to just slap together a few text blurbs for the >> front page and carry on your business usin

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Aaron Cohen
On Sun, Jan 30, 2011 at 12:12 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar > wrote: >> On Jan 30, 2:17 pm, Alexander Yakushev >> wrote: >>> Why not use a constraint? It looks much cleaner. >>> >>> (defn hello [& {:keys [a b] :as input}] >>>          {:pre [(= (set (key

Re: Debugging with 1.3 and CDT

2011-01-30 Thread Daniel Renfer
That did the trick. The keys on my keyboard that spell out "println" thank you. On Sun, Jan 30, 2011 at 2:25 PM, George Jahad wrote: > Hey Daniel: > > I'm embarrassed to say I've never tried it before on 1.3.  You've > found a real bug.  I'll try to get a proper patch out later today, but > if y

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 4:03 PM, Aaron Cohen wrote: > On Sun, Jan 30, 2011 at 12:12 PM, Ken Wesson wrote: >> On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar >> wrote: >>> On Jan 30, 2:17 pm, Alexander Yakushev >>> wrote: Why not use a constraint? It looks much cleaner. (defn hell

How to disallow unlisted optional argument keys?

2011-01-30 Thread Alexander Yakushev
> Where is this documented? I couldn't find the documentation for it. I learned about them in Full Disclojure screencasts by Sean Devlin. -- 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

Re: def inside a function / set object null

2011-01-30 Thread David Steiner
> You just discard all references to an object. And then afterwards I called (makea), creating a new 'a object. But then why does it throw an exception when I deref it? I searched the archives and learned that my intended coding style (using global vars) isn't idiomatic: http://groups.google.com/

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 (

Re: Struct vs. Record: Now and Future

2011-01-30 Thread Stuart Sierra
This is not solvable in the most general case. Java serialization tries really hard to be a completely generic format, but when you have a large graph of complex objects it becomes unwieldy and inefficient. Clojure's pr/read will suffice if you restrict yourself to types that can be read by the

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Bill James
Alexander Yakushev wrote: > Why not use a constraint? It looks much cleaner. > > (defn hello [& {:keys [a b] :as input}] > {:pre [(= (set (keys input)) #{:a :b})]} > "hello") > > You can learn more about constraints here: > http://vimeo.com/channels/fulldisclojure#8399758 {:pre

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 5:08 PM, Alexander Yakushev wrote: >> Where is this documented? > > I couldn't find the documentation for it. I learned about them in Full > Disclojure screencasts by Sean Devlin. There is another, quite active thread on this topic right here, right now. It includes some m

a tour of Clojure (network analysis of Clojure projects)

2011-01-30 Thread Eric Lavigne
I've been studying network analysis recently, in an attempt to automatically infer relationships between various Clojure projects. If a program can determine which similar libraries are good replacements for eachother, and which libraries tend to work well together, I can build a browseable directo

Re: Ridiculously massive slowdown when working with images

2011-01-30 Thread Bill James
Benny Tsai wrote: > 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 (i