Re: EOFException when using clojuredocs under repl

2012-11-09 Thread Satoru Logic


On Saturday, November 10, 2012 1:34:20 PM UTC+8, Sean Corfield wrote:
>
> On Fri, Nov 9, 2012 at 8:50 PM, Satoru Logic 
> > 
> wrote: 
> > But when I try, it failed with an `EOFException`: 
> > 
> >   user=> (clojuredocs pprint) 
> >   EOFException Unexpected end of ZLIB input stream 
> > java.util.zip.InflaterInputStream.fill (InflaterInputStream.java:223) 
> > 
> > Is this a bug? 
>
> Perhaps a firewall issue or something? Or maybe clojuredocs.org was 
> temporarily down? 
>

I think so.

It works now. 

Thanks. 

>
> It works fine for me now.  

-- 
> Sean A Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
> World Singles, LLC. -- http://worldsingles.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 anyone explain this behavior of clojure.java.shell/sh ?

2012-11-09 Thread Michael Gardner
I can't duplicate your results on my Debian wheezy box (Clojure 1.4, openjdk 
1.6.0_24, xdg-open 1.1.0 rc1); the call to (sh "xdg-open" …) returns 
immediately. The only possibilities I can think of are that your version of 
xdg-open blocks when run from a non-interactive shell, or that your version of 
Java somehow handles subprocesses differently.

The first possibility should be easy to test. And you should be able to test 
the second by writing your own shell script that forks and then exits (at 
least, I assume that's what xdg-open is doing).

On Nov 9, 2012, at 19:26 , Andy Fingerhut  wrote:

> This issue may be specific to Linux, or even to a particular version of Linux 
> that I am using (Ubuntu 11.10 32-bit desktop), although I doubt it is.  If 
> others try this out, I'd be curious to know what your results are, especially 
> if you know why it is happening, and how it can be fixed.
> 
> First, some behavior from a bash window on Ubuntu 11.10:
> 
> % echo hi
> hi
> % xdg-open http://www.google.com
> %
> 
> After pressing return for the xdg-open command above, my browser opens a tab 
> to Google's home page.  Back in the shell window, the next prompt appears 
> immediately, even though the browser is still running and open to that page.  
> That is what I expect to happen.
> 
> However, if I do the following commands inside of a Clojure REPL (tested 
> Clojure 1.4 and 1.5-beta1 so far):
> 
> % rlwrap java -cp ~/lein/clojure-1.4.0/lib/clojure-1.4.0.jar clojure.main
> Clojure 1.4.0
> user=> (require '[clojure.java.shell :as sh])
> nil
> user=> (sh/sh "echo" "hi")
> {:exit 0, :out "hi\n", :err ""}
> user=> (sh/sh "xdg-open" "http://www.google.com";)
> 
> The invocation of echo returns immediately, printing the result and the next 
> REPL prompt.  But when I invoke xdg-open, while the browser window appears 
> and goes to the Google home page, back in the bash window I see no return 
> value and no new REPL prompt.
> 
> If I quit the browser, then back in the bash window I finally see the return 
> value and a REPL prompt, as shown below:
> 
> {:exit 0, :out "", :err ""}
> user=> 
> 
> 
> What I'm wishing would happen is for the return value and REPL prompt to 
> appear very soon after pressing return when invoking xdg-open with 
> clojure.java.shell/sh.
> 
> I added some debug print messages to a local copy of clojure.java.shell/sh, 
> and it is stopping when waiting for the evaluation of either @out or @err in 
> the final line of the function.
> 
> If I do the same commands above on Mac OS X, with "open" instead of 
> "xdg-open", it all works as I expect.
> 
> Any clues?
> 
> Thanks,
> 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

-- 
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: EOFException when using clojuredocs under repl

2012-11-09 Thread Sean Corfield
On Fri, Nov 9, 2012 at 8:50 PM, Satoru Logic  wrote:
> But when I try, it failed with an `EOFException`:
>
>   user=> (clojuredocs pprint)
>   EOFException Unexpected end of ZLIB input stream
> java.util.zip.InflaterInputStream.fill (InflaterInputStream.java:223)
>
> Is this a bug?

Perhaps a firewall issue or something? Or maybe clojuredocs.org was
temporarily down?

It works fine for me now.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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


EOFException when using clojuredocs under repl

2012-11-09 Thread Satoru Logic
HI, all.

I read in a `leiningen` tutorial that we can use `clojuredocs` to get docs 
and examples.

But when I try, it failed with an `EOFException`:

  user=> (clojuredocs pprint)
  EOFException Unexpected end of ZLIB input stream 
 java.util.zip.InflaterInputStream.fill (InflaterInputStream.java:223)

Is this a bug?

BTW, I'm using Leiningen 2.0.0-preview10 on Java 1.6.0_35 Java HotSpot(TM) 
64-Bit Server 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

Re: is it possible to run `lein repl` without generating a `repl-port` file?

2012-11-09 Thread Satoru Logic
Cool! Thanks.

On Saturday, November 10, 2012 10:20:14 AM UTC+8, Phil Hagelberg wrote:
>
> This is a bug that's been fixed on master. A new release is just around 
> the corner.
>
> -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: Can anyone explain this behavior of clojure.java.shell/sh ?

2012-11-09 Thread Ravindra Jaju
Don't have access right now to check, but guessing that xdg-open waits for
the child process to exit.
Try detaching/backgrounding? Not sure how you'd do that with the "sh"
function though.

Naively, wrap in (future ...)?

-- 
jaju

On Sat, Nov 10, 2012 at 6:56 AM, Andy Fingerhut wrote:

> This issue may be specific to Linux, or even to a particular version of
> Linux that I am using (Ubuntu 11.10 32-bit desktop), although I doubt it
> is.  If others try this out, I'd be curious to know what your results are,
> especially if you know why it is happening, and how it can be fixed.
>
> First, some behavior from a bash window on Ubuntu 11.10:
>
> % echo hi
> hi
> % xdg-open http://www.google.com
> %
>
> After pressing return for the xdg-open command above, my browser opens a
> tab to Google's home page.  Back in the shell window, the next prompt
> appears immediately, even though the browser is still running and open to
> that page.  That is what I expect to happen.
>
> However, if I do the following commands inside of a Clojure REPL (tested
> Clojure 1.4 and 1.5-beta1 so far):
>
> % rlwrap java -cp ~/lein/clojure-1.4.0/lib/clojure-1.4.0.jar clojure.main
> Clojure 1.4.0
> user=> (require '[clojure.java.shell :as sh])
> nil
> user=> (sh/sh "echo" "hi")
> {:exit 0, :out "hi\n", :err ""}
> user=> (sh/sh "xdg-open" "http://www.google.com";)
>
> The invocation of echo returns immediately, printing the result and the
> next REPL prompt.  But when I invoke xdg-open, while the browser window
> appears and goes to the Google home page, back in the bash window I see no
> return value and no new REPL prompt.
>
> If I quit the browser, then back in the bash window I finally see the
> return value and a REPL prompt, as shown below:
>
> {:exit 0, :out "", :err ""}
> user=>
>
>
> What I'm wishing would happen is for the return value and REPL prompt to
> appear very soon after pressing return when invoking xdg-open with
> clojure.java.shell/sh.
>
> I added some debug print messages to a local copy of
> clojure.java.shell/sh, and it is stopping when waiting for the evaluation
> of either @out or @err in the final line of the function.
>
> If I do the same commands above on Mac OS X, with "open" instead of
> "xdg-open", it all works as I expect.
>
> Any clues?
>
> Thanks,
> 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
>

-- 
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: is it possible to run `lein repl` without generating a `repl-port` file?

2012-11-09 Thread Phil Hagelberg
This is a bug that's been fixed on master. A new release is just around the
corner.

-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

Can anyone explain this behavior of clojure.java.shell/sh ?

2012-11-09 Thread Andy Fingerhut
This issue may be specific to Linux, or even to a particular version of Linux 
that I am using (Ubuntu 11.10 32-bit desktop), although I doubt it is.  If 
others try this out, I'd be curious to know what your results are, especially 
if you know why it is happening, and how it can be fixed.

First, some behavior from a bash window on Ubuntu 11.10:

% echo hi
hi
% xdg-open http://www.google.com
%

After pressing return for the xdg-open command above, my browser opens a tab to 
Google's home page.  Back in the shell window, the next prompt appears 
immediately, even though the browser is still running and open to that page.  
That is what I expect to happen.

However, if I do the following commands inside of a Clojure REPL (tested 
Clojure 1.4 and 1.5-beta1 so far):

% rlwrap java -cp ~/lein/clojure-1.4.0/lib/clojure-1.4.0.jar clojure.main
Clojure 1.4.0
user=> (require '[clojure.java.shell :as sh])
nil
user=> (sh/sh "echo" "hi")
{:exit 0, :out "hi\n", :err ""}
user=> (sh/sh "xdg-open" "http://www.google.com";)

The invocation of echo returns immediately, printing the result and the next 
REPL prompt.  But when I invoke xdg-open, while the browser window appears and 
goes to the Google home page, back in the bash window I see no return value and 
no new REPL prompt.

If I quit the browser, then back in the bash window I finally see the return 
value and a REPL prompt, as shown below:

{:exit 0, :out "", :err ""}
user=> 


What I'm wishing would happen is for the return value and REPL prompt to appear 
very soon after pressing return when invoking xdg-open with 
clojure.java.shell/sh.

I added some debug print messages to a local copy of clojure.java.shell/sh, and 
it is stopping when waiting for the evaluation of either @out or @err in the 
final line of the function.

If I do the same commands above on Mac OS X, with "open" instead of "xdg-open", 
it all works as I expect.

Any clues?

Thanks,
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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread Sean Corfield
On Fri, Nov 9, 2012 at 3:17 PM, larry google groups
 wrote:
> http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/UsingSQL.html
>
> I will read over that page. I have no experience with Java, which would
> probably help as there seem to be an abundance of Java examples on related
> topics.

There's no Java at all on that page (hence my puzzlement).

> but I am assuming I would get terrible performance if I use with-connection,
> since I need to make several queries.

Get it working first, then worry about performance (and all you'll
need to do is add the connection pooling stuff as indicated in the
java.jdbc docs and use (db-connection) instead of plain db in your
with-connection calls).

I think you're over-thinking things and I'd be happy to try to help
you off-list if you want - send me an email and we'll figure out
screen sharing or something so I can walk you thru it and get you up
and running.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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


Clojure Signal Processing

2012-11-09 Thread Stephen Olsen
 

Hey all,

I've been thinking about and wanting to do some music transcription 
projects recently (inferring musical notes from audio) and what the best 
way to write systems like this is clojure would be. There are java 
libraries and things like fftw that can handle the *hard* parts like 
computing fourier transformations. These libraries are not necessarily easy 
to use idiomatically from clojure or easily composable though. I'm also 
having a hard time seeing the best way to wire up different components so 
that a stream of audio can flow between them.

What I think I want is a toolkit for creating signal processing graphs in 
idiomatic clojure. It seems like the main abstractions that I'd want would 
be similar to what storm uses for data processing; stream sources, bolts 
and topologies to show how they connect. That way one could code up some 
pieces, use common built in bolts to get things like frequency information, 
declare how the pieces fit together and then run the system in a variety of 
different ways.

I'd also like the library to be built on a set of protocols so the 
processing graphs can be run in a variety of settings. In process in an 
async manner (something similar to the way lamina works), paralyzed across 
many machines with storm or even in the web browser leveraging the new 
html5 audio data apis.

I plan to build this library and what I'm looking for is some feedback and 
guidance before I begin. I'd especially love to hear from anyone that is 
working on these kinds of systems in clojure.

A Couple of the main questions I have before I can begin are these.

1) Are streams, bolts and topologies the right level of abstraction for 
building systems like this? They will need to be a little more complicated 
than the way storm does things I think. Different bolts will need to 
operate on different length intervals of the signal. (an fft bolt will need 
one bin size but then later down stream a pitch tracking bolt will need 
different interval sizes) I guess giving bolts a buffer size would be 
necessary and every time that buffer is filled the analysis function would 
be called.

2) What is the best way to implement asynchronous streaming binary data in 
clojure?

-- 
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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread larry google groups
do-commands is intended for DDL. All of these API methods are intended 
to be used inside (with-connection ...) which is how they know which 
DB connection to use. 
Again: 
Perhaps you can explain a bit more about what you're trying to do. 
Have you looked at this page: 
http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/UsingSQL.html 


I will read over that page. I have no experience with Java, which would 
probably help as there seem to be an abundance of Java examples on related 
topics. 

Right now I'm trying to run this query against a MySql database:

select u.first_name, u.last_name, sum(p.amount) as amountTotal from 
sf_guard_user_profile as u, payment_outgoing_for_answers as p where 
u.user_id=p.user_id group by p.user_id order by amountTotal ;

I can not figure out what command to use. The examples all look like this:

sql/with-connection db


but I am assuming I would get terrible performance if I use with-connection, 
since I need to make several queries.  





On Friday, November 9, 2012 1:48:25 PM UTC-5, Sean Corfield wrote:
>
> On Fri, Nov 9, 2012 at 10:19 AM, larry google groups 
> > wrote: 
> > Usage: (do-commands & commands) 
> > 
> > This seems flexible, but how does it know what the open database 
> connection 
> > is? I have to switch between 2 databases. 
>
> do-commands is intended for DDL. All of these API methods are intended 
> to be used inside (with-connection ...) which is how they know which 
> DB connection to use. 
>
> Again: 
>
> Perhaps you can explain a bit more about what you're trying to do. 
>
> Have you looked at this page: 
> http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/UsingSQL.html 
>
> I think you're over-thinking / over-complicating what you need... 
> -- 
> Sean A Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
> World Singles, LLC. -- http://worldsingles.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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread Sean Corfield
On Fri, Nov 9, 2012 at 10:19 AM, larry google groups
 wrote:
> Usage: (do-commands & commands)
>
> This seems flexible, but how does it know what the open database connection
> is? I have to switch between 2 databases.

do-commands is intended for DDL. All of these API methods are intended
to be used inside (with-connection ...) which is how they know which
DB connection to use.

Again:

Perhaps you can explain a bit more about what you're trying to do.

Have you looked at this page:
http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/UsingSQL.html

I think you're over-thinking / over-complicating what you need...
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread larry google groups
>the general idiom with-some-resource means that resources will be cleared 
after leaving its 
>scope. JUst like with 'with-open' which has a try/finally in order to 
.close() any closable 
>resource upon exit. I've not used  clojure.java.jdbc but I suspect the 
same rationale applies 
>for with-connection...


Thanks for that. That is good to remember. 




On Friday, November 9, 2012 12:56:00 PM UTC-5, Jim foo.bar wrote:
>
>  the general idiom with-some-resource means that resources will be 
> cleared after leaving its scope. JUst like with 'with-open' which has a 
> try/finally in order to .close() any closable resource upon exit. I've not 
> used  clojure.java.jdbc but I suspect the same rationale applies for 
> with-connection...
>
> for example in one of my GUIs I have a 'with-busy-cursor' and a 
> 'with-block' macros. Every time an expensive operation happens on the gui I 
> want a busy cursor but also I want my buttons to be non-reactive while the 
> busy-cursor is visible (the user can click but nothing happens). so imagine 
> i've got  the 'with-block' called from inside the 'with-busy-cursor' and 
> that removes all the boilerplate code for restoring the cursor and the 
> reactive gui...
>
> hope that helps...
>
> Jim
>
>
>
>
>
> On 09/11/12 17:42, larry google groups wrote:
>  
>
> Sorry this is such an ignorant question, but I am new to Clojure and the 
> JVM. I am tring to find info about clojure.java.jdbc so I looked here:
>
>  http://corfield.org/blog/post.cfm/connecting-clojure-and-mysql
>  
>  and saw this example:
>
>  (ns mysql.core
>   (:require [clojure.java.jdbc :as sql]))
>
> (def db {:classname "com.mysql.jdbc.Driver"
>  :subprotocol "mysql"
>  :subname "//localhost:3306/dbname"
>  :user "dbuser"
>  :password "secret"})
>
> (defn list-users []
>   (sql/with-connection db
> (sql/with-query-results rows
>   ["select * from user"]
>   (println rows
>
> Can I assume that sql/with-connection does some magic in the background to 
> manage the connection? I would not want the connection to get shut down, and 
> then restarted, everytime I run a query. 
>
>-- 
> 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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread larry google groups
I am looking here:

http://clojure.github.com/java.jdbc/

I notice this:

do-commands

Usage: (do-commands & commands)

Executes SQL commands on the open database connection.



This seems flexible, but how does it know what the open database connection 
is? I have to switch between 2 databases. 



On Friday, November 9, 2012 12:53:56 PM UTC-5, Sean Corfield wrote:
>
> On Fri, Nov 9, 2012 at 9:42 AM, larry google groups 
> > wrote: 
> > Can I assume that sql/with-connection does some magic in the background 
> to 
> > manage the connection? I would not want the connection to get shut down, 
> and 
> > then restarted, everytime I run a query. 
>
> Use a connection pool. There's an example of c3p0 in the java.jdbc 
> documentation: 
>
> http://clojure.github.com/java.jdbc/ 
>
> Specifically: 
>
>
> http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/ConnectionPooling.html
>  
> -- 
> Sean A Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
> World Singles, LLC. -- http://worldsingles.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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread Sean Corfield
I'm not sure why you'd need to use those low-level APIs for normal queries etc?

Perhaps you can explain a bit more about what you're trying to do.

Have you looked at this page:
http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/UsingSQL.html

Sean

On Fri, Nov 9, 2012 at 10:13 AM, larry google groups
 wrote:
> Thank you. Again, apologies for the ignorant questions. I'm reading over
> this:
>
> http://clojure.github.com/java.jdbc/
>
> If I read this correctly, once I have the db connection, I can use a
> combination of
>
> prepare-statement
>
> and
>
> do-prepared
>
> to run the select statements that i need to make?

-- 
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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread larry google groups

Thank you. Again, apologies for the ignorant questions. I'm reading over 
this:

http://clojure.github.com/java.jdbc/ 

If I read this correctly, once I have the db connection, I can use a 
combination of 

prepare-statement

and
do-prepared

to run the select statements that i need to make? 





On Friday, November 9, 2012 12:53:56 PM UTC-5, Sean Corfield wrote:
>
> On Fri, Nov 9, 2012 at 9:42 AM, larry google groups 
> > wrote: 
> > Can I assume that sql/with-connection does some magic in the background 
> to 
> > manage the connection? I would not want the connection to get shut down, 
> and 
> > then restarted, everytime I run a query. 
>
> Use a connection pool. There's an example of c3p0 in the java.jdbc 
> documentation: 
>
> http://clojure.github.com/java.jdbc/ 
>
> Specifically: 
>
>
> http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/ConnectionPooling.html
>  
> -- 
> Sean A Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
> World Singles, LLC. -- http://worldsingles.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: Coding Standard - ns usage

2012-11-09 Thread Softaddicts
Yep but still longer to type :) we are in the process of shrinking the code 
base,
nit expanding it, any bytes count :))


> On Fri, Nov 9, 2012 at 8:28 AM, Sean Corfield  wrote:
> > On Thu, Nov 8, 2012 at 3:19 PM, Softaddicts  
> > wrote:
> >> Removing use would force us to redefine it somehow.
> > (:use clojure.tools.trace) => (:require [clojure.tools.trace :refer :all)
> 
> *sigh* no paredit in Gmail and I haven't had my coffee yet:
> 
> (ns ...
>   (:use clojure.tools.trace) => (:require [clojure.tools.trace :refer :all])
>   ...)
> 
> but I'm sure y'all knew what I meant.
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.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
> 
--
Softaddicts sent by ibisMail from my ipad!

-- 
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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread Jim foo.bar
the general idiom with-some-resource means that resources will be 
cleared after leaving its scope. JUst like with 'with-open' which has a 
try/finally in order to .close() any closable resource upon exit. I've 
not used  clojure.java.jdbc but I suspect the same rationale applies for 
with-connection...


for example in one of my GUIs I have a 'with-busy-cursor' and a 
'with-block' macros. Every time an expensive operation happens on the 
gui I want a busy cursor but also I want my buttons to be non-reactive 
while the busy-cursor is visible (the user can click but nothing 
happens). so imagine i've got  the 'with-block' called from inside the 
'with-busy-cursor' and that removes all the boilerplate code for 
restoring the cursor and the reactive gui...


hope that helps...

Jim





On 09/11/12 17:42, larry google groups wrote:


Sorry this is such an ignorant question, but I am new to Clojure and 
the JVM. I am tring to find info about clojure.java.jdbc so I looked here:


http://corfield.org/blog/post.cfm/connecting-clojure-and-mysql

and saw this example:

(ns mysql.core
   (:require [clojure.java.jdbc :as sql]))

(def db {:classname "com.mysql.jdbc.Driver"
  :subprotocol "mysql"
  :subname "//localhost:3306/dbname"
  :user "dbuser"
  :password "secret"})

(defn list-users []
   (sql/with-connection db
 (sql/with-query-results rows
   ["select * from user"]
   (println rows
Can I assume thatsql/with-connection does some magic in the background to 
manage the connection? I would not want the connection to get shut down, and 
then restarted, everytime I run a query.


--
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: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread Sean Corfield
On Fri, Nov 9, 2012 at 9:42 AM, larry google groups
 wrote:
> Can I assume that sql/with-connection does some magic in the background to
> manage the connection? I would not want the connection to get shut down, and
> then restarted, everytime I run a query.

Use a connection pool. There's an example of c3p0 in the java.jdbc
documentation:

http://clojure.github.com/java.jdbc/

Specifically:

http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/ConnectionPooling.html
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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: [ANN] new book: "ClojureScript: Up and Running"

2012-11-09 Thread Ravindra Jaju
I see you guys have kept that margin for updates/fixes already.

The copyright notice talks about the year 2013. :)
" Copyright © 2013 Stuart Sierra, Luke VanderHart."

Anyway, looking forward to spending some time with the book!

-- 
jaju

On Fri, Nov 9, 2012 at 7:49 PM, Stuart Sierra
wrote:

> On Thursday, November 8, 2012 4:14:03 PM UTC-5, Robert Pitts wrote:
>>
>> Awesome. Would you say that this is essentially a completed work? Growing
>> weary or reading and re-reading beta books lately.
>
>
> Yes, the book is finished and out of beta.
>
> There may still be periodic updates and bug fixes to the eBook in the
> future.
>
> -S
>
> --
> 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

does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread larry google groups

Sorry this is such an ignorant question, but I am new to Clojure and the 
JVM. I am tring to find info about clojure.java.jdbc so I looked here:

http://corfield.org/blog/post.cfm/connecting-clojure-and-mysql

and saw this example:

(ns mysql.core
  (:require [clojure.java.jdbc :as sql]))

(def db {:classname "com.mysql.jdbc.Driver"
 :subprotocol "mysql"
 :subname "//localhost:3306/dbname"
 :user "dbuser"
 :password "secret"})

(defn list-users []
  (sql/with-connection db
(sql/with-query-results rows
  ["select * from user"]
  (println rows

Can I assume that sql/with-connection does some magic in the background to 
manage the connection? I would not want the connection to get shut down, and 
then restarted, everytime I run a query. 





-- 
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: Slow image convolution

2012-11-09 Thread Jim foo.bar
I thought 'definline' addresses exactly that...cases where one might 
want to pull out small pieces of first class functionality without 
sacrificing performance and without macros (which are not 
first-class)...am I mistaken?


Jim

ps: the only similarly big function that I've ever written (still 
smaller than this one) was for a GUI of mine and basically the Java 
interop caused it to be that big - it's not doing anything complicated 
like this one. I could not maintain such a function like the one shown 
here



On 09/11/12 17:32, Andy Fingerhut wrote:
Having worked on Clojure benchmarks on the Computer Language 
Benchmarks Game web site, that is sometimes the kind of Clojure code 
one needs to write if you want it to be as fast as it can be.


http://shootout.alioth.debian.org/u64q/compare.php?lang=clojure

Also, splitting it out into smaller chunks, if by that you mean 
functions, requires care in Clojure to avoid boxing and unboxing of 
primitive numbers.  It is possible, but can be an additional hurdle 
when trying to optimize code.  Macros can be better in that regard.


--
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: Slow image convolution

2012-11-09 Thread Andy Fingerhut
Having worked on Clojure benchmarks on the Computer Language Benchmarks Game 
web site, that is sometimes the kind of Clojure code one needs to write if you 
want it to be as fast as it can be.

http://shootout.alioth.debian.org/u64q/compare.php?lang=clojure

Also, splitting it out into smaller chunks, if by that you mean functions, 
requires care in Clojure to avoid boxing and unboxing of primitive numbers.  It 
is possible, but can be an additional hurdle when trying to optimize code.  
Macros can be better in that regard.

Another comment, Cedric: Consider writing that part of your code in Java and 
call it from Clojure.  Java is to Clojure as in-line assembler is to C, except 
that it isn't in-line :-)

Andy

On Nov 9, 2012, at 8:57 AM, Yakovlev Roman wrote:

> what a mess if it is a function it's huuge did you try split it to useful 
> chunks ? it's just unreadable and that's why you cann't spot anything i 
> guess..
> 
> пятница, 9 ноября 2012 г., 0:48:20 UTC+4 пользователь Cedric Greevey написал:
> I have the following code to perform a complicated image convolution. It 
> takes 10-15 seconds with output dimensions 256x256 and samples 6. No 
> reflection warnings, and using unchecked math doesn't speed it up any. I've 
> tried to ensure it uses primitive math inside the loops, aside from 
> generating the outer loop's values. What cached-load-chunk does shouldn't 
> matter much, but in most cases it should boil down to a map lookup inside a 
> swap! and a couple of atom derefs and function calls. The bottleneck is 
> likely in the math somewhere, and likely something is being boxed, though 
> I've primitive-coerced every numerical let and loop value and avoided more 
> than two arguments per arithmetic op.
> 
> Can anyone spot anything I haven't that could be causing boxed arithmetic 
> inside the loops?
> 
>   (let [^BufferedImage out (BufferedImage. width height 
> BufferedImage/TYPE_INT_BGR)
> half-w (double (/ width 2.0))
> half-h (double (/ height 2.0))
> lnk (double (- (* (Math/log 0.1) (inc l10-mag))
>(/ (Math/log (+ (* half-w half-w) (* half-h half-h))) 
> 2)))
> cconv (double (/ chunk-width (* 2.0 Math/PI)))
> c-base-ln (double (* chunk-base-mag (Math/log 0.1)))
> x-offset (double (* chunk-width (+ 0.5 (/ deg-rot 360
> fmtstr (str "%0" chunk-name-digits "d")
> cached-load-chunk (cached-objects
> (fn [chunk-num]
>   (maybe-load-image
> (str chunk-name-base
>  (format fmtstr (inc chunk-num)) 
> ".png"]
> (doseq [oy (range height) ox (range width)]
>   (let [ox (int ox)
> oy (int oy)
> ix (double (- ox half-w))
> iy (double (- oy half-h))
> samples (double samples)
> smo (int (dec samples))]
> (loop [sx (int 0) sy (int 0) ns (double 0)
>r (double 0) g (double 0) b (double 0)]
>   (if (== sy samples)
> (.setRGB out ox oy (int (+
>   (int (/ b ns))
>   (+ (* 256 (int (/ g ns)))
>  (* 65536 (int (/ r ns)))
> (let [nsx (int (if (== sx smo) 0 (inc sx)))
>   nsy (int (if (zero? nsx) (inc sy) sy))
>   ix (double (+ ix (/ (+ sx (rand)) samples)))
>   iy (double (+ iy (/ (+ sy (rand)) samples)))]
>   (if (and (== ix 0) (== iy 0))
> (recur nsx nsy ns r g b)
> (let [lnz-P (double (+ lnk (/ (Math/log (+ (* ix ix) (* iy 
> iy))) 2)))
>   argz-P (double (+ Math/PI (Math/atan2 iy ix)))
>   ; atan2 output range is -pi...pi and oy increases down 
> the screen
>   x (double (* argz-P cconv))
>   y (double (* (- c-base-ln lnz-P) cconv))
>   ;
>   chunk-num (int (/ y chunk-height))
>   chunk-x (int (rem (int (+ x x-offset)) chunk-width))
>   chunk-y (int (- y (* chunk-height chunk-num)))
>   ^BufferedImage chunk (cached-load-chunk chunk-num)
>   pixel (int (if chunk (.getRGB chunk chunk-x chunk-y) 0))
>   r (double (+ r (/ (bit-and pixel 0x00ff) 65536)))
>   g (double (+ g (/ (bit-and pixel 0xff00) 256)))
>   b (double (+ b (bit-and pixel 0x00ff)))]
>   (recur nsx nsy (inc ns) r g b
> 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 t

Re: Slow image convolution

2012-11-09 Thread Yakovlev Roman
what a mess if it is a function it's huuge did you try split it to useful 
chunks ? it's just unreadable and that's why you cann't spot anything i 
guess..

пятница, 9 ноября 2012 г., 0:48:20 UTC+4 пользователь Cedric Greevey 
написал:
>
> I have the following code to perform a complicated image convolution. It 
> takes 10-15 seconds with output dimensions 256x256 and samples 6. No 
> reflection warnings, and using unchecked math doesn't speed it up any. I've 
> tried to ensure it uses primitive math inside the loops, aside from 
> generating the outer loop's values. What cached-load-chunk does shouldn't 
> matter much, but in most cases it should boil down to a map lookup inside a 
> swap! and a couple of atom derefs and function calls. The bottleneck is 
> likely in the math somewhere, and likely something is being boxed, though 
> I've primitive-coerced every numerical let and loop value and avoided more 
> than two arguments per arithmetic op.
>
> Can anyone spot anything I haven't that could be causing boxed arithmetic 
> inside the loops?
>
>   (let [^BufferedImage out (BufferedImage. width height 
> BufferedImage/TYPE_INT_BGR)
> half-w (double (/ width 2.0))
> half-h (double (/ height 2.0))
> lnk (double (- (* (Math/log 0.1) (inc l10-mag))
>(/ (Math/log (+ (* half-w half-w) (* half-h 
> half-h))) 2)))
> cconv (double (/ chunk-width (* 2.0 Math/PI)))
> c-base-ln (double (* chunk-base-mag (Math/log 0.1)))
> x-offset (double (* chunk-width (+ 0.5 (/ deg-rot 360
> fmtstr (str "%0" chunk-name-digits "d")
> cached-load-chunk (cached-objects
> (fn [chunk-num]
>   (maybe-load-image
> (str chunk-name-base
>  (format fmtstr (inc chunk-num)) 
> ".png"]
> (doseq [oy (range height) ox (range width)]
>   (let [ox (int ox)
> oy (int oy)
> ix (double (- ox half-w))
> iy (double (- oy half-h))
> samples (double samples)
> smo (int (dec samples))]
> (loop [sx (int 0) sy (int 0) ns (double 0)
>r (double 0) g (double 0) b (double 0)]
>   (if (== sy samples)
> (.setRGB out ox oy (int (+
>   (int (/ b ns))
>   (+ (* 256 (int (/ g ns)))
>  (* 65536 (int (/ r ns)))
> (let [nsx (int (if (== sx smo) 0 (inc sx)))
>   nsy (int (if (zero? nsx) (inc sy) sy))
>   ix (double (+ ix (/ (+ sx (rand)) samples)))
>   iy (double (+ iy (/ (+ sy (rand)) samples)))]
>   (if (and (== ix 0) (== iy 0))
> (recur nsx nsy ns r g b)
> (let [lnz-P (double (+ lnk (/ (Math/log (+ (* ix ix) (* iy 
> iy))) 2)))
>   argz-P (double (+ Math/PI (Math/atan2 iy ix)))
>   ; atan2 output range is -pi...pi and oy increases 
> down the screen
>   x (double (* argz-P cconv))
>   y (double (* (- c-base-ln lnz-P) cconv))
>   ;
>   chunk-num (int (/ y chunk-height))
>   chunk-x (int (rem (int (+ x x-offset)) chunk-width))
>   chunk-y (int (- y (* chunk-height chunk-num)))
>   ^BufferedImage chunk (cached-load-chunk chunk-num)
>   pixel (int (if chunk (.getRGB chunk chunk-x chunk-y) 
> 0))
>   r (double (+ r (/ (bit-and pixel 0x00ff) 65536)))
>   g (double (+ g (/ (bit-and pixel 0xff00) 256)))
>   b (double (+ b (bit-and pixel 0x00ff)))]
>   (recur nsx nsy (inc ns) r g b
> 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: [ANN] ClojureScript release 0.0-1535 with G.Closure 0.0-2029

2012-11-09 Thread Sean Corfield
Nice!

I wonder how quickly lein-cljsbuild will get updated for this new
release? (Evan?)

Nice to see Leiningen and lein-cljsbuild introduced up front in your
book as the quickest way to get up and running, Stuart!

Sean

On Fri, Nov 9, 2012 at 6:17 AM, Stuart Sierra
 wrote:
> ClojureScript release 0.0-1535 is out. Get it in Leiningen:
>
> [org.clojure/clojurescript "0.0-1535"]
>
> Change log for this release:
> http://build.clojure.org/job/clojurescript-release/19/
>
> This release depends on the latest version of the Google Closure Library,
> r2029. You can also depend on it explicitly:
>
> [org.clojure/google-closure-library "0.0-2029"]
>
> ClojureScript does NOT depend directly on the Google Closure Library
> third-party extensions, but you can get it:
>
>  [org.clojure/google-closure-library-third-party "0.0-2029"]

-- 
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: Slow image convolution

2012-11-09 Thread Andy Fingerhut
I haven't determined exactly why that particular code is slow for you, but I 
have looked at it for a few minutes and have some suggestions:

1. In Clojure 1.3 and later, the default integer type for primitive arithmetic 
is long, not int.  Declaring things int means that they are really longs in the 
byte code, with type casts between long and int where needed.  Type casts 
between long and int are not slow, I'd guess, but wanted to mention this FYI.

2. I haven't followed all of the changes you have made to the code, but looked 
at the version in your original message of the thread.  There chunk-width and 
chunk-height are used in the inner loop, but have no let binding to cause them 
to be primitives, therefore are more likely to be boxed numbers and slow down 
the operations in which they are involved.  Maybe you already found and fixed 
this in your "I've now checked for Var lookups" message, but I can't tell from 
your message.

3. I have some hope that if I can find a decent Java decompiler, it will help 
in tracking these things down, by decompiling the .class files that Clojure can 
be compiled to back into Java source code.  If one is experienced in reading 
Java byte code, then a simpler Java disassembler is sufficient, but I'm not 
sure I want to learn to read Java byte codes that well.

I've tried the free JD-GUI, which produces output that looks like Java, but the 
tool seems to not handle Clojure loops very well.  I've gotten better results 
in a couple of small tests with the commercial AndroChef Java Decompiler 1.0, 
using a few of its 10 free trials.  I may purchase a copy for $24.99 after a 
few more trials if it looks good.  Seems to be Windows and GUI only.

>From a *brief* look at the Java decompiled by AndroChef for your original 
>code, wrapped in a function with untyped arguments for all of the unbound 
>symbols (see https://gist.github.com/4046744 ), it appears that perhaps 
>operations on a mix of doubles and longs don't use primitive arithmetic.  That 
>is a guess, mind you.  I haven't tried out smaller experiments to see whether 
>that is true in general, or whether it is something about this particular 
>function that causes that.

Andy


On Nov 8, 2012, at 6:50 PM, Cedric Greevey wrote:

> I can now add that the 30 taken by the cache lookup + .getRGB call is almost 
> entirely consumed by the latter. BufferedImage.getRGB is 50% slower than 
> rand. There's still about 380 billion cycles being spent on only around 3 
> billion numerical ops plus 100 million each of log and atan, though. Seems 
> excessive.
> 
> 
> 
> On Thu, Nov 8, 2012 at 8:38 PM, Cedric Greevey  wrote:
> So 100 million (rand) calls take 20 seconds. From temporarily changing 
> ^BufferedImage chunk (chunk-cache chunk-num) to ^BufferedImage chunk nil, I 
> determined that 100 million of the *combination* of the cache lookup (with no 
> misses) and the .getRGB call took 30. That still leaves just over two minutes 
> with only the arithmetic left in the loop. Either something's getting boxed 
> or it's the trig calls.
> 
> 
> 
> On Thu, Nov 8, 2012 at 8:18 PM, Cedric Greevey  wrote:
> (rand) is expensive -- removing the two (rand)s knocks about 40 seconds off 
> it, nearly 1/5 the total time. I'll try replacing them with lookup from a 
> precalculated grid of randoms -- long-range correlations shouldn't matter 
> here.
> 
> 
> 
> 
> On Thu, Nov 8, 2012 at 8:00 PM, Cedric Greevey  wrote:
> On Thu, Nov 8, 2012 at 3:48 PM, Cedric Greevey  wrote:
> I have the following code to perform a complicated image convolution. It 
> takes 10-15 seconds with output dimensions 256x256 and samples 6. No 
> reflection warnings, and using unchecked math doesn't speed it up any. I've 
> tried to ensure it uses primitive math inside the loops, aside from 
> generating the outer loop's values. What cached-load-chunk does shouldn't 
> matter much, but in most cases it should boil down to a map lookup inside a 
> swap! and a couple of atom derefs and function calls. The bottleneck is 
> likely in the math somewhere, and likely something is being boxed, though 
> I've primitive-coerced every numerical let and loop value and avoided more 
> than two arguments per arithmetic op.
> 
> Can anyone spot anything I haven't that could be causing boxed arithmetic 
> inside the loops?
> 
> I've now checked for Var lookups (none outside the caching function, and now 
> none inside either) and checked the caching code itself (there's a .get on a 
> closed-over ConcurrentHashMap, a null check, a .get on a SoftReference, and 
> another null check, on each lookup, if there isn't a cache miss on that 
> lookup; plus a couple more method calls for the IFn invokes and an ivar fetch 
> to get the ConcurrentHashMap reference).
> 
> In the absence of cache misses I'm still seeing ~3.5 *minutes* at 1280x720 
> with 10 samples (= about 100 million iterations total of the inner loop). The 
> arithmetic in there is 23 floating-point ops, five compares, a log, a

Re: Coding Standard - ns usage

2012-11-09 Thread Sean Corfield
On Fri, Nov 9, 2012 at 8:28 AM, Sean Corfield  wrote:
> On Thu, Nov 8, 2012 at 3:19 PM, Softaddicts  
> wrote:
>> Removing use would force us to redefine it somehow.
> (:use clojure.tools.trace) => (:require [clojure.tools.trace :refer :all)

*sigh* no paredit in Gmail and I haven't had my coffee yet:

(ns ...
  (:use clojure.tools.trace) => (:require [clojure.tools.trace :refer :all])
  ...)

but I'm sure y'all knew what I meant.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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: Coding Standard - ns usage

2012-11-09 Thread Sean Corfield
On Thu, Nov 8, 2012 at 3:19 PM, Softaddicts  wrote:
> Oh, I must say that I rarely use the Eclipse debugger. Tracing does most of 
> the job.
> Removing use would force us to redefine it somehow.

(:use clojure.tools.trace) => (:require [clojure.tools.trace :refer :all)
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Cedric Greevey
N could equal 1 under circumstances that make T small enough or d large
enough. T might be small for a tiny collection, or d large for a large
collection. Access pattern might matter, too. If a particular sequence of
inserts causes a lot of worst-case tree rotations or something, say, maybe
it could make the next insert particularly expensive to perform, but only
for a persistent collection. I'd have to dig into the actual implementation
to be more certain.

I'd expect that N will be greater than 1 for all but fairly atypical
circumstances, though, which fits with a few observations of transients
being faster for a tiny number of operations and many observations of
transients not being faster for a tiny number of operations.



On Fri, Nov 9, 2012 at 10:12 AM, Jim foo.bar  wrote:

> exactly the point I was trying to make! However, other peoples' experiment
> seem not to agree with that!
>
> Jim
>
>
>
> On 09/11/12 15:09, Cedric Greevey wrote:
>
>> In the real world, it's more complicated than that, and N could end up
>> not only depending on which transient operations and on vector vs. map but
>> even on details of the system hardware, Clojure version, and JVM version.
>> However it's likely to be a small integer in every case, so if you're doing
>> dozens or hundreds or more of operations, transients will generally help,
>> and if you're only doing one or two, don't bother.
>>
>
> --
> 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+unsubscribe@**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: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Jim foo.bar
exactly the point I was trying to make! However, other peoples' 
experiment seem not to agree with that!


Jim


On 09/11/12 15:09, Cedric Greevey wrote:
In the real world, it's more complicated than that, and N could end up 
not only depending on which transient operations and on vector vs. map 
but even on details of the system hardware, Clojure version, and JVM 
version. However it's likely to be a small integer in every case, so 
if you're doing dozens or hundreds or more of operations, transients 
will generally help, and if you're only doing one or two, don't bother.


--
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: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Cedric Greevey
It stands to reason that transients won't help given a small number of
operations. Consider a simplified model where conversion to transient and,
eventually, back to persistent takes a constant number of cycles T and
every operation on a transient takes exactly d cycles less than the
corresponding operation on a persistent. The savings from using transients
is then nd - T for n operations between making transient and making
persistent again. If d is much smaller than T then nd will be less than T
for the first several n, and using transients will be slower for n less
than some threshold N. (N = ceil(T/d) in fact.)

In the real world, it's more complicated than that, and N could end up not
only depending on which transient operations and on vector vs. map but even
on details of the system hardware, Clojure version, and JVM version.
However it's likely to be a small integer in every case, so if you're doing
dozens or hundreds or more of operations, transients will generally help,
and if you're only doing one or two, don't bother.


On Fri, Nov 9, 2012 at 7:27 AM, Softaddicts wrote:

> Ubuntu 12.04, java 6 32 bits
>
> Luc P.
>
>
> > This is weird...for just 2 operations I'm getting consistently better
> > timings with persistent than transients...
> >
> > user=> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
> > "Elapsed time: 240.247405 msecs"
> > nil
> > user=>
> > user=> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3
> > 4 5 6 7 8 9 0]) 3 5 6 8
> > "Elapsed time: 354.122806 msecs"
> > nil
> > user=> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
> > "Elapsed time: 188.765493 msecs"
> > nil
> > user=> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3
> > 4 5 6 7 8 9 0]) 3 5 6 8
> > "Elapsed time: 318.90242 msecs"
> > nil
> >
> > Jim
> >
> > ps: are you guys on java 1.7 ?
> >
> > On 09/11/12 02:29, Softaddicts wrote:
> > > Roughly... My FPU module is slow tonight
> > >
> > >
> > >> My own tests shows that the transient version is twice as fast:
> > >>
> > >> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
> > >> Elapsed time: 711.848312 msecs
> > >>
> > >> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 4 5
> 6 7 8 9 0]) 3 5 6 8
> > >> Elapsed time: 399.466556 msecs
> > >>
> > >> Luc P.
> > >>
> > >>> user=>  (use '[criterium.core])
> > >>> nil
> > >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a)) ;;2
> operations
> > >>>
> > >>> Evaluation count : 125829120 in 60 samples of 2097152 calls.
> > >>>Execution time mean : 488.826554 ns
> > >>>   Execution time std-deviation : 19.952095 ns
> > >>>  Execution time lower quantile : 459.910320 ns ( 2.5%)
> > >>>  Execution time upper quantile : 527.008269 ns (97.5%)
> > >>> nil
> > >>> user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0])
> 3
> > >>> nil 6 'a)))
> > >>> Evaluation count : 97399860 in 60 samples of 1623331 calls.
> > >>>Execution time mean : 639.789263 ns
> > >>>   Execution time std-deviation : 26.265080 ns
> > >>>  Execution time lower quantile : 597.753127 ns ( 2.5%)
> > >>>  Execution time upper quantile : 687.838668 ns (97.5%)
> > >>> nil
> > >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5)) ;;4
> > >>> operations
> > >>> Evaluation count : 68275920 in 60 samples of 1137932 calls.
> > >>>Execution time mean : 901.407416 ns
> > >>>   Execution time std-deviation : 35.682637 ns
> > >>>  Execution time lower quantile : 851.060950 ns ( 2.5%)
> > >>>  Execution time upper quantile : 970.492949 ns (97.5%)
> > >>>
> > >>> Found 1 outliers in 60 samples (1.6667 %)
> > >>>   low-severe 1 (1.6667 %)
> > >>>Variance from outliers : 25.4849 % Variance is moderately
> inflated by
> > >>> outliers
> > >>> nil
> > >>> user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0])
> 3
> > >>> nil 6 'a 0 "z" 2 5)))
> > >>> Evaluation count : 68844120 in 60 samples of 1147402 calls.
> > >>>Execution time mean : 893.798444 ns
> > >>>   Execution time std-deviation : 24.566655 ns
> > >>>  Execution time lower quantile : 848.307600 ns ( 2.5%)
> > >>>  Execution time upper quantile : 952.841308 ns (97.5%)
> > >>>
> > >>> Found 13 outliers in 60 samples (21.6667 %)
> > >>>   low-severe 7 (11.6667 %)
> > >>>   low-mild 6 (10. %)
> > >>>Variance from outliers : 14.2244 % Variance is moderately
> inflated by
> > >>> outliers
> > >>> nil
> > >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5 4
> (atom
> > >>> []) 7 "v")) ;;6 operations
> > >>> Evaluation count : 39783840 in 60 samples of 663064 calls.
> > >>>Execution time mean : 1.480511 us
> > >>>   Execution time std-deviation : 50.249443 ns
> > >>>  Execution time lower quantile : 1.425053 us ( 2.5%)
> > >>>  Execution time upper quantile : 1.591407

Re: [ANN] new book: "ClojureScript: Up and Running"

2012-11-09 Thread Stuart Sierra
On Thursday, November 8, 2012 4:14:03 PM UTC-5, Robert Pitts wrote:
>
> Awesome. Would you say that this is essentially a completed work? Growing 
> weary or reading and re-reading beta books lately.


Yes, the book is finished and out of beta.

There may still be periodic updates and bug fixes to the eBook in the 
future.

-S 

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

[ANN] ClojureScript release 0.0-1535 with G.Closure 0.0-2029

2012-11-09 Thread Stuart Sierra
ClojureScript release 0.0-1535 is out. Get it in Leiningen:

[org.clojure/clojurescript "0.0-1535"]

Change log for this release:
http://build.clojure.org/job/clojurescript-release/19/

This release depends on the latest version of the Google Closure Library, 
r2029. You can also depend on it explicitly:

[org.clojure/google-closure-library "0.0-2029"]

ClojureScript does NOT depend directly on the Google Closure Library 
third-party extensions, but you can get it:

 [org.clojure/google-closure-library-third-party "0.0-2029"]


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

is it possible to run `lein repl` without generating a `repl-port` file?

2012-11-09 Thread Satoru Logic
Hi, all.

I notice that in every directory that I have runed `lein repl`, a file 
named `repl-port`is generated.

I wonder if it's possible to set things up so that this file is not 
generated, or maybe I can set up some directory for these files.

-- 
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: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Softaddicts
Ubuntu 12.04, java 6 32 bits

Luc P.


> This is weird...for just 2 operations I'm getting consistently better 
> timings with persistent than transients...
> 
> user=> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
> "Elapsed time: 240.247405 msecs"
> nil
> user=>
> user=> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 
> 4 5 6 7 8 9 0]) 3 5 6 8
> "Elapsed time: 354.122806 msecs"
> nil
> user=> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
> "Elapsed time: 188.765493 msecs"
> nil
> user=> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 
> 4 5 6 7 8 9 0]) 3 5 6 8
> "Elapsed time: 318.90242 msecs"
> nil
> 
> Jim
> 
> ps: are you guys on java 1.7 ?
> 
> On 09/11/12 02:29, Softaddicts wrote:
> > Roughly... My FPU module is slow tonight
> >
> >
> >> My own tests shows that the transient version is twice as fast:
> >>
> >> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
> >> Elapsed time: 711.848312 msecs
> >>
> >> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 4 5 6 7 
> >> 8 9 0]) 3 5 6 8
> >> Elapsed time: 399.466556 msecs
> >>
> >> Luc P.
> >>
> >>> user=>  (use '[criterium.core])
> >>> nil
> >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a)) ;;2 operations
> >>>
> >>> Evaluation count : 125829120 in 60 samples of 2097152 calls.
> >>>Execution time mean : 488.826554 ns
> >>>   Execution time std-deviation : 19.952095 ns
> >>>  Execution time lower quantile : 459.910320 ns ( 2.5%)
> >>>  Execution time upper quantile : 527.008269 ns (97.5%)
> >>> nil
> >>> user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
> >>> nil 6 'a)))
> >>> Evaluation count : 97399860 in 60 samples of 1623331 calls.
> >>>Execution time mean : 639.789263 ns
> >>>   Execution time std-deviation : 26.265080 ns
> >>>  Execution time lower quantile : 597.753127 ns ( 2.5%)
> >>>  Execution time upper quantile : 687.838668 ns (97.5%)
> >>> nil
> >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5)) ;;4
> >>> operations
> >>> Evaluation count : 68275920 in 60 samples of 1137932 calls.
> >>>Execution time mean : 901.407416 ns
> >>>   Execution time std-deviation : 35.682637 ns
> >>>  Execution time lower quantile : 851.060950 ns ( 2.5%)
> >>>  Execution time upper quantile : 970.492949 ns (97.5%)
> >>>
> >>> Found 1 outliers in 60 samples (1.6667 %)
> >>>   low-severe 1 (1.6667 %)
> >>>Variance from outliers : 25.4849 % Variance is moderately inflated by
> >>> outliers
> >>> nil
> >>> user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
> >>> nil 6 'a 0 "z" 2 5)))
> >>> Evaluation count : 68844120 in 60 samples of 1147402 calls.
> >>>Execution time mean : 893.798444 ns
> >>>   Execution time std-deviation : 24.566655 ns
> >>>  Execution time lower quantile : 848.307600 ns ( 2.5%)
> >>>  Execution time upper quantile : 952.841308 ns (97.5%)
> >>>
> >>> Found 13 outliers in 60 samples (21.6667 %)
> >>>   low-severe 7 (11.6667 %)
> >>>   low-mild 6 (10. %)
> >>>Variance from outliers : 14.2244 % Variance is moderately inflated by
> >>> outliers
> >>> nil
> >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5 4 (atom
> >>> []) 7 "v")) ;;6 operations
> >>> Evaluation count : 39783840 in 60 samples of 663064 calls.
> >>>Execution time mean : 1.480511 us
> >>>   Execution time std-deviation : 50.249443 ns
> >>>  Execution time lower quantile : 1.425053 us ( 2.5%)
> >>>  Execution time upper quantile : 1.591407 us (97.5%)
> >>> nil
> >>> user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
> >>> nil 6 'a 0 "z" 2 5 4 (atom []) 7 "v")))
> >>> Evaluation count : 44755020 in 60 samples of 745917 calls.
> >>>Execution time mean : 1.358394 us
> >>>   Execution time std-deviation : 49.723547 ns
> >>>  Execution time lower quantile : 1.306456 us ( 2.5%)
> >>>  Execution time upper quantile : 1.473882 us (97.5%)
> >>> nil
> >>>
> >>> user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5 4 (atom
> >>> []) 7 "v" 5 1200 8 -)) ;;8 operations
> >>> Evaluation count : 31457280 in 60 samples of 524288 calls.
> >>>Execution time mean : 1.907389 us
> >>>   Execution time std-deviation : 74.523511 ns
> >>>  Execution time lower quantile : 1.822336 us ( 2.5%)
> >>>  Execution time upper quantile : 2.076044 us (97.5%)
> >>> nil
> >>> user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
> >>> nil 6 'a 0 "z" 2 5 4 (atom []) 7 "v" 5 1200 8 -)))
> >>> Evaluation count : 37739640 in 60 samples of 628994 calls.
> >>>Execution time mean : 1.623599 us
> >>>   Execution time std-deviation : 68.677518 ns
> >>>  Execution time lower quantile : 1.529454 us ( 2.5%)
> >>> 

Re: Polymorphism based on predicates instead of dispatch value types

2012-11-09 Thread Matt Ridsdale
Thanks for the pointer, I haven't seen it and I'll be sure to give it a 
look when I have some time.

Matt

On Thursday, November 8, 2012 11:29:12 AM UTC+1, Philip Potter wrote:
>
> Have you seen David Nolen's conj 2011 talk, "Predicate Dispatch"? It 
> covers exactly this material, but looks at trying to be somewhat more 
> efficient by not making method dispatch O(n) in the number of 
> implementations. At least as far as I understand it anyway. 
>
> http://lanyrd.com/2011/clojure-conj/shhfg/ 
>
> Phil 
>
> On 7 November 2012 18:08, Matt Ridsdale > 
> wrote: 
> > Hi, 
> > 
> > I was thinking about multimethods and the flexibility given by being 
> able to 
> > dispatch on the value of an arbitrary function of the arguments, 
> > instead of just the class of the first argument as in Java. It seems to 
> me 
> > that we could be even more flexible if each method implementation 
> > was associated with a predicate function of the args, instead of being 
> > associated with a fixed dispatch value. See the below code for an 
> example of 
> > what I mean: 
> > 
> > (ns polymorphism 
> >   (:use clojure.test)) 
> > 
> > (def pm-to-dispatch-pred-map (ref {})) 
> > 
> > ; these are kind of like multimethods, so let's give them a similar name 
> - 
> > polymethods. 
> > (defmacro defpoly [a-name [& args]] 
> >   "define a polymethod signature" 
> >   `(do 
> >  (defn ~a-name [~@args] 
> >  (let [dispatch-pred-to-impl-fn-map# (get 
> > @polymorphism/pm-to-dispatch-pred-map ~a-name) 
> >matching-keys# (filter #(apply % [~@args]) (keys 
> > dispatch-pred-to-impl-fn-map#)) 
> >num-matches# (count matching-keys#)] 
> >(case num-matches# 
> >  0 (throw (Exception. (str "No matching function defined for 
> > polymethod " ~a-name " and args " [~@args]))) 
> >  1 (apply (get dispatch-pred-to-impl-fn-map# (first 
> > matching-keys#)) [~@args]) 
> >  (throw (Exception. (str num-matches# " matching functions 
> > defined for polymethod " ~a-name " and args " [~@args])) 
> >(dosync (alter polymorphism/pm-to-dispatch-pred-map assoc ~a-name 
> > {} 
> > 
> > (defmacro defpolyimpl [a-name dispatch-pred & body] 
> >   "define a polymethod implementation, for a given dispatch predicate" 
> >   `(let [dispatch-pred-to-impl-fn-map# (get 
> > @polymorphism/pm-to-dispatch-pred-map ~a-name)] 
> >  (if (nil? dispatch-pred-to-impl-fn-map#) 
> >(throw (Exception. "No such polymethod: " ~a-name))) 
> >  (let [impl-fn# (fn ~@body)] 
> >(dosync (alter polymorphism/pm-to-dispatch-pred-map assoc ~a-name 
> > (assoc dispatch-pred-to-impl-fn-map# ~dispatch-pred impl-fn#))) 
> >~a-name))) 
> > 
> > 
> > (deftest polymorphism-test 
> >   (defpoly find-name [a-map]) 
> > 
> >   (defpolyimpl find-name 
> > #(and (contains? % :first-name) (contains? % :surname)) 
> > [a-map] 
> > (str (:first-name a-map) " "  (:surname a-map))) 
> > 
> >   (defpolyimpl find-name 
> > #(contains? % :full-name) 
> > [a-map] 
> > (:full-name a-map)) 
> > 
> >   (def personA {:first-name "John" :surname "Smith"}) 
> >   (def personB {:full-name "Jane Bloggs"}) 
> >   (is (= "John Smith" (find-name personA))) 
> >   (is (= "Jane Bloggs" (find-name personB 
> > 
> > (run-tests) 
> > 
> > I think this system of "dispatch predicates" instead of dispatch values 
> is 
> > more flexible/expressive, because you can easily emulate multimethods: 
> if 
> > your multimethod had dispatch function dispatch-fn and a dispatch value 
> > dispatch-val, you would use 
> >   #(isa? (apply dispatch-fn %&) dispatch-val) 
> > as the dispatch predicate. Whereas I can't see a simple way to express 
> an 
> > arbitrary set of "polymethods" in terms of multimethods. 
> > 
> > There are a few problems I can see with this approach, but none of them 
> seem 
> > to be dealbreakers to me: 
> > - You need to filter a list to determine the appropriate function 
> > implementation, whereas multimethods just look up the dispatch value in 
> a 
> > hash map. This could decrease performance if there are many 
> implementations. 
> > - In this version, they don't compose well: somebody could define a new 
> > implementation somewhere else which breaks your code, because two 
> dispatch 
> > predicates match the args you're using. We could get around this with 
> > something like prefer-method, or by remembering the order in which 
> > implementations are defined, and always taking the first/last one which 
> > matches the args. 
> > - Maybe this shouldn't be called polymorphism, since there is no notion 
> of 
> > type involved anywhere, except for the "types" defined by the 
> predicates. 
> > 
> > Is there anything wrong with this approach, or any particular reason it 
> > wasn't done this way in Clojure? 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this g

Re: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Jim - FooBar();
This is weird...for just 2 operations I'm getting consistently better 
timings with persistent than transients...


user=> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
"Elapsed time: 240.247405 msecs"
nil
user=>
user=> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 
4 5 6 7 8 9 0]) 3 5 6 8

"Elapsed time: 354.122806 msecs"
nil
user=> (time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
"Elapsed time: 188.765493 msecs"
nil
user=> (time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 
4 5 6 7 8 9 0]) 3 5 6 8

"Elapsed time: 318.90242 msecs"
nil

Jim

ps: are you guys on java 1.7 ?

On 09/11/12 02:29, Softaddicts wrote:

Roughly... My FPU module is slow tonight



My own tests shows that the transient version is twice as fast:

(time (dotimes [_ 100] (assoc [1 2 3 4 5 6 7 8 9 0] 3 5 6 8)))
Elapsed time: 711.848312 msecs

(time (dotimes [_ 100] (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 
0]) 3 5 6 8
Elapsed time: 399.466556 msecs

Luc P.


user=>  (use '[criterium.core])
nil
user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a)) ;;2 operations

Evaluation count : 125829120 in 60 samples of 2097152 calls.
   Execution time mean : 488.826554 ns
  Execution time std-deviation : 19.952095 ns
 Execution time lower quantile : 459.910320 ns ( 2.5%)
 Execution time upper quantile : 527.008269 ns (97.5%)
nil
user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
nil 6 'a)))
Evaluation count : 97399860 in 60 samples of 1623331 calls.
   Execution time mean : 639.789263 ns
  Execution time std-deviation : 26.265080 ns
 Execution time lower quantile : 597.753127 ns ( 2.5%)
 Execution time upper quantile : 687.838668 ns (97.5%)
nil
user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5)) ;;4
operations
Evaluation count : 68275920 in 60 samples of 1137932 calls.
   Execution time mean : 901.407416 ns
  Execution time std-deviation : 35.682637 ns
 Execution time lower quantile : 851.060950 ns ( 2.5%)
 Execution time upper quantile : 970.492949 ns (97.5%)

Found 1 outliers in 60 samples (1.6667 %)
  low-severe 1 (1.6667 %)
   Variance from outliers : 25.4849 % Variance is moderately inflated by
outliers
nil
user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
nil 6 'a 0 "z" 2 5)))
Evaluation count : 68844120 in 60 samples of 1147402 calls.
   Execution time mean : 893.798444 ns
  Execution time std-deviation : 24.566655 ns
 Execution time lower quantile : 848.307600 ns ( 2.5%)
 Execution time upper quantile : 952.841308 ns (97.5%)

Found 13 outliers in 60 samples (21.6667 %)
  low-severe 7 (11.6667 %)
  low-mild 6 (10. %)
   Variance from outliers : 14.2244 % Variance is moderately inflated by
outliers
nil
user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5 4 (atom
[]) 7 "v")) ;;6 operations
Evaluation count : 39783840 in 60 samples of 663064 calls.
   Execution time mean : 1.480511 us
  Execution time std-deviation : 50.249443 ns
 Execution time lower quantile : 1.425053 us ( 2.5%)
 Execution time upper quantile : 1.591407 us (97.5%)
nil
user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
nil 6 'a 0 "z" 2 5 4 (atom []) 7 "v")))
Evaluation count : 44755020 in 60 samples of 745917 calls.
   Execution time mean : 1.358394 us
  Execution time std-deviation : 49.723547 ns
 Execution time lower quantile : 1.306456 us ( 2.5%)
 Execution time upper quantile : 1.473882 us (97.5%)
nil

user=> (bench (assoc [1 2 3 4 5 6 7 8 9 0] 3 nil 6 'a 0 "z" 2 5 4 (atom
[]) 7 "v" 5 1200 8 -)) ;;8 operations
Evaluation count : 31457280 in 60 samples of 524288 calls.
   Execution time mean : 1.907389 us
  Execution time std-deviation : 74.523511 ns
 Execution time lower quantile : 1.822336 us ( 2.5%)
 Execution time upper quantile : 2.076044 us (97.5%)
nil
user=> (bench (persistent! (assoc! (transient [1 2 3 4 5 6 7 8 9 0]) 3
nil 6 'a 0 "z" 2 5 4 (atom []) 7 "v" 5 1200 8 -)))
Evaluation count : 37739640 in 60 samples of 628994 calls.
   Execution time mean : 1.623599 us
  Execution time std-deviation : 68.677518 ns
 Execution time lower quantile : 1.529454 us ( 2.5%)
 Execution time upper quantile : 1.777040 us (97.5%)

Found 1 outliers in 60 samples (1.6667 %)
  low-severe 1 (1.6667 %)
   Variance from outliers : 28.6901 % Variance is moderately inflated by
outliers
nil


etc etc...

you get the idea...conclusion: there is no real benefit to using
transients for less than 6 operations...

Jim




On 08/11/12 23:04, Philip Potter wrote:

Share the benchmark!

In theory, conversion to and from transients should be constant time
operations, but it would not surprise me if in practice transients
aren't universally faster than persistent.

Performance 

Re: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Jim - FooBar();

No I'm on Ubuntu 12.04 64bit, oracle-java 7,  clojure 1.4...

Jim

On 09/11/12 03:36, Herwig Hochleitner wrote:
Hmm, this is the second (unverified) report of transients being slower 
than persistents.


Jim, are you on OSX too, by chance? Which JVM?
--
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