Re: possible bug in `case'

2011-01-07 Thread Alex Osborne
"Eric Schulte"  writes:

> Hi,
>
> The following case statement
>
>   #+begin_src clojure
> (defn buggy-case [n]
>   (case (int n)
> 0  :null
> 1  :load
> 0x7000 :loproc))
>   #+end_src
>
> throws the following error
>
>   No distinct mapping found
> [Thrown class java.lang.IllegalArgumentException]
>
> However removing any of the cases alleviates the problem.  Am I missing
> something obvious, or is this a bug in the case statement?

Interesting!  I hadn't looked at how case was implemented before.  It
takes the keys and then finds a shift and bitmask which can be used to
differentiate them with a minimum number of contiguous bits.  The
private function clojure.core/min-hash is used to do this.  For example
if you have the case keys 0x400, 0x500 and 0x7700 then:

(min-hash [0x400 0x500 0x7700]) => [8 3]

Which means bit-shift-right by 8 bits and then bitwise-and by 3.  So if
we apply that to our keys we get:

(map #(shift-mask 8 3 %) [0x400 0x500 0x7700]) => (0 1 3)

The resulting values are then turned into a jump table which the
tableswitch JVM instruction dispatches on.

The maximum size of the mask is 14 bits, presumably as that's the
maximum the tableswitch instruction supports.

Now the problem in your case is there's no simple shift mask that is
unique.   If we write your keys in binary then the problem is obvious:

000
001
111
  ^-^

000
001
111
^-^

There's no way to position the 14-bit mask (the ^-^ in my
diagram) to obtain a unique result.

It looks like Java's switch statement falls back to the lookupswitch
instruction which is apparently usually implemented with a binary
search.  That doesn't seem to be implemented in Clojure and would in any
case be breaking the "constant time" contract the case macro's docstring
mentions (binary search is logarithmic time).

-- 
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: possible bug in `case'

2011-01-07 Thread Stuart Halloway
This is on the release roadmap for 1.3: 
http://dev.clojure.org/jira/browse/CLJ-426.

Volunteers welcome!

Stu

> Hi,
> 
> The following case statement
> 
>  #+begin_src clojure
>(defn buggy-case [n]
>  (case (int n)
>0  :null
>1  :load
>0x7000 :loproc))
>  #+end_src
> 
> throws the following error
> 
>  No distinct mapping found
>[Thrown class java.lang.IllegalArgumentException]
> 
> However removing any of the cases alleviates the problem.  Am I missing
> something obvious, or is this a bug in the case statement?
> 
> Thanks -- Eric
> 
> -- 
> 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: ANN: ClojureQL 1.0.0 now released

2011-01-07 Thread LauJensen
Hi Sean,

Half right - It will compile everytime, but not necessary create the
AST everytime:

(let [my-table (-> (table :user)
(select (where (= :id user-id)))
(project [:dateofbirth :gender :zipcode]))]
  (repeatedly @my-table))

However I see there are some good thoughts on optimization in this
thread already.
Perhaps is the AST always kept the SQL representation in a field, we
could totally
avoid re-compilation for repeat queries. That would still created the
preparedStatement,
but Im not sure thats a real time-stealer. I'll have to check.

On Jan 7, 1:33 am, Sean Corfield  wrote:
> On Thu, Jan 6, 2011 at 2:33 AM, LauJensen  wrote:
> > Yes the two statements are equivalent. ClojureQL compiles everything
> > to prepared
> > statements, with every argument automatically paramterized.
>
> Cool, that's what I'd hoped. But just to clarify...
>
> If I have code that repeatedly calls this:
>
> @(-> (table :user)
>     (select (where (= :id user-id)))
>     (project [:dateofbirth :gender :zipcode]))
>
> it is going to construct that AST and compile it to SQL every time it
> hits it, yes?
> --
> Sean A Corfield -- (904) 302-SEAN
> Railo Technologies, Inc. --http://getrailo.com/
> An Architect's View --http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: What am I not getting here?

2011-01-07 Thread new2clojure

Thank you all for your help, I appreciate it very much. I come from
the world of OO programming and I am bending my head backwards to try
to think in the functional paradigm.

Bellow you will find my version of Peter Norvig's spell checker
(http://norvig.com/spell-correct.html) in clojure, followed by the
java version. I coded the later first and then I attempted to
"translate" it. In a few months time I will try to implement it again
from scratch (in clojure) and I will be able to check my functional
mindset evolution.

Note: The reason for initializing the values of the dictionary to one
is explained in Norvig's essay

= C L O J U R E =

(ns SpellChecker)

;; Version of http://norvig.com/spell-correct.html by
'miguel.arre...@gmail.com'
;; 7th January 2011

(import (java.io BufferedReader FileReader))

(defn build-dictionary [file-name]
  "Returns a \"dictionary{'word'} = frequency\" mapping
   each of the words in the file pointed to by 'file-name' to the
   number of its occurrences.
   Thank you 'Jason Wolfe' for the hints on how to produce the
dictionary
   (http://groups.google.com/group/clojure/browse_thread/thread/
a1265d60229b8cd5)"
  (with-open [rdr (BufferedReader. (FileReader. file-name))]
(reduce #(assoc %1 %2 (inc (get %1 %2 1)))
  {}
  (mapcat
#(re-seq #"[a-z]+" (.toLowerCase %))
(line-seq rdr)

(defn- alpha []
  "Explicit alphabet a-z (English)"
  "abcdefghijklmnopqrstuvwxyz")

(defn- deletes [word]
  "Words derivated from word which are missing a letter"
  (for [i (range (count word))] (str (subs word 0 i) (subs word (inc
i)

(defn- transposes [word]
  "Words derivated from word in which two adjacent letters are
swapped"
  (for [i (range (dec (count word)))]
(let [i1 (inc i), i2 (inc i1)]
(str (subs word 0 i) (subs word i1 i2) (subs word i i1) (subs
word i2)

(defn- replaces [word]
  "Words derivated from word which are miss-spelled by one letter"
  (for [i (range (count word)), j (alpha)]
(str (subs word 0 i) j (subs word (inc i)

(defn- inserts [word]
  "Words derivated from word which contain an additional letter"
  (for [i (range (count word)), j (alpha)]
(str (subs word 0 i) j (subs word i

(defn variations [word]
  "Returns all the words at edit distance 1 from word
   (includes: deletes, transposes, replaces and inserts)"
  (concat (replaces word) (inserts word) (deletes word) (transposes
word)))

(defn check [dict word]
  "Checks the word agains the dictionary, returning the variation
   at edit distances 1 and 2 that has the highest frequency (may be
   the word itself if not found in the dictionary)"
  (if (dict word)
word
(let [edit1 (distinct (filter #(dict %) (variations word))),
  edit2 (distinct (filter #(dict %) (map #(variations %)
edit1))),
  candidates (reduce #(assoc %1 (dict %2 0) %2) (sorted-map-by
>) (into edit1 edit2))]
   (if (empty? candidates) word (val (first candidates))

;; Main

(def dictionary (build-dictionary "big.txt"))
(check dictionary "amunition")

;; End


= J A V A =

package power;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class SpellChecker {

private Map dictionary;


public SpellChecker (String fileName) throws IOException {

File fileHndl = new File(fileName);
System.err.println(String.format(
"Loading dictionary '%s' (%d bytes)",
fileName, fileHndl.length()
));
long startTime = System.currentTimeMillis();
dictionary = new HashMap();
BufferedReader in = new BufferedReader(new 
FileReader(fileName));
Pattern pattern = Pattern.compile("\\w+");
for (String line=null; null != (line=in.readLine()); ) {

Matcher matcher = pattern.matcher(line.toLowerCase());
while (matcher.find()) {

String word = matcher.group();
Integer frequency = dictionary.get(word);
if (null == frequency) {

frequency = Integer.valueOf(1);
}
else {

frequency = 
Integer.valueOf(frequency.intValue() + 1);
}
dictionary.put(word, frequency);
}
}
in.close();
System.err.println(String.format(
"Loaded, %d entries, %d millis",
dictionary.

Re: What am I not getting here?

2011-01-07 Thread Baishampayan Ghose
> Bellow you will find my version of Peter Norvig's spell checker
> (http://norvig.com/spell-correct.html) in clojure, followed by the
> java version. I coded the later first and then I attempted to
> "translate" it. In a few months time I will try to implement it again
> from scratch (in clojure) and I will be able to check my functional
> mindset evolution.

For comparison, take a look at this version written by none other than
Rich Hickey himself -
http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Norvig_Spelling_Corrector

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Midje 0.9 released #testing

2011-01-07 Thread Brian Marick
Midje  provides a migration path from 
clojure.test to a more flexible, readable, abstract, and gracious style of 
testing. 

The 0.9 release mainly provides useful checkers for "collection-like things" 
(collections and strings). Checkers are single-argument functions that produce 
truth values:

(facts "about prime numbers"
   (first (primes)) => even?
   (second (primes)) => odd?)

Here are examples of the new checkers:

user> (fact "the quick brown fox" => (has-suffix "fox"))
true

;; I've tried to make diagnostics useful:
user> (fact "where is the animal?" => (contains "hen"))

FAIL at (NO_SOURCE_FILE:1)
Actual result did not agree with the checking function.
   Actual result: "where is the animal?"
   Checking function: (contains "hen")
   The checker said this about the reason:
  Best match found: [\h \e]
false

;; You can tell the checkers to ignore order or gaps:

user> (fact "where is the animal?" => (contains "hen" :gaps-ok))
true
user> (fact "where is the animal?" => (contains "lama" :in-any-order :gaps-ok))
true
;; "Lama" is too a valid alternate spelling of "llama".


;; The same checkers work on collections:

user> (fact [4 'h "regex" 2] => (contains [2 #"re" 4] :in-any-order :gaps-ok))
true

;; You can use checkers within checkers:

user> (fact {:a 1 :b 3 :c 5} => (just {:a odd? :b odd? :c odd?}))
true


... and so on. You can find a complete description here:
https://github.com/marick/Midje/wiki/Checkers-for-collections-and-strings

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Author of /Ring/ (forthcoming; sample: http://bit.ly/hfdf9T)
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

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

2011-01-07 Thread Trevor
What's the best way to kick off Clojure code at scheduled times? I
have some that would run once a day. Some that might run 2 or 3 times
a day based upon a test being met.

1. I could write a function that sleeps an interval, check the time
differential to perform a time-box triggered function, but would that
consume too much memory?, cause long term problems?

2. I could use quartz, but that seems like overkill.

3. I could set a job-schedule using the OS to run a clojure script.
I'd rather not, I would like to do things like send emails / check
status via web app (making option 1 more appealing).

I'm looking for input/guidance. What are your experiences?

Thanks,

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Boston meetup Jan 11?

2011-01-07 Thread Eric Kobrin
Jeff posted this in a separate thread. We'll be hosting a meetup on
the 13th:

1st Boston Clojure Meetup

Date:  Thursday, January 13th, 2011

Location:  Akamai Technologies
8 Cambridge Center
Conference Room 200D
Cambridge, MA 02142
(Corner of Broadway and Galileo Galilei)

Akamai Technologies will be hosting the first Boston Clojure
Meetup on Thursday, January 13th.  This will be an opportunity
for local Clojure enthusiasts to gather and discuss topics of
interest to the Clojure community. For this first meeting,
Jeffrey Straszheim will be presenting his Dataflow library from
Clojure Contrib.

Please forward this meeting invitation to anyone you know who
might be interested.

Agenda:

6:307:00   Informal Meet & Greet
7:007:15   Introduction - Eric Kobrin
7:157:30   Future Meetup Topics and Locations
7:408:00   Dataflow in Clojure - Jeffrey Straszheim
8:00-  Drinks at CBC on your own

If you have any questions, please contact:

Eric Kobrin 
617-444-3951(office)
786-261-7093(cell)


On Jan 6, 1:50 pm, rob levy  wrote:
> I'm also going to Boston Coding Dojo tonight.  The Clojure Meetup is going
> to be at Akamai, a week from tonight's dojo, which I'm looking forward 
> to:http://groups.google.com/group/clojure/browse_thread/thread/821248c3d...
>
> On Thu, Dec 30, 2010 at 9:34 PM, Alyssa Kwan wrote:
>
> > Hi!
>
> > You would be more than welcome at the Boston Coding Dojo (http://
> >www.meetup.com/boston-coding-dojo/).  We meet every other Thursday at
> > First Church in Boston, in Boston's Back Bay on Marlborough St.  In
> > January, we are meeting on 1/6 and 1/20, so nothing on the week of
> > 1/9, I'm afraid.  What kind of meeting do you have in mind?  I could
> > certainly recommend some restaurants that are more conducive to
> > conversation.  If you are looking for a space to hack, I can certainly
> > check with the church for availability; we meet in a lovely chapel
> > with plenty of room.  It would cost $75 for the space for the night.
> > There's also the Workbar (http://www.workbarboston.com), which is
> > pricier and a little more cramped... :).
>
> > Everyone on the list should also check out Boston Software
> > Craftsmanship (http://groups.google.com/group/boston-software-
> > craftsmanship/).  Their next meeting is on 1/24 and is on monads
> > (http://gathers.us/events/jan-boston-software-craftsmanship-meeting).
>
> > Thanks!
> > Alyssa
>
> > On Dec 30, 1:52 pm, dysinger  wrote:
> > > 10 of us from Sonian are going to converge on Boston the week of Jan
> > > 9.  It's always awesome to meet other Clojure hackers. I propose we
> > > meet up somewhere central(ish) Jan 11 @ 7-9pm-ish.  We have room at
> > > our company headquarters in Dedham but that might be a hike for some
> > > people.  Any other places we could meet/greet & hack for an hour or
> > > two central to Boston?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure job scheduler

2011-01-07 Thread gaz jones
the work library has a function which it describes as 'cron for
clojure functions':

https://github.com/clj-sys/work.git

cant say i have used it, but i noticed it in there recently whilst
looking for other things.

here is the function:

(defn schedule-work
  "schedules work. cron for clojure fns. Schedule a single fn with a
pool to run every n seconds,
where n is specified by the rate arg, or supply a vector of fn-rate
tuples to schedule a bunch of fns at once."
  ([f rate]
 (let [pool (Executors/newSingleThreadScheduledExecutor)]
 (.scheduleAtFixedRate
  pool (with-log f) (long 0) (long rate) TimeUnit/SECONDS)
 pool))
  ([jobs]
 (let [pool (Executors/newSingleThreadScheduledExecutor)]
   (doall (for [[f rate] jobs]
(schedule-work pool f rate)))
   pool)))

hope that is useful,
cheers
gaz

On Fri, Jan 7, 2011 at 11:13 AM, Trevor  wrote:
> What's the best way to kick off Clojure code at scheduled times? I
> have some that would run once a day. Some that might run 2 or 3 times
> a day based upon a test being met.
>
> 1. I could write a function that sleeps an interval, check the time
> differential to perform a time-box triggered function, but would that
> consume too much memory?, cause long term problems?
>
> 2. I could use quartz, but that seems like overkill.
>
> 3. I could set a job-schedule using the OS to run a clojure script.
> I'd rather not, I would like to do things like send emails / check
> status via web app (making option 1 more appealing).
>
> I'm looking for input/guidance. What are your experiences?
>
> Thanks,
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ANN: ClojureQL 1.0.0 now released

2011-01-07 Thread Feng
I'd suggest ClojureQL only optimize lisp form to SQL text
transformation, and provide options whether to use PreparedStatement
or not. Leave other kind of optimizations to databases/drivers.

Some thoughts below:

- PreparedStatement avoids high cost of frequent query planning
(oracle call it hard parsing) and SQL injection, which are critical
for OLTP workload. However, it's not always good practice for
datawarehousing queries. In some high end databases, query planner
need to see join and filter conditions as constant for the best query
planning (e.g. leveraging histogram, partition statistics).  ClojureQL
can provide controls to evaluate clojure variables right before
creating SQL string. Not sure about whether at variable level, or
statement level, or connection level though. I can see various trade-
offs (simplicity vs flexibility etc).

- Client side JDBC Statement caching should leave to db Driver, or
DataSource implementations. Most of high end database and JEE
appserver do, with various trade-offs and complexities. I think
ClojureQL should stay away from them.

BTW, great library and fun to use!

On Jan 7, 6:23 am, LauJensen  wrote:
> Hi Sean,
>
> Half right - It will compile everytime, but not necessary create the
> AST everytime:
>
> (let [my-table (-> (table :user)
>     (select (where (= :id user-id)))
>     (project [:dateofbirth :gender :zipcode]))]
>   (repeatedly @my-table))
>
> However I see there are some good thoughts on optimization in this
> thread already.
> Perhaps is the AST always kept the SQL representation in a field, we
> could totally
> avoid re-compilation for repeat queries. That would still created the
> preparedStatement,
> but Im not sure thats a real time-stealer. I'll have to check.
>
> On Jan 7, 1:33 am, Sean Corfield  wrote:
>
> > On Thu, Jan 6, 2011 at 2:33 AM, LauJensen  wrote:
> > > Yes the two statements are equivalent. ClojureQL compiles everything
> > > to prepared
> > > statements, with every argument automatically paramterized.
>
> > Cool, that's what I'd hoped. But just to clarify...
>
> > If I have code that repeatedly calls this:
>
> > @(-> (table :user)
> >     (select (where (= :id user-id)))
> >     (project [:dateofbirth :gender :zipcode]))
>
> > it is going to construct that AST and compile it to SQL every time it
> > hits it, yes?
> > --
> > Sean A Corfield -- (904) 302-SEAN
> > Railo Technologies, Inc. --http://getrailo.com/
> > An Architect's View --http://corfield.org/
>
> > "If you're not annoying somebody, you're not really alive."
> > -- Margaret Atwood

-- 
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: ClojureQL 1.0.0 now released

2011-01-07 Thread Rick Mouritzen
A prepared statement is something inside a database. The true object
isn't part of JDBC or a JDBC driver.

So you open a connection, then create your SQL using JDBC's
PreparedStatement to tell the DB to use a prepared statement. Next
time that same SQL is used with another JDBC PreparedStatement, the DB
will do it's magic.

Re-using a single PreparedStatement within a Connection is something
you can only do with one Connection on one thread. Generally it's not
worth over-thinking. Using batching is where you really see
performance gains.

This is all separate from parsing from ClojureQL to SQL/JDBC, of course.


On Fri, Jan 7, 2011 at 10:22 AM, Feng  wrote:
> I'd suggest ClojureQL only optimize lisp form to SQL text
> transformation, and provide options whether to use PreparedStatement
> or not. Leave other kind of optimizations to databases/drivers.
>
> Some thoughts below:
>
> - PreparedStatement avoids high cost of frequent query planning
> (oracle call it hard parsing) and SQL injection, which are critical
> for OLTP workload. However, it's not always good practice for
> datawarehousing queries. In some high end databases, query planner
> need to see join and filter conditions as constant for the best query
> planning (e.g. leveraging histogram, partition statistics).  ClojureQL
> can provide controls to evaluate clojure variables right before
> creating SQL string. Not sure about whether at variable level, or
> statement level, or connection level though. I can see various trade-
> offs (simplicity vs flexibility etc).
>
> - Client side JDBC Statement caching should leave to db Driver, or
> DataSource implementations. Most of high end database and JEE
> appserver do, with various trade-offs and complexities. I think
> ClojureQL should stay away from them.
>
> BTW, great library and fun to use!
>
> On Jan 7, 6:23 am, LauJensen  wrote:
>> Hi Sean,
>>
>> Half right - It will compile everytime, but not necessary create the
>> AST everytime:
>>
>> (let [my-table (-> (table :user)
>>     (select (where (= :id user-id)))
>>     (project [:dateofbirth :gender :zipcode]))]
>>   (repeatedly @my-table))
>>
>> However I see there are some good thoughts on optimization in this
>> thread already.
>> Perhaps is the AST always kept the SQL representation in a field, we
>> could totally
>> avoid re-compilation for repeat queries. That would still created the
>> preparedStatement,
>> but Im not sure thats a real time-stealer. I'll have to check.
>>
>> On Jan 7, 1:33 am, Sean Corfield  wrote:
>>
>> > On Thu, Jan 6, 2011 at 2:33 AM, LauJensen  
>> > wrote:
>> > > Yes the two statements are equivalent. ClojureQL compiles everything
>> > > to prepared
>> > > statements, with every argument automatically paramterized.
>>
>> > Cool, that's what I'd hoped. But just to clarify...
>>
>> > If I have code that repeatedly calls this:
>>
>> > @(-> (table :user)
>> >     (select (where (= :id user-id)))
>> >     (project [:dateofbirth :gender :zipcode]))
>>
>> > it is going to construct that AST and compile it to SQL every time it
>> > hits it, yes?
>> > --
>> > Sean A Corfield -- (904) 302-SEAN
>> > Railo Technologies, Inc. --http://getrailo.com/
>> > An Architect's View --http://corfield.org/
>>
>> > "If you're not annoying somebody, you're not really alive."
>> > -- Margaret Atwood
>
> --
> 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


REPL+Laziness: the worst combination ever!

2011-01-07 Thread Nicolas Buduroi
I've been doing a lot of Clojure lately and, of all thing,
collection's laziness coupled with a REPL is what makes me loose the
most time. I really love having laziness built-in by default and I'm a
REPL-driven development addict, but sometimes I just loose minutes (if
not hours) chasing imaginary bugs that in the end only were a misuse
of laziness at the REPL. Still, I can't think of any way of fixing
this problem other than writing on top of my monitor: "If it doesn't
make sense it's certainly because of laziness". I wonder what other
people think about this problem?

P.S.: While writing this I just got an idea, but I'm not really sure
it's a good one. Would it be wise to make the binding macro force
evaluation of its body? That would be the most common mistake I 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: ANN: ClojureQL 1.0.0 now released

2011-01-07 Thread Feng


On Jan 7, 7:36 pm, Rick Mouritzen  wrote:
> A prepared statement is something inside a database. The true object
> isn't part of JDBC or a JDBC driver.

Some JDBC drivers and JEE Datasources (all Oracle and IBM products) do
cache stmt per connection (i.e. stmt.close() doesn't really close it,
just put it back to cache). The cache is just a ConcurrentHashMap of
SQL text to stmt object , with some MRU or MFU algorithm.

>
> So you open a connection, then create your SQL using JDBC's
> PreparedStatement to tell the DB to use a prepared statement. Next
> time that same SQL is used with another JDBC PreparedStatement, the DB
> will do it's magic.

In Oracle, this causes a soft parsing hitting db server library cache,
lot less overhead compare to hard parsing. But, in extremely high
concurrent (100s threads) pushing high frequent short transactions.
Latch contention on db library cache can be scalability killer. JDBC
client side stmt cache reduces the contention significantly in same
cases. The situation is rare, but I did see > 50% throughput increase
by tuning stmt caching in two systems I worked on.

Agreed ClojureQL should not be bothered with this. Just to clarify the
point.

>
> Re-using a single PreparedStatement within a Connection is something
> you can only do with one Connection on one thread. Generally it's not
> worth over-thinking. Using batching is where you really see
> performance gains.
>
> This is all separate from parsing from ClojureQL to SQL/JDBC, of course.
>
>
>
>
>
>
>
> On Fri, Jan 7, 2011 at 10:22 AM, Feng  wrote:
> > I'd suggest ClojureQL only optimize lisp form to SQL text
> > transformation, and provide options whether to use PreparedStatement
> > or not. Leave other kind of optimizations to databases/drivers.
>
> > Some thoughts below:
>
> > - PreparedStatement avoids high cost of frequent query planning
> > (oracle call it hard parsing) and SQL injection, which are critical
> > for OLTP workload. However, it's not always good practice for
> > datawarehousing queries. In some high end databases, query planner
> > need to see join and filter conditions as constant for the best query
> > planning (e.g. leveraging histogram, partition statistics).  ClojureQL
> > can provide controls to evaluate clojure variables right before
> > creating SQL string. Not sure about whether at variable level, or
> > statement level, or connection level though. I can see various trade-
> > offs (simplicity vs flexibility etc).
>

In previous version a while ago, ClojureQL seems always use Statement
with var values inlined into SQL text. This is actually good for data
warehousing queries.
Maybe just introduce a flag :use-prepared (default true) in db config
object,  bring back old implementation when set it to false?
It's rarely seen mixed OLTP and ad hoc analytical queries to a single
database, so this will cover both use cases well. Stmt or var level
control may destroy elegancy of ClojureQL API, which is less
desirable.

> > - Client side JDBC Statement caching should leave to db Driver, or
> > DataSource implementations. Most of high end database and JEE
> > appserver do, with various trade-offs and complexities. I think
> > ClojureQL should stay away from them.
>
> > BTW, great library and fun to use!
>
> > On Jan 7, 6:23 am, LauJensen  wrote:
> >> Hi Sean,
>
> >> Half right - It will compile everytime, but not necessary create the
> >> AST everytime:
>
> >> (let [my-table (-> (table :user)
> >>     (select (where (= :id user-id)))
> >>     (project [:dateofbirth :gender :zipcode]))]
> >>   (repeatedly @my-table))
>
> >> However I see there are some good thoughts on optimization in this
> >> thread already.
> >> Perhaps is the AST always kept the SQL representation in a field, we
> >> could totally
> >> avoid re-compilation for repeat queries. That would still created the
> >> preparedStatement,
> >> but Im not sure thats a real time-stealer. I'll have to check.
>
> >> On Jan 7, 1:33 am, Sean Corfield  wrote:
>
> >> > On Thu, Jan 6, 2011 at 2:33 AM, LauJensen  
> >> > wrote:
> >> > > Yes the two statements are equivalent. ClojureQL compiles everything
> >> > > to prepared
> >> > > statements, with every argument automatically paramterized.
>
> >> > Cool, that's what I'd hoped. But just to clarify...
>
> >> > If I have code that repeatedly calls this:
>
> >> > @(-> (table :user)
> >> >     (select (where (= :id user-id)))
> >> >     (project [:dateofbirth :gender :zipcode]))
>
> >> > it is going to construct that AST and compile it to SQL every time it
> >> > hits it, yes?
> >> > --
> >> > Sean A Corfield -- (904) 302-SEAN
> >> > Railo Technologies, Inc. --http://getrailo.com/
> >> > An Architect's View --http://corfield.org/
>
> >> > "If you're not annoying somebody, you're not really alive."
> >> > -- Margaret Atwood
>
> > --
> > 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 

distributeted computing newby, clojure ...

2011-01-07 Thread Nick Zbinden
Hallo,

I would like to talk about two things.

General:

I have a small project that has really easy to paralyzable problem so
I think that a good place to start with parallel programming. Doning
it on one pc is simple in clojure. So I tought to myself: You can
distribute that. I have never done anything like that bevor (not in
clojure or any other language).

So I wanted to ask people. Have you done distributed stuff in clojure?
Whats the easiest way distribute? Are there librarys to help or should
I start reading into Java Distributet librarys?

My Project:

I think I quickly explain my project. Think you have pool of something
(for example diffrent fighters for a game). I want to find out witch
one is the best. So I want to write a function that takes some
fighters and a function to compair two of the fighters and a function
that decides how to play it out (K.O.-Mode, All-Vs-All, Playoff
Style).

To make this multithread my take on this would be to generat a future
for every fight and then just do you match and deref if you need a
winner. (is this a good idea?)

(Warning the stuff I take about now is just guessing correct me if I
talk total nosence)
To distribut this I would have to need something like an Pool of
Workers or some kind of executer that handles that stuff. My thinking
was I could provid the executer as an I argument (the futures would
just be send in to the executer the executer then decides to run it
with normal threads or do distributed work.

This would be a general library to find out the best of anything. In
my example fighter with diffrent attribut configurations.

Love to hear your thoughts.

-- 
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: Midje 0.9 released #testing

2011-01-07 Thread Alex Baranosky
Thanks Brian, I for one love Midje.

-- 
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: ClojureQL 1.0.0 now released

2011-01-07 Thread Sean Corfield
On Fri, Jan 7, 2011 at 3:23 AM, LauJensen  wrote:
> Half right - It will compile everytime, but not necessary create the
> AST everytime:
>
> (let [my-table (-> (table :user)
>    (select (where (= :id user-id)))
>    (project [:dateofbirth :gender :zipcode]))]
>  (repeatedly @my-table))

Interesting approach. I hadn't thought of a way to reuse a query in
the context of the app I'm working with but that gives me some ideas
about rethinking things. Thanx.
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure job scheduler

2011-01-07 Thread Michael Gardner
On Jan 7, 2011, at 11:13 AM, Trevor wrote:

> 3. I could set a job-schedule using the OS to run a clojure script.
> I'd rather not, I would like to do things like send emails / check
> status via web app (making option 1 more appealing).

Could you elaborate on why a scheduled job to run a Clojure script would be 
inappropriate for those kinds of tasks? Anything you can do from a daemon, you 
should be able to do from a cron job.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure job scheduler

2011-01-07 Thread Ken Wesson
On Fri, Jan 7, 2011 at 9:35 PM, Michael Gardner  wrote:
> On Jan 7, 2011, at 11:13 AM, Trevor wrote:
>
>> 3. I could set a job-schedule using the OS to run a clojure script.
>> I'd rather not, I would like to do things like send emails / check
>> status via web app (making option 1 more appealing).
>
> Could you elaborate on why a scheduled job to run a Clojure script would be 
> inappropriate for those kinds of tasks? Anything you can do from a daemon, 
> you should be able to do from a cron job.

Let's see. On the one hand, running a job scheduler from inside
Clojure results in cranking up a big, slow to start up, expensive JVM
process once a session, on startup, which then runs some tasks
periodically, and the scheduling itself can be done in a nice language
like, say, Clojure, with nice error reporting.

On the other hand, running a job scheduler from outside Clojure
results in cranking up a big, slow to start up, expensive JVM process
every single time a task needs to run, each of which runs one task
once, and the scheduling itself must be done in an icky language like
shell or cron's idiosyncratic "crontab" files with icky error
reporting (e.g., need to run a local mail *server* to receive error
notifications).

I think I can see why someone might prefer to have the scheduling done
inside the 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


Re: REPL+Laziness: the worst combination ever!

2011-01-07 Thread Alan
I do this too on occasion, and my opinion is: better to chase them in
the REPL than in deployed code, because the same problem would usually
come up there.

On Jan 7, 5:03 pm, Nicolas Buduroi  wrote:
> I've been doing a lot of Clojure lately and, of all thing,
> collection's laziness coupled with a REPL is what makes me loose the
> most time. I really love having laziness built-in by default and I'm a
> REPL-driven development addict, but sometimes I just loose minutes (if
> not hours) chasing imaginary bugs that in the end only were a misuse
> of laziness at the REPL. Still, I can't think of any way of fixing
> this problem other than writing on top of my monitor: "If it doesn't
> make sense it's certainly because of laziness". I wonder what other
> people think about this problem?
>
> P.S.: While writing this I just got an idea, but I'm not really sure
> it's a good one. Would it be wise to make the binding macro force
> evaluation of its body? That would be the most common mistake I 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: Clojure job scheduler

2011-01-07 Thread Michael Gardner
On Jan 7, 2011, at 9:19 PM, Ken Wesson wrote:

> On the other hand, running a job scheduler from outside Clojure
> results in cranking up a big, slow to start up, expensive JVM process
> every single time a task needs to run, each of which runs one task
> once, and the scheduling itself must be done in an icky language like
> shell or cron's idiosyncratic "crontab" files with icky error
> reporting (e.g., need to run a local mail *server* to receive error
> notifications).

If you care about startup times, you can use nailgun. But that shouldn't matter 
unless you're running the job every minute or something.

As for scheduling, crontabs are really not hard to figure out. If you need more 
complex scheduling, you can do that from your Clojure script (essentially using 
cron to set the polling interval).

And what kinds of error reporting could you do from a persistent daemon that 
you couldn't also do from a cron job? Besides, most systems that have cron also 
come with postfix (though it's disabled by default on Mac OS X), so all you 
have to do is add your email address to /etc/aliases. Email-based error 
reporting for background tasks is really nice because you don't have to 
remember to check some log file or other task-specific status indicator 
periodically (which has burned me in the past).

But this is all somewhat beside the point. What Trevor said sounded as though 
the specific types of tasks he mentioned (sending emails and checking some kind 
of status via web app) were particularly unsuited to scheduled jobs; I was 
asking what it was about those tasks in particular that made him lean towards a 
daemon instead.

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