Re: get the total memory used by a data structure?

2010-12-22 Thread Alan
This can't really be done in a language that transparently handles
pointers for you - who's "responsible" for some data that's pointed to
by four different pointers?

(let [a [1 2 [1 2]]
  b [2 [1 2]]
  c (next a)]
  (map total-memory [a b c]))

What does this return? b and c are structurally identical, but c is
taking up less memory because really it's just a pointer into a
subvector of a. If you say that c should print the same size as b -
just pretend data sharing doesn't exist - then this feature becomes
misleading if you use it to compare how much space algorithms require.

(defn sum1 [list]
  (loop [data (into-array Integer/TYPE list) acc 0]
(if (zero? (alength data))
  acc
  (recur (into-array Integer/TYPE (next data)) (+ acc (first
data))

(defn sum2 [list]
  (loop [data (seq list) acc 0]
(if-not data
  acc
  (recur (rest data) (+ acc (first data))

If you added some code to add up the total memory taken by every
object in each iteration of the loop, you would get the wrong results.
An array of N ints definitely takes less space than a vector of those
same ints - it doesn't have to store type information, or be ready to
grow if you need it to, or...

But the vector is getting transparently reused for you, while the
array is getting copied every time. Obviously this example is
intentionally poorly-written, but it would be easy to write something
bad and discover that it's "better" than the right way.

So I'm not sure what benefit all this would have. But it's pretty easy
to do:

(defmulti sizeof class)
(defmethod sizeof Number ([_] 4)) ; or decide by size if you prefer
(defmethod sizeof java.util.Collection
  ([coll]
(reduce + 4 (map sizeof (seq coll)
(defmethod sizeof clojure.lang.ISeq
  ([coll]
(reduce + 4 (map sizeof (seq coll)

(sizeof [1 2 [1 2]])
;=> 24

Just add methods for more things you want to count.

On Dec 22, 8:51 pm, Robert McIntyre  wrote:
> I think it would be really cool to have a function that gives the
> total number of bytes that a data structure consumes.
>
> so something like:
>
> (total-memory [1 2 [1 2]])
>
> would return however many bytes this structure is.
>
> Is there already something like this around? Would it be hard to write
> to work for any clojure data structure?
>
> just like (time), I think (total-memory) would be very enlightening
> for basic testing.
>
> sincerely,
>
> --Robert McIntyre

-- 
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: dispatching on a resulting range

2010-12-22 Thread Sunil S Nandihalli
yea Ken I agree with you.. but it was just an exercise .. you could
definitely add a priority option to every method.. Thanks for your
comments.. besides the code was tested..
Sunil.

On Thu, Dec 23, 2010 at 11:45 AM, Ken Wesson  wrote:

> On Thu, Dec 23, 2010 at 1:09 AM, Ken Wesson  wrote:
> > An untested implementation:
>
> Yeah, there's a bug or two.
>
> > (def qlzqqlzuup (Object.))
> >
> > (defmacro my-defmulti [name]
> >  `(def name
>
> Should be ~name.
>
> > (let [dtable (atom (sorted-map))]
>
> Should be dtable#, and likewise the rest of the local symbols in the
> def. Probably best to hoist the bulk out to a function:
>
> (defn dispatch-multi [dtable arg-seq]
>  (if (= (first arg-seq) qlzqqlzuup)
>(let [[_ pri predmeth] arg-seq]
>   (swap! dtable assoc pri predmeth))
>  (loop [d (seq @dtable)]
>(if d
>  (let [[_ [pred meth]] (first d)]
> (if (apply pred arg-seq)
>  (apply meth arg-seq)
> (recur (next d
>   (throw IllegalArgumentException
>(str "no matching method in " name " for " args)))
>
> (defmacro my-defmulti [name]
>  `(def ~name
> (let [dtable# (atom (sorted-map))]
>(fn [& args#]
> (dispatch-multi dtable# args#)
>
> Warning: still untested.
>
> --
> 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: dispatching on a resulting range

2010-12-22 Thread Ken Wesson
On Thu, Dec 23, 2010 at 1:09 AM, Ken Wesson  wrote:
> An untested implementation:

Yeah, there's a bug or two.

> (def qlzqqlzuup (Object.))
>
> (defmacro my-defmulti [name]
>  `(def name

Should be ~name.

>     (let [dtable (atom (sorted-map))]

Should be dtable#, and likewise the rest of the local symbols in the
def. Probably best to hoist the bulk out to a function:

(defn dispatch-multi [dtable arg-seq]
  (if (= (first arg-seq) qlzqqlzuup)
(let [[_ pri predmeth] arg-seq]
  (swap! dtable assoc pri predmeth))
  (loop [d (seq @dtable)]
(if d
  (let [[_ [pred meth]] (first d)]
(if (apply pred arg-seq)
  (apply meth arg-seq)
                (recur (next d
          (throw IllegalArgumentException
(str "no matching method in " name " for " args)))

(defmacro my-defmulti [name]
  `(def ~name
 (let [dtable# (atom (sorted-map))]
   (fn [& args#]
 (dispatch-multi dtable# args#)

Warning: still untested.

-- 
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: dispatching on a resulting range

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 11:36 PM, Sunil S Nandihalli
 wrote:
> the caveat is that the order in which you specify the methods would matter
> .. since that is the order in which it is going to check for the appropriate
> method to call.. Just like condp again.

That seems sucky. What about adding a priority parameter to your
defmethod-analogue? The predicates are kept sorted by priority. So

(my-defmulti foo)

(my-defmethod foo 4
  (constantly true)
  [x y] (str "x = " x "\ny = " y "\n"))

(my-defmethod foo 3
  #(= %2 1)
  [x y] (str "y is one!\nx = " x))

(my-defmethod foo 2
  #(= %1 %2)
  [x y] (str "x = y = " x))

(my-defmethod foo 1
  #(or (> %1 5) (> %2 5) (> 1 %1) (> 1 %2))
  [x y] (str "One is out of range!\n x = " x "\ny = " y "\n"))

would check for out of range first, then for equality, then for the
default case, despite these being defined in the reverse of that
order.

Of course this could be nicened up further. For example, extend the
scope of the bindings to cover the predicate as well as what follows;
and if the object after the bindings is not a list, if it's the value
true treat it as (constantly true) and if it's a vector check it for
equality against the arguments, treating any vector element equal to
the clojure.core multiplication function as matching anything (so,
under normal circumstances, a literal * in the vector is a wild-card):

(my-defmethod foo 4 [x y]
  true
  (str "x = " x "\ny = " y "\n"))

(my-defmethod foo 3 [x y]
  [* 1]
  (str "y is one!\nx = " x))

(my-defmethod foo 2 [x y]
  (= x y)
  (str "x = y = " x))

(my-defmethod foo 1 [x y]
  (or (> x 5) (> y 5) (> 1 x) (> 1 y))
  (str "One is out of range!\n x = " x "\ny = " y "\n"))

An untested implementation:

(def qlzqqlzuup (Object.))

(defmacro my-defmulti [name]
  `(def name
 (let [dtable (atom (sorted-map))]
   (fn [& args]
 (if (= (first args) qlzqqlzuup)
   (let [[_ pri predmeth] args]
 (swap! dtable assoc pri predmeth))
   (loop [d (seq @dtable)]
 (if d
   (let [[_ [pred meth]] (first d)]
 (if (apply pred args)
   (apply meth args)
   (recur (next d
   (throw IllegalArgumentException
 (str "no matching method in " name " for " args)

(defn wildmatch [matcher & args]
  (loop [m (seq matcher) a (seq args)]
(if (and m a)
  (let [fm (first m)]
(if (or (= fm *) (= fm (first a)))
  (recur (next m) (next a
  true)))

(defmacro my-defmethod [multifn priority bindings matcher & body]
  (let [pred (cond
   (= true matcher) `(constantly true)
   (vector? matcher) `(fn ~bindings
(wildmatch ~matcher ~...@bindings))
   true `(fn ~bindings ~matcher))]
`(~multifn qlzqqlzuup ~priority [~pred (fn ~bindings ~...@body)])))

WARNING: Untested!

IF it works, this implementation has three particular properties not
mentioned above:

1. Defining two methods of the same multifn with the same priority
   isn't possible -- the later one will replace the earlier method of
   the same priority.

2. Vector matching matches if there are fewer arguments than the
   vector length, and the n arguments match against the first n
   elements of the vector, and if there are more arguments than the
   vector length, and the n vector elements match against the first
   n arguments, as well as if there are equal numbers of each and they
   match in sequence.

3. If no method matches it throws an IAE.

Note also that if a method is given a vector as matcher, and that
vector contains expressions, those expressions get run every time the
matcher does (including in some cases where it doesn't match!); e.g.

(my-defmethod foo 3 [x y]
  [(* bar quux) 42]
  (str "x is bar times quux and y is 42"))

will generate a predicate test defined as

(fn [x y] (wildmatch [(* bar quux) 42] x y))

and the lookup and multiplication of bar and quux will be done every
time this is called. Obviously it's best if no such computation is
expensive (unless it needs to be and can't be hoisted out of the
defmethod because it must be run every time) or has side effects
(other than temporary debugging printlns, anyway).

As you can see also, the bindings are in effect where the (* bar quux)
appeared, so the above equality test method could also have been
written as:

(my-defmethod foo 2 [x y]
  [y]
  (str "x = y = " x))

which yields a predicate defined by

(fn [x y] (wildmatch [y] x y))

which in turn will simply see if y is equal to x.

That makes some cases like that one nicer to write, but also means
that the bindings will shadow globals of the same name in the vector,
which might be a surprise some of the time; if we had a global y and
expected the above to check x against that and not against the
argument y we'd get a nasty, and perhaps subtle, bug.

-- 
You received this message because you are subscribed to the Google
Grou

Re: Automatically unmapping unit tests from namespaces

2010-12-22 Thread Phil Hagelberg
On Dec 22, 8:54 am, Constantine Vetoshev  wrote:
> clojure-test-mode is pretty nice, but is there any way to make its
> test namespace naming convention configurable?
>
> It currently expects src/com/company/project/file.clj to correspond to
> test/com/company/project/test/file.clj. I prefer test/test/com/company/
> project/file.clj, i.e., just prefix the whole namespace with "test",
> rather than insert it as the penultimate namespace element. I find it
> much easier to tell, at a glance, if I'm looking at a test namespace
> if it just starts with "test", rather than hunting through the entire
> dotted string.

I used to use that naming scheme (I didn't have any automated way of
switching between the two), but I found that since switching to clj-
stacktrace, it was no longer a problem; it makes it much easier to
tell test and implementation namespaces apart. You will also want to
require uniquify and set uniquify-buffer-name-style to 'forward.

Anyway, there's no way to do what you want now, but I'd be happy to
take a patch that could add it.

-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: about the repl

2010-12-22 Thread Tom Faulhaber
I have submitted a patch for pprint's tendency to mess up when
exceeding *print-length*. I assume that Stuart will apply it to the
1.3 (master) branch RSN, unless he sees a problem with it.

Sorry for the inconvenience.

Tom

On Dec 21, 12:30 am, Tom Faulhaber  wrote:
> Hmm, looks like I broke some logic when I hand unrolled the original
> cl-format based dispatch to get better performance for lists, vectors, and
> maps. (Really I shouldn't have to do this, but I need to make cl-format
> itself generate code rather than threaded functions which are slow and tend
> to blow your stack. Haven't gotten around to that yet, though so the
> hand-coded versions are stop-gaps.)
>
> I'm not digging the patch too much, though, for 3 reasons:
>
> 1) It breaks sets and arrays, which work in master.
> 2) It pushes the logic for *print-length* printing into the dispatch
> functions (redundantly since there's still logic in write-out). Since these
> are customizable, it places that load on whoever customizes it.
> 3) It adds redundant logic in write-out which is the called for every object
> that the pretty printer deals with.
>
> I'll try to take a stab at a patch that fits a little better with what I'm
> trying to do in the next couple of days.
>
> Tom
>
> On Sat, Dec 18, 2010 at 1:18 PM, Stuart Halloway
> wrote:
>
> > > The latter is easy to fix: provide a version of println that wraps an
> > > implicit (take n ...) around seq arguments (including when it calls
> > > itself on seqs nested within other structures). (*print-length*
> > > doesn't seem to work, just causes an infinite seq to print the first n
> > > items and then a never-ending string of "..."s.)
>
> > Hi Ken,
>
> > In my tests *print-length* works fine with the regular REPL printer, but
> > has the defect you describe when using pprint. Can you confirm that you are
> > also seeing the problem with pprint, not print?
>
> > Do some REPLs automatically replace print with pprint?
>
> > Tom:  I have created a ticket with a partial fix and would appreciate your
> > input:http://dev.clojure.org/jira/browse/CLJ-695.
>
> > Thanks,
> > Stu

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


get the total memory used by a data structure?

2010-12-22 Thread Robert McIntyre
I think it would be really cool to have a function that gives the
total number of bytes that a data structure consumes.

so something like:

(total-memory [1 2 [1 2]])

would return however many bytes this structure is.

Is there already something like this around? Would it be hard to write
to work for any clojure data structure?

just like (time), I think (total-memory) would be very enlightening
for basic testing.

sincerely,

--Robert McIntyre

-- 
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: dispatching on a resulting range

2010-12-22 Thread Sunil S Nandihalli
the caveat is that the order in which you specify the methods would matter
.. since that is the order in which it is going to check for the appropriate
method to call.. Just like condp again.



On Thu, Dec 23, 2010 at 10:04 AM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi Alex,
>  I have come across a similar need and I wrote the following macro which
> dispatches in a style similar to condp which can achieve what you are asking
> for ..
>
>
> https://gist.github.com/752567
>
> basically instead of just having the
> dispatch-fn apply only on the arguments of the method and getting the method
> corresponding to the value returned .. what the above does is it passes both
> the array of all the method arguments and the key- for a given method .. if
> that returns true then the corresponding method is called . What this lets
> you do is give a meaning to how the value should be compared.. With this
> flexibility you can achieve what you want.
>
> It works exactly like "condp" in terms of chosing the correct method ..
> which would correspond to a clause in condp.
>
> Sunil.
>
>
> On Thu, Dec 23, 2010 at 8:10 AM, Alex Baranosky <
> alexander.barano...@gmail.com> wrote:
>
>> Hi
>>
>> I've been playing with multimethods, and trying to see if there was a way
>> to dispatch on a non-specific result of the dispatching function, such as a
>> range, like this:
>>
>> (defn how-to-move [map1 map2]
>>   (+ (:cats map1) (:dogs map2)))
>>
>> (defmulti move how-to-move)
>>
>> (defmethod move 1 [map1 map2]
>>   (println "one"))
>>
>> (defmethod move 2 [map1 map2]
>>   (println "two"))
>>
>> (defmethod move 3 [map1 map2]
>>   (println "three"))
>>
>> (defmethod move #(> % 3) [map1 map2]
>>   (println "lots!"))
>>
>> (move {:cats 1} { :dogs 0})
>> (move {:cats 0} { :dogs 1})
>> (move {:cats 1} { :dogs 1})
>> (move {:cats 1} { :dogs 2})
>> (move {:cats 2} { :dogs 0})
>> (move {:cats 2} { :dogs 5})
>>
>> It seems I could easily do this by changing how-to-move to:
>>
>> (defn how-to-move [map1 map2]
>>   (let [cnt (+ (:cats map1) (:dogs map2))]
>> (if (> cnt 3)
>>   :lots
>>   cnt)))
>>
>> and changing the last move defmethod to:
>>
>> (defmethod move :lots [map1 map2]
>>   (println "lots"))
>>
>> I am wondering if there is a built in syntax for this?
>>
>> Thanks,
>> Alex
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>

-- 
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: dispatching on a resulting range

2010-12-22 Thread Sunil S Nandihalli
Hi Alex,
 I have come across a similar need and I wrote the following macro which
dispatches in a style similar to condp which can achieve what you are asking
for ..


https://gist.github.com/752567

basically instead of just having the
dispatch-fn apply only on the arguments of the method and getting the method
corresponding to the value returned .. what the above does is it passes both
the array of all the method arguments and the key- for a given method .. if
that returns true then the corresponding method is called . What this lets
you do is give a meaning to how the value should be compared.. With this
flexibility you can achieve what you want.

It works exactly like "condp" in terms of chosing the correct method ..
which would correspond to a clause in condp.

Sunil.

On Thu, Dec 23, 2010 at 8:10 AM, Alex Baranosky <
alexander.barano...@gmail.com> wrote:

> Hi
>
> I've been playing with multimethods, and trying to see if there was a way
> to dispatch on a non-specific result of the dispatching function, such as a
> range, like this:
>
> (defn how-to-move [map1 map2]
>   (+ (:cats map1) (:dogs map2)))
>
> (defmulti move how-to-move)
>
> (defmethod move 1 [map1 map2]
>   (println "one"))
>
> (defmethod move 2 [map1 map2]
>   (println "two"))
>
> (defmethod move 3 [map1 map2]
>   (println "three"))
>
> (defmethod move #(> % 3) [map1 map2]
>   (println "lots!"))
>
> (move {:cats 1} { :dogs 0})
> (move {:cats 0} { :dogs 1})
> (move {:cats 1} { :dogs 1})
> (move {:cats 1} { :dogs 2})
> (move {:cats 2} { :dogs 0})
> (move {:cats 2} { :dogs 5})
>
> It seems I could easily do this by changing how-to-move to:
>
> (defn how-to-move [map1 map2]
>   (let [cnt (+ (:cats map1) (:dogs map2))]
> (if (> cnt 3)
>   :lots
>   cnt)))
>
> and changing the last move defmethod to:
>
> (defmethod move :lots [map1 map2]
>   (println "lots"))
>
> I am wondering if there is a built in syntax for this?
>
> Thanks,
> Alex
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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: Let's see how fast we can make this

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 10:19 PM, Rayne  wrote:
> private static int countNumChars(String s) {
>        int num = s.length();
>        for (int i = 0; i < s.length(); i++) {
>                if (s.charAt(i) == ' ') {
>                        num--;
>                }
>        }
>        return num;
> }
>
> Is one of the fastest I've seen. It runs around 4366.293

Does it speed up any further if you manually hoist the s.length() out
of the loop?

It's encouraging that the fastest Clojure implementation we've found
takes only ~25% longer on your machine.

-- 
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: Let's see how fast we can make this

2010-12-22 Thread Rayne
private static int countNumChars(String s) {
int num = s.length();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') {
num--;
}
}
return num;
}

Is one of the fastest I've seen. It runs around 4366.293

On Dec 22, 1:43 pm, David Nolen  wrote:
> On Wed, Dec 22, 2010 at 12:52 PM, Rayne  wrote:
> > Running it gives me around 137343.295 nanoseconds. I've seen some Java
> > algorithms that could run at just under 3000 nanoseconds.
>
> What do the Java implementations look like?
>
> (defn count-num-chars [^String s]
>   (let [l (.length s)
>         c (int \space)]
>    (loop [i 0 acc 0]
>     (if (< i l)
>       (recur (unchecked-inc-long i)
>              (if (= (int (.charAt s i)) c) acc
>                  (unchecked-inc-long acc)))
>       acc
>
> On 1.3.0 alpha3 on a 2.66ghz Core i7, 64bit OS X JDK 1.6 I see anywhere
> from-
>
> 6900ns-11000ns
>
> Using identical?, codePointAt all make things slower for me.
>
> David

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


dispatching on a resulting range

2010-12-22 Thread Alex Baranosky
Hi

I've been playing with multimethods, and trying to see if there was a way to
dispatch on a non-specific result of the dispatching function, such as a
range, like this:

(defn how-to-move [map1 map2]
  (+ (:cats map1) (:dogs map2)))

(defmulti move how-to-move)

(defmethod move 1 [map1 map2]
  (println "one"))

(defmethod move 2 [map1 map2]
  (println "two"))

(defmethod move 3 [map1 map2]
  (println "three"))

(defmethod move #(> % 3) [map1 map2]
  (println "lots!"))

(move {:cats 1} { :dogs 0})
(move {:cats 0} { :dogs 1})
(move {:cats 1} { :dogs 1})
(move {:cats 1} { :dogs 2})
(move {:cats 2} { :dogs 0})
(move {:cats 2} { :dogs 5})

It seems I could easily do this by changing how-to-move to:

(defn how-to-move [map1 map2]
  (let [cnt (+ (:cats map1) (:dogs map2))]
(if (> cnt 3)
  :lots
  cnt)))

and changing the last move defmethod to:

(defmethod move :lots [map1 map2]
  (println "lots"))

I am wondering if there is a built in syntax for this?

Thanks,
Alex

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

Is swank-clojure.el deprecated?

2010-12-22 Thread limux
The clojure has released the 1.2 version, while swank-clojure.el is
used 1.1 yet, Is swank-clojure deprecated at all?

-- 
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: Out of memory

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 6:38 PM, David Nolen  wrote:
> On Wed, Dec 22, 2010 at 6:10 PM, Ken Wesson  wrote:
>>
>> On Wed, Dec 22, 2010 at 6:08 PM, Chris Riddoch  wrote:
>> > On Wed, Dec 22, 2010 at 3:46 PM, David Nolen 
>> > wrote:
>> >> A entire collection of 5e7 *objects* is being realized into memory as
>> >> it is
>> >> being reduced down to a single value to be stored into a var. I would
>> >> expect
>> >> this to perform poorly in any language.
>> >
>> > Range doesn't return a lazy seq?  Or reduce somehow doesn't work
>> > lazily?  This is a little discouraging - it seems like this is a
>> > perfect example of a case where laziness could significantly improve
>> > things.
>>
>> No, both are lazy. Something else is going on here, involving def
>> holding onto the head of any sequence whose expression is in the def
>> form but not in a nested let or fn similar scope-creating form.
>>
>> http://groups.google.com/group/clojure?hl=en
>
> reduce is not lazy. It is eager. chouser corrected me of my misconception.

It's a consumer rather than a producer (or both) of sequences; and, as
such, it's lazy inasmuch as it does not hold onto the head of the
sequence, so if you pass it a lazy sequence it does not keep the whole
thing realized and in memory at one time.

Lazy producer -- sequence is made a bit at a time, on demand, instead
of realized all at once.
Lazy consumer -- sequence is traversed without retaining parts
internally (holding onto the head).

Map is both; range is a lazy producer; reduce is a lazy consumer but
an eager producer, though not generally of a transformed version of
the seq. It's possible to be a lazy consumer and an eager producer of
even a transformed seq though; (doall (map f s)) presumably generates
and discards an element of s for each element of output it generates,
and holds onto the head of the output only, never holding more than
one element of s at a time. A seq view of a collection will be an
eager consumer but might be a lazy producer; (apply list a-coll) will
eager-consume and eager-produce but makes a new data structure the
size of the input, while a lazy seq view may only need to generate the
equivalent of a single cons cell at a time, holding an element in
"first" and a closure wrapping an Iterator or index of some sort in
"rest" as the generator of (next the-seq-view). This reduces memory
overhead somewhat, especially if traversal is never completed,
compared to a seq view generator outputting (list element1 element2
element3 ...).

So there's two sorts of "lazy behavior" at issue: on the producer
side, does it generate a whole list or other data structure all at
once, or only a bit at a time as needed? On the consumer side, does it
hold onto the head of a passed-in seq or does it consume and discard
one element at a time? The difficulty with clarity of language arises
when something is a lazy consumer but an eager producer, like reduce,
or vice versa.

If you want to use lazy to generally only mean "lazy producer", that's
OK, but it would be helpful to have some alternative term for a lazy
consumer (that is, anything that traverses a seq without internally
hanging onto the head).

-- 
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: Clojure web application using NHPM for server push

2010-12-22 Thread rob levy
Hi Anders, thanks.  If I understand what you are asking, in fact the server
in my case does not care if anyone is listening, however you can set how
long the messages live in the queue.  The client holds the responsibility of
keeping track of what messages it has already seen based on the date in the
response header.  If you want to make sure your client doesn't miss messages
you set a very long time to live and let the client catch up to what it
hasn't seen yet in the spew of messages when it signs back on.  For my
application this was not necessary, as I treat push messages as ephemeral
short lived things.  When the client comes back on the direct request to the
server to log in gives its next waiting event as a plain old response to the
request to the application maintaining this state.  Does this answer your
question?
On Dec 21, 2010 5:50 PM, "Anders Rune Jensen" 
wrote:
> On Mon, Dec 20, 2010 at 6:06 PM, rob levy  wrote:
>> I have posted a repository containing the code for a web application I
made
>> using a server push (AKA Comet, long polling) architecture.  The front
end
>> is in Javascript, and the back end is in Clojure.  The clojure code is
able
>> to send notifications to clients' browsers effectively through use of
>> nginx's push module, which the clients subscribe to.  With websockets
>> presently out of reach this can be a good way of doing this sort of
thing,
>> and at least on my small-scale testing it is a super responsive way of
>> simulating a socket.
>
> Hi Rob
>
> Interesting project. I havn't looked at the machine learning part of
> it, although that also sounds interesting, but at first I was more
> interested in the long polling aspect of your application. I was
> looking at something similar but in the end I decided that given my
> use case (mostly a single client polling) it didn't make much sense to
> use nginx. I'm guessing that in your architecture, nginx makes more
> sense because you have a lot of clients polling the same interface?
> That way you know that it is much more likely that there will be at
> least one subscriber left for a message when the server actually has
> something to send. And I guess the way the back-end knows that there
> is still someone that wants to know about a message is that nginx says
> that there is still clients waiting when it delivers the message.
> Could you maybe elaborate a bit more on this?
>
>> https://github.com/rplevy/sayoperation
>>
>> The application itself is online (for now) at:
>>
>> http://www.robertplevy.net/sayoperation/
>>
>> A little bit of context is necessary here.  This is a game I made as part
of
>> my final project for a course I am in (I am taking courses part time as
part
>> of an MA program I will eventually complete) on the topic of Machine
>> Learning and Natural Language Processing.  The purpose of the game is to
>> collect game move data.  I'm in the process of figuring out how to train
a
>> classifier to learn to make the same sorts of game moves (though the text
>> generation piece is out of scope), to have 1/2 of an AI game player.
>>
>> If you want to play the game and help me collect training data, here are
>> some things to know:
>>
>>1.  You will be asked to give an instruction to your team mate, given
the
>> information on the screen.  The red is the target, and the green is what
>> your teammate will move to the target.  Notice that the target is always
an
>> empty space.   For example "put the crab above the butterfly" would make
>> sense if the crab had a green border, and there were a red bordered
target
>> above the butterfly.
>>
>>2.  Use clear and natural language when entering data., try to explain
in
>> the way you would explain to a person.  Punctuation and capitalization is
>> stripped out/lowercased.
>>
>>3.  The rounds work like this.  Player 1 instruct -> Player 2 move -->
>> Player 2 instruct --> Player 1 move.  The game automatically presents
your
>> next available move just like in RIAs such as gchat or facebook (no need
to
>> refresh).
>>
>>4.  Multiple concurrent games are encouraged.  The game should be
>> responsive and will immediately tell you if you have a move to play in
any
>> of your games.
>>
>>5. Caveat:  The application has been tested thoroughly in Firefox and
>> Chrome.  While there is no inherent reason why it shouldn't be possible
to
>> make it work in Opera or Internet Explorer, I have not tested it in IE
(so
>> it probably doesn't work in that browser), and I am aware that it doesn't
>> work in Opera.  This is just a matter of time and effort, that I need to
>> spend on the NLP side of this project at the moment.
>>
>>6. The high scoring team as of 2am tonight will win something (I
haven't
>> decide what, give me ideas please).
>>
>> Thanks,
>> Rob
>>
>> --
>> 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 me

Re: Out of memory

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 6:10 PM, Ken Wesson  wrote:

> On Wed, Dec 22, 2010 at 6:08 PM, Chris Riddoch  wrote:
> > On Wed, Dec 22, 2010 at 3:46 PM, David Nolen 
> wrote:
> >> A entire collection of 5e7 *objects* is being realized into memory as it
> is
> >> being reduced down to a single value to be stored into a var. I would
> expect
> >> this to perform poorly in any language.
> >
> > Range doesn't return a lazy seq?  Or reduce somehow doesn't work
> > lazily?  This is a little discouraging - it seems like this is a
> > perfect example of a case where laziness could significantly improve
> > things.
>
> No, both are lazy. Something else is going on here, involving def
> holding onto the head of any sequence whose expression is in the def
> form but not in a nested let or fn similar scope-creating form.

http://groups.google.com/group/clojure?hl=en
>

reduce is not lazy. It is eager. chouser corrected me of my misconception.

David

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

Re: Out of memory

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 6:08 PM, Chris Riddoch  wrote:
> On Wed, Dec 22, 2010 at 3:46 PM, David Nolen  wrote:
>> A entire collection of 5e7 *objects* is being realized into memory as it is
>> being reduced down to a single value to be stored into a var. I would expect
>> this to perform poorly in any language.
>
> Range doesn't return a lazy seq?  Or reduce somehow doesn't work
> lazily?  This is a little discouraging - it seems like this is a
> perfect example of a case where laziness could significantly improve
> things.

No, both are lazy. Something else is going on here, involving def
holding onto the head of any sequence whose expression is in the def
form but not in a nested let or fn similar scope-creating form.

-- 
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: "classic" clojure-contrib 1.3.0-alpha4 released

2010-12-22 Thread Stuart Halloway
Nothing about multiple small bundles prevents doing a bigger bundled release as 
well. There continues to be a "kitchen sink" contrib, and there can be a 
"batteries included" build of the newer libs too. Repositories are orthogonal 
to build artifacts.

On the other hand, building only a big bundle makes it difficult for anyone to 
ever go in the other direction.
 
> For me as a user, the appeal of contrib was the bundling. I used to
> just download the latest contrib jar, throw it in the classpath, and
> have plenty of functionality that could be easily summoned using a
> single line of code. Just like a standard library, even though it's
> not officially standard. It's the "batteries included" way which
> established itself as an important aspect of modern programming. Now
> if you need something in contrib, it's a chore.
> 
> To pre-empt the argument for automation tools/libs: I'm not big on
> those. They change too often; they feel patchy, and they add, in my
> opinion, an unnecessary layer of incidental complexity between me and
> my code.
> 
> If you separate the libs then I can't see a difference or advantage
> from the "third party" libs. The separate libs will not be considered
> standard and therefore not be extensively deployed, and therefore not
> be extensively used or fixed or improved or held to a higher standard.
> 
> I understand the problems of contrib in one repository, yet I can't
> help but feel unbundling is a step in the wrong direction.
> 
> 
> On Dec 19, 6:36 pm, Stuart Sierra  wrote:
>> Description of current plans for future releases is
>> athttp://dev.clojure.org/display/design/Common+Contrib+Build
>> 
>> -Stuart Sierra
>> clojure.com
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To 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: Out of memory

2010-12-22 Thread Chris Riddoch
On Wed, Dec 22, 2010 at 3:46 PM, David Nolen  wrote:
> A entire collection of 5e7 *objects* is being realized into memory as it is
> being reduced down to a single value to be stored into a var. I would expect
> this to perform poorly in any language.

Range doesn't return a lazy seq?  Or reduce somehow doesn't work
lazily?  This is a little discouraging - it seems like this is a
perfect example of a case where laziness could significantly improve
things.

-- 
Chris Riddoch

-- 
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: Out of memory

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 5:32 PM, Chris Riddoch  wrote

>
> If the workarounds mentioned actually work (I haven't tried) I really
> don't understand why.  This *looks* like a genuine bug to me, but I
> really don't know Clojure's internals well enough (yet) to be able to
> have the slightest hint where to start looking.  I don't see any
> reason why (reduce + (range )) should take so much
> memory.
>
> --
> Chris Riddoch
>

A entire collection of 5e7 *objects* is being realized into memory as it is
being reduced down to a single value to be stored into a var. I would expect
this to perform poorly in any language.

David

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

Re: Calling methods with a dollar sign in them

2010-12-22 Thread Daniel Werner
On 22 December 2010 23:22, Seth  wrote:
> ok, thats what i thought. Any change of a literal syntax for symbols
> like in lisp, |symbol|??

There is no special reader syntax for weirdly named symbols, at least
as far as I am aware, but you can always use:

(symbol "strange$name")

-- 
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: Calling methods with a dollar sign in them

2010-12-22 Thread Sean Corfield
Since nested classes in Java get compiled to Outer$Inner, has any
thought been given to allowing $ ?

(Outer$Inner.)

On Tue, Dec 21, 2010 at 12:30 PM, Stuart Sierra
 wrote:
> Right now, probably not. But you can use the Java Reflection API to work
> around it.

-- 
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: Out of memory

2010-12-22 Thread Chris Riddoch
On Wed, Dec 22, 2010 at 9:54 AM, Laurent PETIT  wrote:
> 2010/12/22 Jeff Palmucci 
>>
>> I've worked around this sort of thing in the past by wrapping the
>> initialization in a closure. My macros:
>
> Couldn't just it be a wrap with (let [] ), and let the choice of running it
> once or not by choosing either def or defonce :

If the workarounds mentioned actually work (I haven't tried) I really
don't understand why.  This *looks* like a genuine bug to me, but I
really don't know Clojure's internals well enough (yet) to be able to
have the slightest hint where to start looking.  I don't see any
reason why (reduce + (range )) should take so much
memory.

-- 
Chris Riddoch

-- 
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: Calling methods with a dollar sign in them

2010-12-22 Thread Seth
ok, thats what i thought. Any change of a literal syntax for symbols
like in lisp, |symbol|??

-- 
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: "classic" clojure-contrib 1.3.0-alpha4 released

2010-12-22 Thread Sean Corfield
On Wed, Dec 22, 2010 at 11:50 AM, Mibu  wrote:
> For me as a user, the appeal of contrib was the bundling.
...
> If you separate the libs then I can't see a difference or advantage
> from the "third party" libs.

When I first started using Clojure, I felt the bundling was very
useful. Over time, I've switched to pulling in specific libraries as I
need them. Of course, I use a build tool so dependency management is
automatic - I can't imagine trying to manage this manually.

As for the differentiation between 3rd party libs and contrib, I would
say contrib *is* considered 'standard' and it's the proving ground for
things that are on a path to becoming core.

For me it's like Java-the-language (with a handful of java.lang.*
packages 'built-in') vs Java-the-standard-library vs 3rd party Java
libraries (so maybe the current/future Clojure situation makes more
sense to folks with a Java background than other folks?).
-- 
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: Let's see how fast we can make this

2010-12-22 Thread David Powell

Wednesday, December 22, 2010, 6:52:01 PM, you wrote:

> On my machine, your reduce example (I actually wrote that myself as my
> first try) runs marginally slower than my loop example. I don't know
> why you're getting such weird numbers. Your areduce example is worst
> of all at 74072 on my machine.

I got those results using:
"Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode)"

With the HEAD version of Clojure from github.

Running with no command-line options other than -server.


The 32-bit version seems vaguely similar.


-- 
Dave

-- 
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: Cannot recur across try

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 3:43 PM, Amitava Shee wrote:

>
> Can someone more qualified than I explain why a recur from a try poses
> a problem?
>
> I am copying the relevant parts of the source below
>
> clojure.tmbundle/Support/repl.clj
> ==
> (defn repl
>  "runs a repl on ins and outs until eof"
>  [ins outs]
>(binding [*ns* (create-ns 'user)
>  *warn-on-reflection* false
>  *out* (new OutputStreamWriter outs)]
>  (let [eof (new Object)
>r (new LineNumberingPushbackReader (new InputStreamReader
> ins))]
>(loop [e (read r false eof)]
>  (when-not (or (= e :repl_eof) (= e eof))
>(try
>  (prn (eval e))
>  (flush)
>  (recur (read r false eof))
>(catch Throwable e
>  (let [c (extract-root-cause e)]
>(if (isa? Compiler$CompilerException e)
>  (println e)
>  (println c)))
>  (flush
>
> Thanks,
> Amitava


I don't know the details, but the ticket is here:

http://dev.clojure.org/jira/browse/CLJ-31?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel#issue-tabs

Perhaps better if the REPL caught exceptions in the manner that Clojure's
REPL does:

https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L115

David

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

Cannot recur across try

2010-12-22 Thread Amitava Shee
While trying to make stephenroller's TextMate bundle (https://
github.com/stephenroller/clojure-tmbundle.git) work against Clojure
1.3.0-master-SNAPSHOT, I am running into the following exception

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.UnsupportedOperationException: Cannot recur
across try, compiling:(/Users/amitava/Library/Application Support/
TextMate/Bundles/clojure.tmbundle/Vendor/../Support/repl.clj:41)

Looks like this is related to the ticket -
http://dev.clojure.org/jira/browse/CLJ-31?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel

Can someone more qualified than I explain why a recur from a try poses
a problem?

I am copying the relevant parts of the source below

clojure.tmbundle/Support/repl.clj
==
(defn repl
  "runs a repl on ins and outs until eof"
  [ins outs]
(binding [*ns* (create-ns 'user)
  *warn-on-reflection* false
  *out* (new OutputStreamWriter outs)]
  (let [eof (new Object)
r (new LineNumberingPushbackReader (new InputStreamReader
ins))]
(loop [e (read r false eof)]
  (when-not (or (= e :repl_eof) (= e eof))
(try
  (prn (eval e))
  (flush)
  (recur (read r false eof))
(catch Throwable e
  (let [c (extract-root-cause e)]
(if (isa? Compiler$CompilerException e)
  (println e)
  (println c)))
  (flush

Thanks,
Amitava

-- 
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: "classic" clojure-contrib 1.3.0-alpha4 released

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 2:50 PM, Mibu  wrote:
> For me as a user, the appeal of contrib was the bundling. I used to
> just download the latest contrib jar, throw it in the classpath, and
> have plenty of functionality that could be easily summoned using a
> single line of code. Just like a standard library, even though it's
> not officially standard. It's the "batteries included" way which
> established itself as an important aspect of modern programming. Now
> if you need something in contrib, it's a chore.
>
> To pre-empt the argument for automation tools/libs: I'm not big on
> those. They change too often; they feel patchy, and they add, in my
> opinion, an unnecessary layer of incidental complexity between me and
> my code.
>
> If you separate the libs then I can't see a difference or advantage
> from the "third party" libs. The separate libs will not be considered
> standard and therefore not be extensively deployed, and therefore not
> be extensively used or fixed or improved or held to a higher standard.
>
> I understand the problems of contrib in one repository, yet I can't
> help but feel unbundling is a step in the wrong direction.

+1

-- 
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: "classic" clojure-contrib 1.3.0-alpha4 released

2010-12-22 Thread Mibu
For me as a user, the appeal of contrib was the bundling. I used to
just download the latest contrib jar, throw it in the classpath, and
have plenty of functionality that could be easily summoned using a
single line of code. Just like a standard library, even though it's
not officially standard. It's the "batteries included" way which
established itself as an important aspect of modern programming. Now
if you need something in contrib, it's a chore.

To pre-empt the argument for automation tools/libs: I'm not big on
those. They change too often; they feel patchy, and they add, in my
opinion, an unnecessary layer of incidental complexity between me and
my code.

If you separate the libs then I can't see a difference or advantage
from the "third party" libs. The separate libs will not be considered
standard and therefore not be extensively deployed, and therefore not
be extensively used or fixed or improved or held to a higher standard.

I understand the problems of contrib in one repository, yet I can't
help but feel unbundling is a step in the wrong direction.


On Dec 19, 6:36 pm, Stuart Sierra  wrote:
> Description of current plans for future releases is
> athttp://dev.clojure.org/display/design/Common+Contrib+Build
>
> -Stuart Sierra
> clojure.com

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


Re: Let's see how fast we can make this

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 12:52 PM, Rayne  wrote:

> Running it gives me around 137343.295 nanoseconds. I've seen some Java
> algorithms that could run at just under 3000 nanoseconds.
>

What do the Java implementations look like?

(defn count-num-chars [^String s]
  (let [l (.length s)
c (int \space)]
   (loop [i 0 acc 0]
(if (< i l)
  (recur (unchecked-inc-long i)
 (if (= (int (.charAt s i)) c) acc
 (unchecked-inc-long acc)))
  acc

On 1.3.0 alpha3 on a 2.66ghz Core i7, 64bit OS X JDK 1.6 I see anywhere
from-

6900ns-11000ns

Using identical?, codePointAt all make things slower for me.

David

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

Re: *print-dup* and records

2010-12-22 Thread Brent Millare
Found an answer on stackoverflow

http://stackoverflow.com/questions/4512790/how-do-i-use-print-dup-to-print-records-in-clojure-a-simple-case

On Dec 22, 1:27 pm, Brent Millare  wrote:
> Hello,
>
> I'm trying to use *print-dup* to allow writing clojure data to a file
> and then read it back, however, I'm getting problems even with this
> simple case. Is there something I am doing wrong? What do I need to do
> to get this to work?
>
> Clojure 1.3.0-alpha3-SNAPSHOT
> user=> (defrecord TreeNode [val left right]) ;;create the record
> user.TreeNode
> user=> (TreeNode. 5 nil nil)
> #:user.TreeNode{:val 5, :left nil, :right nil} ;; it works just fine
> user=> (binding [*print-dup* true] (prn (TreeNode. 5 nil nil))) ;; use
> *print-dup* to support reading in and preserving type
> #=(user.TreeNode/create {:val #=(java.lang.Long. "5"), :left
> nil, :right nil}) ;; this is the form we need to copy paste
> nil
> user=> #=(user.TreeNode/create {:val #=(java.lang.Long. "5"), :left
> nil, :right nil}) ;;trying to copy and paste
> IllegalArgumentException No matching method found: create
> clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:50) ;;we
> have an error
> user=>

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

2010-12-22 Thread Brian Marick
> What are the cons of using midje?  Any reason I shouldn't migrate all
> my unit testing to it?


I'm biased, but I think Midje is ready for production use. There's a smooth 
migration path because Midje uses the same reporting as clojure.test, so you 
can mix styles in the same file and still use (for example) lein test to see if 
anything failed. (I'll go write up a Migrating page in the wiki after I send 
this mail.)

There are things clojure.test does that Midje doesn't:

* Named tests (deftest). So you can't write runner functions like this:

 (deftest arithmetic-tests
(subtraction-tests)
   (addition-tests))

  unless you also :use clojure.test and wrap the Midje facts in deftests (which 
works fine). 

* There's no equivalent to with-test.

* There's no #'are, though I suspect using checker functions would work as well.

Midje isn't a superset of the features of other clojure.test alternatives. For 
example, it doesn't have the auto-runner that LazyTest does, and it doesn't 
have the trimmed stack traces of Expectations. I plan to keep stealing ideas, 
though.

-
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


Re: Let's see how fast we can make this

2010-12-22 Thread Rayne
On my machine, your reduce example (I actually wrote that myself as my
first try) runs marginally slower than my loop example. I don't know
why you're getting such weird numbers. Your areduce example is worst
of all at 74072 on my machine.

On Dec 22, 12:39 pm, David Powell  wrote:
> Hi,
>
> > I have a piece of code, and I'd like to see how fast it can be.
> > (defn count-num-chars [^String s]
> >   (loop [s s acc 0]
> >     (if (seq s)
> >       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
> >       acc)))
>
> I get an average of 46928 for this.
>
> But for the straightforward option of reduce:
>
> (defn count-num-chars3 [^String s]
>   (reduce (fn [acc c] (if (= c \space) acc (inc acc))) 0 s))
>
> I get an average of 27424.  Cool!  So writing it the nicest way, is
> also faster.
>
> I tend to avoid spamming .charAt even in Java for things like this,
> and often find converting to an array first to be faster, like this:
>
> (defn count-num-chars4 [^String s]
>   (let [as (.toCharArray s)]
>     (areduce as idx acc 0 (if (= (int (aget as idx)) (int \space)) acc (inc 
> acc)
>
> I get an average of 3631.
>
> (needed to cast the char to int there, else clojure seems to hit
> reflection problems)
>
> --
> Dave

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai  wrote:
> Hi Ken,
>
>> user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
>> [1 2 (3 4 5)]
>> user=> (let [[x y z] [1 2 3 4 5]] [x y z])
>> [1 2 3]
>> user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
>> [3 4]
>>
>> You can grab any fixed position in this way, as well as a "rest" that
>> is the tail of the sequence past the last of such.
>
> Right, that's true.  However, Marek had given two examples of Python
> tuple unpacking, the first being:
>
>> first, *middle, last = sequence(...)
>
> Which I believe in Python 3 will bind 'first' to the first element,
> 'last' to the last element, and 'middle' to a sequence of all the
> elements in the middle.  That last part is what I don't know how to do
> in Clojure.

I don't think Clojure has that. Closest is

(let [[f & rst] [1 2 3 4 5]
  l (last rst)
  m (butlast rst)]
  [f m l])

Output is [1 (2 3 4) 5]

Obviously, using the last element is non-lazy. It may well be that in
cases where you'd want to do this you might prefer another data
representation.

-- 
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: Let's see how fast we can make this

2010-12-22 Thread David Powell
Hi,

> I have a piece of code, and I'd like to see how fast it can be.

> (defn count-num-chars [^String s]
>   (loop [s s acc 0]
> (if (seq s)
>   (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>   acc)))

I get an average of 46928 for this.


But for the straightforward option of reduce:

(defn count-num-chars3 [^String s]
  (reduce (fn [acc c] (if (= c \space) acc (inc acc))) 0 s))

I get an average of 27424.  Cool!  So writing it the nicest way, is
also faster.


I tend to avoid spamming .charAt even in Java for things like this,
and often find converting to an array first to be faster, like this:

(defn count-num-chars4 [^String s]
  (let [as (.toCharArray s)]
(areduce as idx acc 0 (if (= (int (aget as idx)) (int \space)) acc (inc 
acc)

I get an average of 3631.

(needed to cast the char to int there, else clojure seems to hit
reflection problems)

-- 
Dave

-- 
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: Let's see how fast we can make this

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 1:19 PM, Rayne  wrote:
> chouser wrote a solution earlier. I and a buddy modified it (a very
> little) bit and managed to get it pretty blazing:
>
> ra...@ubuntu:~$ cake run ~/challenge.clj
> Chars outputted: 460
> Time (in nanoseconds): 5768.677
>
> Here is the function:
>
> (defn count-num-chars [^String s]
>  (let [len (.length s)
>        space (int 32)]
>    (loop [i (int 0), c (int 0)]
>      (if (< i len)
>        (recur
>         (inc i)
>         (if (== (.codePointAt s i) space)
>           c
>           (unchecked-inc c)))
>        c

I get about 6000ns with this also. It looks like one bit of Clojure in
need of improvement is the handling of the = operator: if at compile
time it's known that either side is a primitive or a character
constant, it really ought to boil down to a Java == operator, but
apparently it doesn't, and JIT and branch prediction don't suffice to
render the difference moot.

Also, == doesn't seem to work with characters -- ClassCastException
java.lang.Character can't be cast to java.lang.Number. This with
\space or (char \space) on the right hand side and (.charAt s i) on
the left. The odd thing is this suggests == isn't a raw Java ==
operator call but rather a method call of Number, likely .equals.
Which shouldn't be particularly fast.

Now, identical? IS supposed to be Java's == operator but for

(defn count-num-chars [^String s]
 (let [l (int (.length s)) c (char \space)]
   (loop [i (int 0) acc (int 0)]
 (if (< i l)
   (recur (unchecked-inc i) (if (identical? (.charAt s i) c) acc
(unchecked-inc acc)))
   acc

I get 9000ns, about two-thirds the speed I get using == and .codePointAt.

Something interesting is going on among =, ==, and identical? here,
but I'm not 100% sure what. Perhaps identical? is not managing to have
its function call overhead JITted away, while the Clojure compiler
treats the operators specially; in theory it *should* be fastest.

-- 
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: Working with protocols

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 1:29 PM, Nicolas Buduroi  wrote:

> On Dec 22, 1:03 pm, David Nolen  wrote:
> > (Foo.) is a Java method call determined at compile-time. If you change
> the
> > definition of the Foo type/record, create-foo will be out of date.
> Default
> > constructor fns could alleviate this but I think some design/modularity
> > issues need to be hashed out.
>
> Yes, I've realized this when developing this project. At first, it was
> less modular and I encountered much more of such issues. I also used
> `immigrate` previously and that was causing troubles not only with
> protocols, but with multimethods also. In the end there still appears
> to be some problems while developing protocol based code in a REPL-
> driven fashion. I was hoping I did something wrong that somebody could
> point out.
>
> P.S.: It makes me wonder if there's some improvements that can be done
> to make that type of coding more REPL friendly.


Hmm. Actually now that you mention it I do recall I did run into some issues
when I was interactively developing types/records across namespaces.

Probably worth coming up with small reproducible example.

David

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

Re: Let's see how fast we can make this

2010-12-22 Thread Rayne
Also, forgot to add an unchecked-int:

(defn count-num-chars [^String s]
  (let [len (.length s)
space (int 32)]
(loop [i (int 0), c (int 0)]
  (if (< i len)
(recur
 (unchecked-inc i)
 (if (== (int (.charAt s i)) space)
   c
   (unchecked-inc c)))
c

Also, any version of Clojure is fine.
On Dec 22, 12:29 pm, Rayne  wrote:
> I actually pasted the wrong code here:
>
> (defn count-num-chars [^String s]
>   (let [len (.length s)
>         space (int 32)]
>     (loop [i (int 0), c (int 0)]
>       (if (< i len)
>         (recur
>          (inc i)
>          (if (== (int (.charAt s i)) space)
>            c
>            (unchecked-inc c)))
>         c
>
> On Dec 22, 12:19 pm, Rayne  wrote:
>
>
>
> > chouser wrote a solution earlier. I and a buddy modified it (a very
> > little) bit and managed to get it pretty blazing:
>
> > ra...@ubuntu:~$ cake run ~/challenge.clj
> > Chars outputted: 460
> > Time (in nanoseconds): 5768.677
>
> > Here is the function:
>
> > (defn count-num-chars [^String s]
> >   (let [len (.length s)
> >         space (int 32)]
> >     (loop [i (int 0), c (int 0)]
> >       (if (< i len)
> >         (recur
> >          (inc i)
> >          (if (== (.codePointAt s i) space)
> >            c
> >            (unchecked-inc c)))
> >         c
>
> > On Dec 22, 11:52 am, Rayne  wrote:
>
> > > I have a piece of code, and I'd like to see how fast it can be.
>
> > > (defn count-num-chars [^String s]
> > >   (loop [s s acc 0]
> > >     (if (seq s)
> > >       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
> > >       acc)))
>
> > > This is the fastest I've been able to get it. The function is very
> > > simple. It takes a string and counts the number of non-space
> > > characters inside of that string.
>
> > > I've been testing this code against a 460 non-space character string.
> > > Here is the entire source, benchmarking and all:
>
> > > (def s (apply str (repeat 20 "This is a really long string")))
>
> > > (defn count-num-chars [^String s]
> > >   (loop [s s acc 0]
> > >     (if (seq s)
> > >       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
> > >       acc)))
>
> > > (println "Chars outputted:" (count-num-chars s))
>
> > > (let [before (System/nanoTime)]
> > >   (dotimes [_ 1000]
> > >     (count-num-chars s))
> > >   (let [after (System/nanoTime)]
> > >     (println "Time (in nanoseconds):" (/ (- after before) 1000.0
>
> > > Running it gives me around 137343.295 nanoseconds. I've seen some Java
> > > algorithms that could run at just under 3000 nanoseconds.
>
> > > Hide your children and hide your women; I want to see the direst,
> > > nastiest, rawest, fastest possible implementation of this function.

-- 
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: Working with protocols

2010-12-22 Thread Nicolas Buduroi
On Dec 22, 1:03 pm, David Nolen  wrote:
> (Foo.) is a Java method call determined at compile-time. If you change the
> definition of the Foo type/record, create-foo will be out of date. Default
> constructor fns could alleviate this but I think some design/modularity
> issues need to be hashed out.

Yes, I've realized this when developing this project. At first, it was
less modular and I encountered much more of such issues. I also used
`immigrate` previously and that was causing troubles not only with
protocols, but with multimethods also. In the end there still appears
to be some problems while developing protocol based code in a REPL-
driven fashion. I was hoping I did something wrong that somebody could
point out.

P.S.: It makes me wonder if there's some improvements that can be done
to make that type of coding more REPL friendly.

-- 
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: Let's see how fast we can make this

2010-12-22 Thread Rayne
I actually pasted the wrong code here:

(defn count-num-chars [^String s]
  (let [len (.length s)
space (int 32)]
(loop [i (int 0), c (int 0)]
  (if (< i len)
(recur
 (inc i)
 (if (== (int (.charAt s i)) space)
   c
   (unchecked-inc c)))
c


On Dec 22, 12:19 pm, Rayne  wrote:
> chouser wrote a solution earlier. I and a buddy modified it (a very
> little) bit and managed to get it pretty blazing:
>
> ra...@ubuntu:~$ cake run ~/challenge.clj
> Chars outputted: 460
> Time (in nanoseconds): 5768.677
>
> Here is the function:
>
> (defn count-num-chars [^String s]
>   (let [len (.length s)
>         space (int 32)]
>     (loop [i (int 0), c (int 0)]
>       (if (< i len)
>         (recur
>          (inc i)
>          (if (== (.codePointAt s i) space)
>            c
>            (unchecked-inc c)))
>         c
>
> On Dec 22, 11:52 am, Rayne  wrote:
>
>
>
> > I have a piece of code, and I'd like to see how fast it can be.
>
> > (defn count-num-chars [^String s]
> >   (loop [s s acc 0]
> >     (if (seq s)
> >       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
> >       acc)))
>
> > This is the fastest I've been able to get it. The function is very
> > simple. It takes a string and counts the number of non-space
> > characters inside of that string.
>
> > I've been testing this code against a 460 non-space character string.
> > Here is the entire source, benchmarking and all:
>
> > (def s (apply str (repeat 20 "This is a really long string")))
>
> > (defn count-num-chars [^String s]
> >   (loop [s s acc 0]
> >     (if (seq s)
> >       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
> >       acc)))
>
> > (println "Chars outputted:" (count-num-chars s))
>
> > (let [before (System/nanoTime)]
> >   (dotimes [_ 1000]
> >     (count-num-chars s))
> >   (let [after (System/nanoTime)]
> >     (println "Time (in nanoseconds):" (/ (- after before) 1000.0
>
> > Running it gives me around 137343.295 nanoseconds. I've seen some Java
> > algorithms that could run at just under 3000 nanoseconds.
>
> > Hide your children and hide your women; I want to see the direst,
> > nastiest, rawest, fastest possible implementation of this function.

-- 
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: Let's see how fast we can make this

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 1:22 PM, Ken Wesson  wrote:

>
> (defn count-num-chars [^String s]
>   (let [l (int (.length s))]
>(loop [i (int 0) acc (int 0)]
>  (if (< i l)
>(recur (unchecked-inc i) (if (= (.charAt s i) \space) acc
> (unchecked-inc acc)))
>acc
>
> 15k nsec -- twice as fast as before. Still 5x slower than Java; I'm
> not sure why. This is now directly equivalent to the obvious Java
> implementation,
>

If you're on 1.2 performance will suffer from boxing/unboxing numbers as
well as vars being dynamically rebindable by default.

You should see a reasonable jump in perf for the same code on the latest 1.3
alphas. You can also remove all those 'int' type-hints.

David

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

*print-dup* and records

2010-12-22 Thread Brent Millare
Hello,

I'm trying to use *print-dup* to allow writing clojure data to a file
and then read it back, however, I'm getting problems even with this
simple case. Is there something I am doing wrong? What do I need to do
to get this to work?

Clojure 1.3.0-alpha3-SNAPSHOT
user=> (defrecord TreeNode [val left right]) ;;create the record
user.TreeNode
user=> (TreeNode. 5 nil nil)
#:user.TreeNode{:val 5, :left nil, :right nil} ;; it works just fine
user=> (binding [*print-dup* true] (prn (TreeNode. 5 nil nil))) ;; use
*print-dup* to support reading in and preserving type
#=(user.TreeNode/create {:val #=(java.lang.Long. "5"), :left
nil, :right nil}) ;; this is the form we need to copy paste
nil
user=> #=(user.TreeNode/create {:val #=(java.lang.Long. "5"), :left
nil, :right nil}) ;;trying to copy and paste
IllegalArgumentException No matching method found: create
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:50) ;;we
have an error
user=>

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


Re: My first Clojure program: request for code review

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 1:22 PM, David Nolen  wrote:

> On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai  wrote:
>
>> Hi Ken,
>>
>> > user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
>> > [1 2 (3 4 5)]
>> > user=> (let [[x y z] [1 2 3 4 5]] [x y z])
>> > [1 2 3]
>> > user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
>> > [3 4]
>> >
>> > You can grab any fixed position in this way, as well as a "rest" that
>> > is the tail of the sequence past the last of such.
>>
>> Right, that's true.  However, Marek had given two examples of Python
>> tuple unpacking, the first being:
>>
>> > first, *middle, last = sequence(...)
>>
>> Which I believe in Python 3 will bind 'first' to the first element,
>> 'last' to the last element, and 'middle' to a sequence of all the
>> elements in the middle.  That last part is what I don't know how to do
>> in Clojure.
>
>
> One way:
>
> (let [[[f & m] l] ((juxt drop-last last) '[a b c d])] [f m l]) ;; [a (b c)
> c]
>
> David
>

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

David

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

Re: My first Clojure program: request for code review

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 1:14 PM, Benny Tsai  wrote:

> Hi Ken,
>
> > user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
> > [1 2 (3 4 5)]
> > user=> (let [[x y z] [1 2 3 4 5]] [x y z])
> > [1 2 3]
> > user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
> > [3 4]
> >
> > You can grab any fixed position in this way, as well as a "rest" that
> > is the tail of the sequence past the last of such.
>
> Right, that's true.  However, Marek had given two examples of Python
> tuple unpacking, the first being:
>
> > first, *middle, last = sequence(...)
>
> Which I believe in Python 3 will bind 'first' to the first element,
> 'last' to the last element, and 'middle' to a sequence of all the
> elements in the middle.  That last part is what I don't know how to do
> in Clojure.


One way:

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

David

-- 
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: Let's see how fast we can make this

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 12:52 PM, Rayne  wrote:
> I have a piece of code, and I'd like to see how fast it can be.
>
> (defn count-num-chars [^String s]
>  (loop [s s acc 0]
>    (if (seq s)
>      (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>      acc)))
>
> This is the fastest I've been able to get it. The function is very
> simple. It takes a string and counts the number of non-space
> characters inside of that string.
>
> I've been testing this code against a 460 non-space character string.
> Here is the entire source, benchmarking and all:
>
> (def s (apply str (repeat 20 "This is a really long string")))
>
> (defn count-num-chars [^String s]
>  (loop [s s acc 0]
>    (if (seq s)
>      (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>      acc)))
>
> (println "Chars outputted:" (count-num-chars s))
>
> (let [before (System/nanoTime)]
>  (dotimes [_ 1000]
>    (count-num-chars s))
>  (let [after (System/nanoTime)]
>    (println "Time (in nanoseconds):" (/ (- after before) 1000.0
>
> Running it gives me around 137343.295 nanoseconds.

I get around half that.

Yours calls seq every loop. Writing

(defn count-num-chars [^String s]
 (loop [s (seq s) acc 0]
   (if s
 (recur (next s) (if (= (first s) \space) acc (inc acc)))
 acc)))

results in about 10% savings.

Using primitive math:

(defn count-num-chars [^String s]
 (loop [s (seq s) acc (int 0)]
   (if s
 (recur (next s) (if (= (first s) \space) acc (unchecked-inc acc)))
 acc)))

yields up another 10% or so.

That's maybe 40,000ns, still over 10x slower than the Java
implementations you mentioned, but it's about the limits of the
savings we'll get while still using the seq abstraction, I suspect. To
get closer to Java performance means getting closer to Java means of
doing it:

(defn count-num-chars [^String s]
  (let [l (int (.length s))]
(loop [i (int 0) acc (int 0)]
  (if (< i l)
(recur (unchecked-inc i) (if (= (.charAt s i) \space) acc
(unchecked-inc acc)))
acc

15k nsec -- twice as fast as before. Still 5x slower than Java; I'm
not sure why. This is now directly equivalent to the obvious Java
implementation,

int l = s.length();
int acc = 0;
for (i = 0; i < l; ++i)
if (s.charAt(i) == ' ') ++acc;

and since the string is type-hinted it shouldn't be using reflection
for the length or charAt calls.

-- 
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: Let's see how fast we can make this

2010-12-22 Thread Rayne
chouser wrote a solution earlier. I and a buddy modified it (a very
little) bit and managed to get it pretty blazing:

ra...@ubuntu:~$ cake run ~/challenge.clj
Chars outputted: 460
Time (in nanoseconds): 5768.677

Here is the function:

(defn count-num-chars [^String s]
  (let [len (.length s)
space (int 32)]
(loop [i (int 0), c (int 0)]
  (if (< i len)
(recur
 (inc i)
 (if (== (.codePointAt s i) space)
   c
   (unchecked-inc c)))
c

On Dec 22, 11:52 am, Rayne  wrote:
> I have a piece of code, and I'd like to see how fast it can be.
>
> (defn count-num-chars [^String s]
>   (loop [s s acc 0]
>     (if (seq s)
>       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>       acc)))
>
> This is the fastest I've been able to get it. The function is very
> simple. It takes a string and counts the number of non-space
> characters inside of that string.
>
> I've been testing this code against a 460 non-space character string.
> Here is the entire source, benchmarking and all:
>
> (def s (apply str (repeat 20 "This is a really long string")))
>
> (defn count-num-chars [^String s]
>   (loop [s s acc 0]
>     (if (seq s)
>       (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>       acc)))
>
> (println "Chars outputted:" (count-num-chars s))
>
> (let [before (System/nanoTime)]
>   (dotimes [_ 1000]
>     (count-num-chars s))
>   (let [after (System/nanoTime)]
>     (println "Time (in nanoseconds):" (/ (- after before) 1000.0
>
> Running it gives me around 137343.295 nanoseconds. I've seen some Java
> algorithms that could run at just under 3000 nanoseconds.
>
> Hide your children and hide your women; I want to see the direst,
> nastiest, rawest, fastest possible implementation of this function.

-- 
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: Let's see how fast we can make this

2010-12-22 Thread nicolas.o...@gmail.com
Which version of Clojure are you using?
(How to speed that up depends a lot of the version you use)

I would like to see a with a longer run.
Optimised clojure is *asymptotically* nearly as fast as Java.
With under 1000 calls I am not sure the JIT is called.

Best,

Nicolas.


On Wed, Dec 22, 2010 at 5:52 PM, Rayne  wrote:
> I have a piece of code, and I'd like to see how fast it can be.
>
> (defn count-num-chars [^String s]
>  (loop [s s acc 0]
>    (if (seq s)
>      (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>      acc)))
>
> This is the fastest I've been able to get it. The function is very
> simple. It takes a string and counts the number of non-space
> characters inside of that string.
>
> I've been testing this code against a 460 non-space character string.
> Here is the entire source, benchmarking and all:
>
> (def s (apply str (repeat 20 "This is a really long string")))
>
> (defn count-num-chars [^String s]
>  (loop [s s acc 0]
>    (if (seq s)
>      (recur (rest s) (if (= (first s) \space) acc (inc acc)))
>      acc)))
>
> (println "Chars outputted:" (count-num-chars s))
>
> (let [before (System/nanoTime)]
>  (dotimes [_ 1000]
>    (count-num-chars s))
>  (let [after (System/nanoTime)]
>    (println "Time (in nanoseconds):" (/ (- after before) 1000.0
>
> Running it gives me around 137343.295 nanoseconds. I've seen some Java
> algorithms that could run at just under 3000 nanoseconds.
>
> Hide your children and hide your women; I want to see the direst,
> nastiest, rawest, fastest possible implementation of this function.
>
> --
> 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



-- 
Sent from an IBM Model M, 15 August 1989.

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
> Just FYI, it's not applicable here but there is also rseq, which
> returns a reversed view on a collection in constant time. It only
> works on vectors and sorted maps, though.

Good stuff, thank you Justin :)

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Hi Ken,

> user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
> [1 2 (3 4 5)]
> user=> (let [[x y z] [1 2 3 4 5]] [x y z])
> [1 2 3]
> user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
> [3 4]
>
> You can grab any fixed position in this way, as well as a "rest" that
> is the tail of the sequence past the last of such.

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

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

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

-- 
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: Working with protocols

2010-12-22 Thread David Nolen
On Wed, Dec 22, 2010 at 12:53 PM, Nicolas Buduroi wrote:

> Hi, I've been working lately on my first project (https://github.com/
> budu/lobos) that use protocols. Up until now, it's been quite
> infuriating, I can't stop getting seemingly random "No implementation
> of method" exceptions and I really don't understand why


Working with protocols/deftype/defrecprd generally requires that you
recompile the whole file when you make a modification. If you stick to that
you'll avoid a lot of confusing REPL states.

Consider:

(defn create-foo []
  (Foo.))

(Foo.) is a Java method call determined at compile-time. If you change the
definition of the Foo type/record, create-foo will be out of date. Default
constructor fns could alleviate this but I think some design/modularity
issues need to be hashed out.

David

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

Working with protocols

2010-12-22 Thread Nicolas Buduroi
Hi, I've been working lately on my first project (https://github.com/
budu/lobos) that use protocols. Up until now, it's been quite
infuriating, I can't stop getting seemingly random "No implementation
of method" exceptions and I really don't understand why.

For example here's what happened this morning. In this project I have
a Creatable protocol that contains only one method: create. It is
currently implemented by two records: Table and Schema. I realized I
hadn't updated the example in the readme file and while testing that
code it threw an error because I changed stuff yesterday and the
object passed to the create method was a function. I call it a second
time, after fixing (at the REPL) that mistake, and there was a bug in
my code when calling create on a MapEntry instead of a Table. I fixed
(in the file) that issue and after that all I get when trying out the
same call is "No implementation of method" for the Schema class. I
review the code (it should work), try stuff and here's the really
strange thing:

user> (create (schema :test {}) nil)
#:lobos.ast.CreateSchemaStatement{:cnx nil, :sname :test, :elements
()}
user> (create (sample-schema) nil)
; Evaluation aborted.
user> (type  (schema :test {}))
lobos.schema.Schema
user> (type (sample-schema))
lobos.schema.Schema

I wasn't able to narrow down what is the problem exactly. The only way
I found to fix that kind of problem is the kill the JVM and restart
the whole thing. This is just one example, a lot of similar situations
happened during the past few days. It may be related more to my
development environment or the way I'm using it. I'm using Clojure 1.2
and swank-clojure 1.2.1 in Emacs from which I connect to a swank
instance launched from Leiningen. I'm using the REPL to test my code
and after I've changed a file I use slime-eval-buffer. I wonder if
there's some general issues with this setup or advices on working with
protocols that can help me?

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


Let's see how fast we can make this

2010-12-22 Thread Rayne
I have a piece of code, and I'd like to see how fast it can be.

(defn count-num-chars [^String s]
  (loop [s s acc 0]
(if (seq s)
  (recur (rest s) (if (= (first s) \space) acc (inc acc)))
  acc)))

This is the fastest I've been able to get it. The function is very
simple. It takes a string and counts the number of non-space
characters inside of that string.

I've been testing this code against a 460 non-space character string.
Here is the entire source, benchmarking and all:

(def s (apply str (repeat 20 "This is a really long string")))

(defn count-num-chars [^String s]
  (loop [s s acc 0]
(if (seq s)
  (recur (rest s) (if (= (first s) \space) acc (inc acc)))
  acc)))

(println "Chars outputted:" (count-num-chars s))

(let [before (System/nanoTime)]
  (dotimes [_ 1000]
(count-num-chars s))
  (let [after (System/nanoTime)]
(println "Time (in nanoseconds):" (/ (- after before) 1000.0

Running it gives me around 137343.295 nanoseconds. I've seen some Java
algorithms that could run at just under 3000 nanoseconds.

Hide your children and hide your women; I want to see the direst,
nastiest, rawest, fastest possible implementation of this function.

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 12:31 PM, Laurent PETIT  wrote:
>
>
> 2010/12/22 Ken Wesson 
>>
>> On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai  wrote:
>> > Hi Marek,
>> >> Great! I was wondering whether Clojure supports something like
>> >> tuple-unpacking in Python. Does it also support "patterned"
>> >> destructuring like:
>> >>
>> >> first, *middle, last = sequence(...)
>> >> -or-
>> >> first, rest = sequence(...)
>> >>
>> >> The latter could be achived by something like `first+rest', I suppose,
>> >> but don't know the "Clojure" name for it.
>> >
>> > The latter is definitely supported; the name after a '&' will be bound
>> > to the remainder of a sequence:
>> >
>> > user=> (let [[fst & rst] [1 2 3]] (println "first:" fst "rest:" rst))
>> > first: 1 rest: (2 3)
>> >
>> > But I don't know of a way to bind the 'middle' elements of a sequence
>> > to something.
>>
>> user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
>> [1 2 (3 4 5)]
>> user=> (let [[x y z] [1 2 3 4 5]] [x y z])
>> [1 2 3]
>> user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
>> [3 4]
>>
>> You can grab any fixed position in this way, as well as a "rest" that
>> is the tail of the sequence past the last of such.
>>
>> By the way, what is "fmap"? It has no entry at
>> http://clojure.github.com/clojure/clojure.core-api.html, and
>>
>> user=> fmap
>> #> fmap in this context (NO_SOURCE_FILE:23)>
>>
>> in my copy of Clojure 1.2.
>
> Answer in Benny's first contribution to this thread: *
>  (:use [clojure.contrib.generic.functor :only (fmap)]))

Oh -- I didn't read back that far.

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Justin Kramer
On Dec 22, 10:59 am, Benny Tsai  wrote:
> > It does, but doesn't that make it less lazy? To reverse something, it
> > needs to evaluate the whole sequence. I yet have to learn how to
> > deal with lazyness.
> You're right, I hadn't realized 'reverse' is not lazy (I have a lot to
> learn about lazyness management myself :)).  In this case, though, I
> don't think it has too much impact, since:

Just FYI, it's not applicable here but there is also rseq, which
returns a reversed view on a collection in constant time. It only
works on vectors and sorted maps, though.

> By the way, what is "fmap"?

See the ns declaration:

> (ns karma
>  (:use [clojure.contrib.duck-streams :only (read-lines)])
>  (:use [clojure.contrib.generic.functor :only (fmap)]))

Justin

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Laurent PETIT
2010/12/22 Ken Wesson 

> On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai  wrote:
> > Hi Marek,
> >> Great! I was wondering whether Clojure supports something like
> >> tuple-unpacking in Python. Does it also support "patterned"
> >> destructuring like:
> >>
> >> first, *middle, last = sequence(...)
> >> -or-
> >> first, rest = sequence(...)
> >>
> >> The latter could be achived by something like `first+rest', I suppose,
> >> but don't know the "Clojure" name for it.
> >
> > The latter is definitely supported; the name after a '&' will be bound
> > to the remainder of a sequence:
> >
> > user=> (let [[fst & rst] [1 2 3]] (println "first:" fst "rest:" rst))
> > first: 1 rest: (2 3)
> >
> > But I don't know of a way to bind the 'middle' elements of a sequence
> > to something.
>
> user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
> [1 2 (3 4 5)]
> user=> (let [[x y z] [1 2 3 4 5]] [x y z])
> [1 2 3]
> user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
> [3 4]
>
> You can grab any fixed position in this way, as well as a "rest" that
> is the tail of the sequence past the last of such.
>
> By the way, what is "fmap"? It has no entry at
> http://clojure.github.com/clojure/clojure.core-api.html, and
>
> user=> fmap
> # fmap in this context (NO_SOURCE_FILE:23)>
>
> in my copy of Clojure 1.2.
>

Answer in Benny's first contribution to this thread: *
 (:use [clojure.contrib.generic.functor :only (fmap)]))

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

Re: My first Clojure program: request for code review

2010-12-22 Thread Ken Wesson
On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai  wrote:
> Hi Marek,
>> Great! I was wondering whether Clojure supports something like
>> tuple-unpacking in Python. Does it also support "patterned"
>> destructuring like:
>>
>> first, *middle, last = sequence(...)
>> -or-
>> first, rest = sequence(...)
>>
>> The latter could be achived by something like `first+rest', I suppose,
>> but don't know the "Clojure" name for it.
>
> The latter is definitely supported; the name after a '&' will be bound
> to the remainder of a sequence:
>
> user=> (let [[fst & rst] [1 2 3]] (println "first:" fst "rest:" rst))
> first: 1 rest: (2 3)
>
> But I don't know of a way to bind the 'middle' elements of a sequence
> to something.

user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
[1 2 (3 4 5)]
user=> (let [[x y z] [1 2 3 4 5]] [x y z])
[1 2 3]
user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
[3 4]

You can grab any fixed position in this way, as well as a "rest" that
is the tail of the sequence past the last of such.

By the way, what is "fmap"? It has no entry at
http://clojure.github.com/clojure/clojure.core-api.html, and

user=> fmap
#

in my copy of Clojure 1.2.

-- 
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: Out of memory

2010-12-22 Thread Laurent PETIT
2010/12/22 Jeff Palmucci 

> I've worked around this sort of thing in the past by wrapping the
> initialization in a closure. My macros:
>
> (defmacro once-fn "Define a function that should only be called once.
> Releases local storage earlier"
>  [args & body]
>  `(^{:once true} fn* ~args ~...@body))
>
> (defmacro top-level-run "work around a memory leak in the repl"
>  [& body]
>  `((once-fn []
>  ~...@body)))
>
> You'll find that:
>
> (def out_of_mem (top-level-run (reduce + 0 (range 5
>
> does not run out of memory.
>

Couldn't just it be a wrap with (let [] ), and let the choice of running it
once or not by choosing either def or defonce :

user=> (def x (reduce + (range 5000)))
java.lang.OutOfMemoryError: Java heap space (NO_SOURCE_FILE:1)
user=> (def x (let [] (reduce + (range 5000
#'user/x
user=> (defonce y (let [] (reduce + (range 5000
#'user/y
user=> (defonce y (let [] (reduce + (range 5000
nil
user=> (defonce z (reduce + (range 5000)))
#'user/z
user=> (defonce z (reduce + (range 5000)))
nil
user=> x
12497500
user=> y
12497500
user=> z
12497500
user=>

-- 
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: Automatically unmapping unit tests from namespaces

2010-12-22 Thread Constantine Vetoshev
On Dec 21, 7:16 pm, Phil Hagelberg  wrote:
> If you're already using swank then you can try clojure-test-mode; it
> clears out all deftests in between test runs.
>
> https://github.com/technomancy/clojure-mode/blob/master/clojure-test-...
>
> It also highlights failures in the test buffer for better feedback.

clojure-test-mode is pretty nice, but is there any way to make its
test namespace naming convention configurable?

It currently expects src/com/company/project/file.clj to correspond to
test/com/company/project/test/file.clj. I prefer test/test/com/company/
project/file.clj, i.e., just prefix the whole namespace with "test",
rather than insert it as the penultimate namespace element. I find it
much easier to tell, at a glance, if I'm looking at a test namespace
if it just starts with "test", rather than hunting through the entire
dotted string.

-- 
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: Automatically unmapping unit tests from namespaces

2010-12-22 Thread gaz jones
you can also move to the failed test and press C-c ' and it will show
them in the mini-buffer

On Tue, Dec 21, 2010 at 11:47 PM, Michael Ossareh  wrote:
>
>
> On Tue, Dec 21, 2010 at 21:36, Michael Ossareh  wrote:
>>
>> On Tue, Dec 21, 2010 at 16:16, Phil Hagelberg  wrote:
>>>
>>> It also highlights failures in the test buffer for better feedback.
>>
>> when there is a failure where are the details of the failure printed out
>> to? I love that the highlight shows me which test have errors, but since
>> I've moved over to the emacs starter kit (thanks!!) I've lost the error
>> output and have to switch to a terminal to run lein test.
>
> The answer: the repl buffer.
> I've no idea why they weren't - but they are now. I'll take it :)
>
> --
> 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: Out of memory

2010-12-22 Thread Jeff Palmucci
I've worked around this sort of thing in the past by wrapping the
initialization in a closure. My macros:

(defmacro once-fn "Define a function that should only be called once.
Releases local storage earlier"
  [args & body]
  `(^{:once true} fn* ~args ~...@body))

(defmacro top-level-run "work around a memory leak in the repl"
  [& body]
  `((once-fn []
  ~...@body)))

You'll find that:

(def out_of_mem (top-level-run (reduce + 0 (range 5

does not run out of memory.

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Benny Tsai
Hi Marek,

> > - To sort the nicks by karma in descending order, instead of sorting
> > by the negation of the karma, I used (reverse (sort-by ...)); again,
> > just a subjective thing, makes the intent more clear to me.
>
> It does, but doesn't that make it less lazy? To reverse something, it
> needs to evaluate the whole sequence. I yet have to learn how to
> deal with lazyness.

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

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

FYI, 'reduce' is also not lazy.

> Great! I was wondering whether Clojure supports something like
> tuple-unpacking in Python. Does it also support "patterned"
> destructuring like:
>
> first, *middle, last = sequence(...)
> -or-
> first, rest = sequence(...)
>
> The latter could be achived by something like `first+rest', I suppose,
> but don't know the "Clojure" name for it.

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

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

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

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


Re: Mocking multimethods

2010-12-22 Thread Alex Baranosky
I love Midje and think migrating all the tests to it is a great idea.

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

2010-12-22 Thread Alyssa Kwan
Thanks, Brian!  I obviously didn't understand the nature of the
provided form.  That's really cool notation!  This is exactly what I
want.

What are the cons of using midje?  Any reason I shouldn't migrate all
my unit testing to it?

Thanks!
Alyssa

On Dec 22, 9:46 am, Brian Marick  wrote:
> On Dec 22, 2010, at 6:52 AM, Alyssa Kwan wrote:
>
> > The issue is where do I specify that:
> > (undo-fn ...patch...) => (fn [] (reset! visible-evidence-of-a-side-
> > effect :happened!))
>
> The code you quoted is that specification. It doesn't matter that undo-fn is 
> a multimethod.
>
> Here's what the notation of the test says:
>
>    When called with an arbitrary patch, undo-patch will produce a particular 
> side effect. It does that because it uses undo-patch, which--when given that 
> arbitrary patch--returns a function that produces that side effect.
>    It also calls remove-patch with the given patch.
>    undo-patch can return anything it wants. We don't care.
>
>
>
> > (fact "The patch's undo-fn is called for its side effect and the patch is 
> > forgotten"
> >  (let [visible-evidence-of-a-side-effect (atom nil)]
> >    (undo-patch ...patch...) => anything
> >    (provided
> >      (undo-fn ...patch...) => (fn [] (reset! 
> > visible-evidence-of-a-side-effect :happened!))
> >      (remove-patch ...patch...) => :nothing-of-interest)
> >   �...@visible-evidence-of-a-side-effect => :happened!))
>
> -
> 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


Re: Mocking multimethods

2010-12-22 Thread Brian Marick

On Dec 22, 2010, at 6:52 AM, Alyssa Kwan wrote:

> The issue is where do I specify that:
> (undo-fn ...patch...) => (fn [] (reset! visible-evidence-of-a-side-
> effect :happened!))


The code you quoted is that specification. It doesn't matter that undo-fn is a 
multimethod.

Here's what the notation of the test says:

   When called with an arbitrary patch, undo-patch will produce a particular 
side effect. It does that because it uses undo-patch, which--when given that 
arbitrary patch--returns a function that produces that side effect. 
   It also calls remove-patch with the given patch.
   undo-patch can return anything it wants. We don't care.

> 
> (fact "The patch's undo-fn is called for its side effect and the patch is 
> forgotten"
>  (let [visible-evidence-of-a-side-effect (atom nil)]
>(undo-patch ...patch...) => anything
>(provided
>  (undo-fn ...patch...) => (fn [] (reset! 
> visible-evidence-of-a-side-effect :happened!))
>  (remove-patch ...patch...) => :nothing-of-interest)
>@visible-evidence-of-a-side-effect => :happened!))


-
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


Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Mark Engelberg 

> I've decided to go with the old gen-class approach (mainly so I can
> take advantage of the "state" option).
> I'm running into a problem implementing Iterable.
> The following lines in gen-class create a conflict:
>   :implements [java.lang.Iterable]
>   :methods [[iterator [] java.util.Iterator]]
>
> It compiles, but when I instantiate a class, I get an error message of
> a duplicate method name&sig.  I've narrowed it down to a problem with
> the signature of the iterator method (if I loosen the return type to
> Object, the class instantiates fine).
> Any ideas what's wrong with that signature for iterator?


Yes, I don't have a REPL at hand, but my guess is that you should just drop
the corresponding :methods ... line.
You don't need to repeat methods sigs inherited from classes / interfaces,
:methods is for declaring public methods beyond that. (And so it seems that
not only is it not needed, but rather that you must not do it).

HTH,

-- 
Laurent

-- 
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: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
I've decided to go with the old gen-class approach (mainly so I can
take advantage of the "state" option).
I'm running into a problem implementing Iterable.
The following lines in gen-class create a conflict:
   :implements [java.lang.Iterable]
   :methods [[iterator [] java.util.Iterator]]

It compiles, but when I instantiate a class, I get an error message of
a duplicate method name&sig.  I've narrowed it down to a problem with
the signature of the iterator method (if I loosen the return type to
Object, the class instantiates fine).
Any ideas what's wrong with that signature for iterator?  It seems to
match the method signature of iterator in the Java reference for
java.lang.Iterable.

[This is in Clojure 1.2]

Thanks,

Mark

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


Re: Clojure, Parallel programming and Leslie Lamport

2010-12-22 Thread Johann Hibschman
Konrad Hinsen  writes:

> Thanks for the link! Judging from the example in the README, it's a
> library for task farming in Clojure. While that's a limited form of
> parallelism, there are still lots of applications where it is useful,
> so I'd say this library is definitely worth a closer look. However, it
> doesn't seem to deal with distributed data.

Distributed data is hard, though, partly because kind of distribution
you need depends on your calculation. Every time I've had to do a
distributed calculations, I've always just used the filesystem for data.

I see a lot of frameworks that assume the data is small and can be
entirely contained in the "message," while I need some kind of data
affinity. (I do model estimation on large data sets, so I'd like to send
a lump of data to different nodes, leave it there, then exchange
parameter vectors and error scores with a controller.)

In today's world, I've found I get more done faster with a single 8-core
machine with a lot of RAM (96 GB now; at a previous employer I had
access to a 512 GB monster) than I would with a farm of machines with
only 4 GB or 8 GB, so I'm back to concurrency.  Of course, that's just
because my data is large, but not too large.


>>  I come from the scientific computing community .. the likes of
>> Computation Fluid Dynamics and related topics.. large matrix
>> operations and such stuff..
>
> My background is somewhat similar: molecular simulations and analysis
> of large data sets.

I did astronomy, but mostly small-scale stuff.  Integration, cascade
calculations, the like.  These days, though, I'm doing finance,
mortgages in particular.  That's a field that's been fun for the past
few years.

-Johann

-- 
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, Parallel programming and Leslie Lamport

2010-12-22 Thread Konrad Hinsen

On 22 Dec 2010, at 14:02, Sunil S Nandihalli wrote:

 I am interested in distributed parallel computing too ... I have  
prior experience coding with MPI and c .. but that besides the  
point .. while I was looking at options with clojure .. I recently  
came across swarmiji. https://github.com/amitrathore/swarmiji


Thanks for the link! Judging from the example in the README, it's a  
library for task farming in Clojure. While that's a limited form of  
parallelism, there are still lots of applications where it is useful,  
so I'd say this library is definitely worth a closer look. However, it  
doesn't seem to deal with distributed data.


 I come from the scientific computing community .. the likes of  
Computation Fluid Dynamics and related topics.. large matrix  
operations and such stuff..


My background is somewhat similar: molecular simulations and analysis  
of large data sets.


Konrad.

--
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, Parallel programming and Leslie Lamport

2010-12-22 Thread Sunil S Nandihalli
Hello Tim and Konrad,
 I am interested in distributed parallel computing too ... I have prior
experience coding with MPI and c .. but that besides the point .. while I
was looking at options with clojure .. I recently came across swarmiji.
https://github.com/amitrathore/swarmiji I don't know much to make any
technical analysis of the tool .. just thought of throwing what little I
knew in to the pot .. would love to hear any technical analysis from either
of you or anybody else...

 I come from the scientific computing community .. the likes of Computation
Fluid Dynamics and related topics.. large matrix operations and such
stuff..

Sunil.

On Wed, Dec 22, 2010 at 2:20 PM, Konrad Hinsen
wrote:

> On 22 Dec 2010, at 09:28, Tim Daly wrote:
>
>  Clojure works well for concurrency but does not really address
>> the parallel question well. For that I've turned to MPI.
>> I am working on using MPI from Clojure.
>>
>
> That's a topic I am very interested in as well, although unfortunately I
> never find the time to really do something. Some random thoughts based on
> what I did look at in the past:
>
> 1) Parallel computing vs. distributed computing: these are two different
> levels of complexity in my opinion. Parallel computing in a shared-memory
> environment (e.g. fork/join style) is a much simpler problem than parallel
> computing on distributed-memory systems, where you have to take care of
> distributing data among the machines and try to minimize data exchange in
> addition to balancing CPU load. There are some interesting approaches in
> Clojure's par branch for the first problem. The second one deserves to be
> tackled as well, but we should use another label than "parallel" to reduce
> confusion.
>
> 2) MPI via Java - which one do you plan to use?
>
> 3) Exchanging data between nodes: as far as I know many Clojure data types,
> in particular closures, are not serializable yet.
>
> 4) Efficient data exchange between nodes: it would be nice to able to
> profit from MPI's efficiency for large homogeneous data sets (read: arrays)
> in Clojure as well. Java arrays should be easy to handle efficiently, but
> Clojure code tends to avoid them. Perhaps primitive-type vectors could be
> transferred as arrays as well?
>
> 5) High-level layer: MPI is much too low-level for daily use. For
> distributed programming in Clojure, I'd like to have a higher-level model
> which abstracts away the synchronization issues that lead to deadlocks, race
> conditions, and ultimately a miserable life for programmers. There are some
> good ideas in the PGAS languages that would perhaps work fine in a Clojure
> context as well.
>
>
>  These are some links others might find interesting.
>>
>
> At first glance this looks promising - they are on my "to watch" list.
> Thanks!
>
> Konrad.
>
>
> --
> 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: Mocking multimethods

2010-12-22 Thread Alyssa Kwan
The issue is where do I specify that:
(undo-fn ...patch...) => (fn [] (reset! visible-evidence-of-a-side-
effect :happened!))

undo-fn is a multimethod in my design, which requires a corresponding
defmethod for each patch type.  I need to create one for the scope of
the test, but defmethod by definition alters the top-level state of
the system, and doesn't automatically unroll like let or binding does.

On Dec 22, 6:33 am, Brian Marick  wrote:
> I think I misunderstand the issue, because this works for me:
>
> (ns midje.util.git
>   (:use [midje.sweet]))
>
> ;; Code except for undo-patch is the same as before.
> ;; ...
>
> ;; I pulled remove-patch out of undo-patch because I was
> ;; getting a screwy read error I didn't want to figure out
> ;; at 5 in the morning, but I'd probably do that anyway:
> ;;http://codebetter.com/jeremymiller/2006/12/03/composed-method-pattern/
>
> (defn remove-patch [patch]
>   (alter patches- #(remove (fn [p] (= patch p)) %)))
>
> (defn undo-patch [patch]
>  (let [fn (undo-fn patch)]
>    (dosync
>      (fn)
>      (remove-patch patch
>
> (fact "The patch's undo-fn is called for its side effect and the patch is 
> forgotten"
>   (let [visible-evidence-of-a-side-effect (atom nil)]
>     (undo-patch ...patch...) => anything
>     (provided
>       (undo-fn ...patch...) => (fn [] (reset! 
> visible-evidence-of-a-side-effect :happened!))
>       (remove-patch ...patch...) => :nothing-of-interest)
>     @visible-evidence-of-a-side-effect => :happened!))
>
> 1855 $ lein midje midje.util.git
> All claimed facts (2) have been confirmed.
> 1856 $
>
> -
> 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


Re: Mocking multimethods

2010-12-22 Thread Alyssa Kwan
I'd like to discuss this design approach.  (It's unrelated to the
testing issue.)  I avoided this design because the undo-fn is
determined at do-patch! time.  The use case is for a persistent system
like Git where patches may be undone long after being done - e.g. long
after the patch is written to the database.  In the meantime, the
system may be upgraded and the undo-fn for a patch may change.  If the
undo-fn and args is written to the database at do-patch! time, for
backwards compatibility, at undo-patch! time, the undo-fn would have
to be updated to whatever the new call is.

Contrast that with my current approach where only the fn is saved and
the undo-fn is determined at undo-patch! time.  For backwards
compatibility, the undo-fn would have to support legacy fn formats,
which I conjecture are slightly less likely to change than the
corresponding undo-fn.  This is a pure guess and is not based on real
requirements yet; I don't know that fns themselves are necessarily
more stable than their counterpart undo-fns.  It's a vague sense that
undo-fns are more subject to bug fixes:  fns themselves are processed
right away at do-patch! time, while undo-fns are like time bombs that
lay dormant until a patch has to be undone, long after the initial
patch.

In addition, in the current implementation I outlined, the undone
patch disappears.  The real implementation will most likely be a patch
with undo-patch! as the :fn and the patch being undone as the :arg.
This is necessary to support merging with remote branches like in
Git.  undo-patch!'s may themselves be undone, which would require 2
degrees of backwards compatibility:  converting the undo-fn in the
first undo, and converting the fn in the second undo.  Both approaches
have the same 2 degrees of backwards compatibility, but the command
approach still somehow seems more fragile.

I'd love to get your thoughts on this.  Anyone with experience working
on a similar system?

Thanks!
Alyssa

On Dec 22, 4:35 am, Meikel Brandmeyer  wrote:
> Hi,
>
> maybe a different approach could be to use a richer datatype than a function, 
> which carries both: the command and the undo command.
>
> (deftype Command [action undo])
>
> Then you could do something like:
>
> (defn do-patch!
>   [command args]
>   (dosync
>     (let [patch {:command command :args (vec args)}]
>       (apply (.action command) args)
>       (alter patches- conj patch)
>       patch)))
>
> (defn undo-patch!
>   []
>   (dosync
>     ((.undo (:command patch)))
>     (alter patches- pop)))
>
> Then you could provide specially crafted Commands and there would not be the 
> need to stub anything. Also Commands wouldn't have to be global objects.
>
> Sincerely
> Meikel

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

2010-12-22 Thread Brian Marick
I think I misunderstand the issue, because this works for me:

(ns midje.util.git
  (:use [midje.sweet]))

;; Code except for undo-patch is the same as before.
;; ...

;; I pulled remove-patch out of undo-patch because I was
;; getting a screwy read error I didn't want to figure out 
;; at 5 in the morning, but I'd probably do that anyway:
;; http://codebetter.com/jeremymiller/2006/12/03/composed-method-pattern/

(defn remove-patch [patch]
  (alter patches- #(remove (fn [p] (= patch p)) %)))

(defn undo-patch [patch]
 (let [fn (undo-fn patch)]
   (dosync
 (fn)
 (remove-patch patch

(fact "The patch's undo-fn is called for its side effect and the patch is 
forgotten"
  (let [visible-evidence-of-a-side-effect (atom nil)]
(undo-patch ...patch...) => anything
(provided
  (undo-fn ...patch...) => (fn [] (reset! visible-evidence-of-a-side-effect 
:happened!))
  (remove-patch ...patch...) => :nothing-of-interest)
@visible-evidence-of-a-side-effect => :happened!))

1855 $ lein midje midje.util.git
All claimed facts (2) have been confirmed. 
1856 $ 


-
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


Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Chas Emerick 

>
> On Dec 22, 2010, at 4:58 AM, Laurent PETIT wrote:
>
> > There's also this issue raised in the bug tracker (by Chas Emerick I
> presume ?) which is about adding a nice java facade for this kind of interop
> (and thus also ensuring some independance towards clojure internals).
> >
> > What about bringing it back to the table for inclusion in 1.3 ?
>
> I don't think it was rejected for 1.3, but I do need to propose a concrete
> patch:
>

Oh, things do not have to be "rejected" in order not to be included, they
just have to be forgotten about ;-)


>
> http://dev.clojure.org/jira/browse/CLJ-452
>
> - Chas
>
> --
> 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: Calling Clojure from Java

2010-12-22 Thread Chas Emerick

On Dec 22, 2010, at 4:58 AM, Laurent PETIT wrote:

> There's also this issue raised in the bug tracker (by Chas Emerick I presume 
> ?) which is about adding a nice java facade for this kind of interop (and 
> thus also ensuring some independance towards clojure internals).
> 
> What about bringing it back to the table for inclusion in 1.3 ?

I don't think it was rejected for 1.3, but I do need to propose a concrete 
patch:

http://dev.clojure.org/jira/browse/CLJ-452

- Chas

-- 
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: Calling Clojure from Java

2010-12-22 Thread Alex Osborne
Mark Engelberg  writes:

> Looks easy, but your dance and speak methods don't return a value
> which leaves a question in my mind...
>
> If the protocol implementation actually returns a value, do you have
> to explicitly typecast it in Java from Object into the desired type?

Yep, certainly.  A Clojure function can return any type so it has to be
that way generally.

However if you don't actually need the features of full protocols you
could use gen-interface instead:

(ns interop.core)

(gen-interface
 :name interop.core.Vocal
 :methods [[dance [Object] Object]
   [speak [] Object]
   [sum [int int] int]])

(deftype Chorus [noise]
  interop.core.Vocal
  (dance [this boogy] (println "Shuffle like a" boogy))
  (speak [this] (println "I say there!  I can hear a" noise))
  (sum [this x y] (+ x y)))

Then the client becomes:

import interop.core.Chorus;
import interop.core.Vocal;

public class Client {
public static void main(String args[]) {
Vocal voice = new Chorus("bird");
voice.speak();
voice.dance("pigeon");
int x = voice.sum(1, 2);
System.out.println("1 and 2 is " + x);
}
}

And so:

$ java -cp $(lein classpath) Client
I say there!  I can hear a bird
Shuffle like a pigeon
1 and 2 is 3

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


Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Mark Engelberg 

> Looks easy, but your dance and speak methods don't return a value
> which leaves a question in my mind...
>
> If the protocol implementation actually returns a value, do you have
> to explicitly typecast it in Java from Object into the desired type?
>

Yes

-- 
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: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
Looks easy, but your dance and speak methods don't return a value
which leaves a question in my mind...

If the protocol implementation actually returns a value, do you have
to explicitly typecast it in Java from Object into the desired type?

Thanks,

Mark

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


Re: Calling Clojure from Java

2010-12-22 Thread Alex Osborne
Mark Engelberg  writes:

> Are there any examples available of creating a compiled
> class/interface with deftype and defprotocol, and using these from
> Java?

It's pretty straightforward and works exactly how you might expect it
to.

Create a new project:

   $ lein new interop

Define a type and protocol in interop/src/interop/core.clj:

(ns interop.core)

(defprotocol Vocal
  (dance [this boogie])
  (speak [this]))

(deftype Chorus [noise]
  Vocal
  (dance [this boogie] (println "Shuffle like a" boogie))
  (speak [this] (println "I say there!  I can hear a" noise)))

(println "boom") ;; just curious if this will be executed

Mark the namespace to be AOT-compiled by lein in interop/project.clj:

(defproject interop "1.0.0"
  :aot [interop.core]
  :dependencies [[org.clojure/clojure "1.2.0"]])

Compile it:

$ lein compile

Create a Java client class interop/src/Client.java:

import interop.core.Chorus;
import interop.core.Vocal;

public class Client {
public static void main(String args[]) {
Vocal voice = new Chorus("bird");
voice.speak();
voice.dance("pigeon");
}
}

Compile it:

$ javac -cp $(lein classpath) src/Client.java

Run it:

$ java -cp $(lein classpath) Client
I say there!  I can hear a bird
Shuffle like a pigeon

-- 
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: Calling Clojure from Java

2010-12-22 Thread Meikel Brandmeyer
Hi,

Am 22.12.2010 um 11:15 schrieb Mark Engelberg:

> Are there any examples available of creating a compiled
> class/interface with deftype and defprotocol, and using these from
> Java?

Protocols also define an interface which can be implemented by classes. For 
deftype this happens when you specify the methods inline in the deftype 
definition. Then you can call the method directly on the object as you would do 
with any other java method. However this does not work for types which use 
extend to extend the protocol to the type. Here you still have to go through 
the protocol functions.

An example should look like this:

(ns some.name.space)

(defprotocol SomeProtocol
  (foo [this]))

(deftype SomeType
  [a b]
  SomeProtocol
  (foo [this] (str a b)))

Then in Java:

import some.name.space.SomeType;
…
SomeType st = new SomeType("some a", "and a b");
…
st.foo();

Not tested, though.

Sincerely
Meikel

-- 
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: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
Are there any examples available of creating a compiled
class/interface with deftype and defprotocol, and using these from
Java?

-- 
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: Calling Clojure from Java

2010-12-22 Thread Meikel Brandmeyer
Hi,

Am 22.12.2010 um 10:56 schrieb Mark Engelberg:

> On Wed, Dec 22, 2010 at 1:52 AM, Meikel Brandmeyer  wrote:
>> It is a little ugly, but works with any function, in particular static and 
>> protocol functions. If you want a less rough interface, you can still go the 
>> gen-class route from the article. But this will come at the cost of one 
>> level of indirection on method calls.
> 
> I had assumed that the Rt.var lookup to "find the function by string
> name" would be more indirect and slower than calling the method of an
> AOT compiled class.  Is that not the case?

It depends how often you do that, I'd think. If you need the function several 
times you can do the lookup up once and store the Var reference for later use. 
I don't know. I haven't checked. Maybe there is no difference after all. And 
the more I think about it, you might be right.

Anyway, gen-class requires AOT. I try to avoid that, but YMMV.

Sincerely
Meikel

-- 
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: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Mark Engelberg 

> On Wed, Dec 22, 2010 at 1:52 AM, Meikel Brandmeyer  wrote:
> > It is a little ugly, but works with any function, in particular static
> and protocol functions. If you want a less rough interface, you can still go
> the gen-class route from the article. But this will come at the cost of one
> level of indirection on method calls.
>
> I had assumed that the Rt.var lookup to "find the function by string
> name" would be more indirect and slower than calling the method of an
> AOT compiled class.  Is that not the case?
>

Methods of AOT compiled classes are not hard wired to the vars. They
reference the var, so basically you indeed have an additional level of
indirection.

-- 
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: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Meikel Brandmeyer 

> Hi,
>
> Am 22.12.2010 um 10:13 schrieb Mark Engelberg:
>
> > I'm trying to figure out how to bundle up some Clojure code into a jar
> > to be accessed by someone in Java.
> >
> > My google search turned up this link:
> > http://java.dzone.com/articles/java-clojure-interop-calling
> > which dates back to Clojure 1.1.
> >
> > Seems like a lot of changes have occurred since then -- static
> > functions, protocols, etc.  So has the "calling Clojure from Java"
> > story changed with Clojure 1.3?  If so, can anyone provide pointers to
> > some recent examples?
>
> If you just want to invoke some functions, you don't have to define a
> class. You can retrieve the corresponding Vars.
>
> Var someFn = RT.var("you.name.space", "some-fn");
> …
> someFn.invoke("Some", "arguments", goHere, 123);
>
> It is a little ugly, but works with any function, in particular static and
> protocol functions. If you want a less rough interface, you can still go the
> gen-class route from the article. But this will come at the cost of one
> level of indirection on method calls.
>

There's also this issue raised in the bug tracker (by Chas Emerick I presume
?) which is about adding a nice java facade for this kind of interop (and
thus also ensuring some independance towards clojure internals).

What about bringing it back to the table for inclusion in 1.3 ?

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

Re: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
On Wed, Dec 22, 2010 at 1:52 AM, Meikel Brandmeyer  wrote:
> It is a little ugly, but works with any function, in particular static and 
> protocol functions. If you want a less rough interface, you can still go the 
> gen-class route from the article. But this will come at the cost of one level 
> of indirection on method calls.

I had assumed that the Rt.var lookup to "find the function by string
name" would be more indirect and slower than calling the method of an
AOT compiled class.  Is that not the case?

-- 
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: Calling Clojure from Java

2010-12-22 Thread Meikel Brandmeyer
Hi,

Am 22.12.2010 um 10:13 schrieb Mark Engelberg:

> I'm trying to figure out how to bundle up some Clojure code into a jar
> to be accessed by someone in Java.
> 
> My google search turned up this link:
> http://java.dzone.com/articles/java-clojure-interop-calling
> which dates back to Clojure 1.1.
> 
> Seems like a lot of changes have occurred since then -- static
> functions, protocols, etc.  So has the "calling Clojure from Java"
> story changed with Clojure 1.3?  If so, can anyone provide pointers to
> some recent examples?

If you just want to invoke some functions, you don't have to define a class. 
You can retrieve the corresponding Vars.

Var someFn = RT.var("you.name.space", "some-fn");
…
someFn.invoke("Some", "arguments", goHere, 123);

It is a little ugly, but works with any function, in particular static and 
protocol functions. If you want a less rough interface, you can still go the 
gen-class route from the article. But this will come at the cost of one level 
of indirection on method calls.

Sincerely
Meikel

PS: Here an example of the above approach incl. namespace loading: 
https://bitbucket.org/kotarak/vimclojure/src/4f2b588aebbe/server/src/main/java/vimclojure/Nail.java

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


Re: My first Clojure program: request for code review

2010-12-22 Thread Marek Kubica
Hi,

Thanks for your review and your improvements (of course also to Justin,
whose improvements are also useful). I'll try to merge them into some
"optimal" solution :)

On Tue, 21 Dec 2010 20:46:56 -0800 (PST)
Benny Tsai  wrote:

> Hi Marek,
> 
> Here's my tweaked version:
> 
> (ns karma
>   (:use [clojure.contrib.duck-streams :only (read-lines)])
>   (:use [clojure.contrib.generic.functor :only (fmap)]))
> 
> (def allowed-nickname "[A-z]{1,16}")
> (def upvote-regexp (re-pattern (format "(%s)\\+\\+" allowed-
> nickname)))
> (def downvote-regexp (re-pattern (format "(%s)\\-\\-" allowed-
> nickname)))
> 
> (defn get-votes [regexp line]
>   (let [nicks (map second (re-seq regexp line))]
> (frequencies nicks)))
> 
> (defn get-histogram [line]
>   (let [upvotes (get-votes upvote-regexp line)
>   downvotes (fmap - (get-votes downvote-regexp line))]
> (merge-with + upvotes downvotes)))
> 
> (defn -main [& args]
>   (let [file-name (ffirst args)
>   histograms (map get-histogram (read-lines file-name))
>   histogram (apply merge-with + histograms)
>   non-zero-histogram (remove (comp zero? second) histogram)
>   sorted-by-karma (reverse (sort-by second non-zero-histogram))]
> (doseq [[nick karma] sorted-by-karma]
>   (println nick karma
> 
> (-main *command-line-args*)
> 
> The only non-trivial change is in the way the histogram is created.
> Instead of "updating" an accumulator map while processing each line, I
> create a mini-histogram for each line and then merge them together at
> the end.

Thats very neat. I need to think about it a bit to merge this with
Justins code, which only does one regexp matching per line.

> 'get-votes' is a lot like 'extract-nicks', but leverages the built-in
> 'frequencies' fn to build a histogram of the upvotes/downvotes in a
> line, depending on the regexp passed in:
> 
> karma=> (get-votes upvote-regexp "c++ d++ b++ c--")
> {"c" 1, "d" 1, "b" 1}
> karma=> (get-votes downvote-regexp "c++ d++ b++ c--")
> {"c" 1}
> 
> Given a line, 'get-histogram' uses 'get-votes' to get a histogram of
> the upvotes and a histogram of the downvotes.  It then uses 'fmap' to
> convert the downvotes into negative numbers:
> 
> karma=> (fmap - {"c" 1})
> {"c" -1}

Oh, fmap looks useful, good to know. I 'd probably use a map and
convert it back instead, but this is useful.

> - (first (first ...)) can be shortened into (ffirst ...)

Yeah, I'd usually use `caar' here :)

> - In cases like removing nicks with 0 karma, instead of (filter (not
> pred) ...), I prefer (remove pred ...); I find it a little easier to
> follow that way.

Oh, I didn't know about remove, that's nice.

> - To sort the nicks by karma in descending order, instead of sorting
> by the negation of the karma, I used (reverse (sort-by ...)); again,
> just a subjective thing, makes the intent more clear to me.

It does, but doesn't that make it less lazy? To reverse something, it
needs to evaluate the whole sequence. I yet have to learn how to
deal with lazyness.

> - In the final 'doseq', (first item) and (second item) can be replaced
> by destructuring.

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

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

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

> Hope you find this useful :)

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

2010-12-22 Thread Meikel Brandmeyer
Hi,

maybe a different approach could be to use a richer datatype than a function, 
which carries both: the command and the undo command.

(deftype Command [action undo])

Then you could do something like:

(defn do-patch!
  [command args]
  (dosync
(let [patch {:command command :args (vec args)}]
  (apply (.action command) args)
  (alter patches- conj patch)
  patch)))

(defn undo-patch!
  []
  (dosync
((.undo (:command patch)))
(alter patches- pop)))

Then you could provide specially crafted Commands and there would not be the 
need to stub anything. Also Commands wouldn't have to be global objects.

Sincerely
Meikel

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


Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
I'm trying to figure out how to bundle up some Clojure code into a jar
to be accessed by someone in Java.

My google search turned up this link:
http://java.dzone.com/articles/java-clojure-interop-calling
which dates back to Clojure 1.1.

Seems like a lot of changes have occurred since then -- static
functions, protocols, etc.  So has the "calling Clojure from Java"
story changed with Clojure 1.3?  If so, can anyone provide pointers to
some recent examples?

Thanks,

Mark

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


Re: Clojure, Parallel programming and Leslie Lamport

2010-12-22 Thread Konrad Hinsen

On 22 Dec 2010, at 09:28, Tim Daly wrote:


Clojure works well for concurrency but does not really address
the parallel question well. For that I've turned to MPI.
I am working on using MPI from Clojure.


That's a topic I am very interested in as well, although unfortunately  
I never find the time to really do something. Some random thoughts  
based on what I did look at in the past:


1) Parallel computing vs. distributed computing: these are two  
different levels of complexity in my opinion. Parallel computing in a  
shared-memory environment (e.g. fork/join style) is a much simpler  
problem than parallel computing on distributed-memory systems, where  
you have to take care of distributing data among the machines and try  
to minimize data exchange in addition to balancing CPU load. There are  
some interesting approaches in Clojure's par branch for the first  
problem. The second one deserves to be tackled as well, but we should  
use another label than "parallel" to reduce confusion.


2) MPI via Java - which one do you plan to use?

3) Exchanging data between nodes: as far as I know many Clojure data  
types, in particular closures, are not serializable yet.


4) Efficient data exchange between nodes: it would be nice to able to  
profit from MPI's efficiency for large homogeneous data sets (read:  
arrays) in Clojure as well. Java arrays should be easy to handle  
efficiently, but Clojure code tends to avoid them. Perhaps primitive- 
type vectors could be transferred as arrays as well?


5) High-level layer: MPI is much too low-level for daily use. For  
distributed programming in Clojure, I'd like to have a higher-level  
model which abstracts away the synchronization issues that lead to  
deadlocks, race conditions, and ultimately a miserable life for  
programmers. There are some good ideas in the PGAS languages that  
would perhaps work fine in a Clojure context as well.



These are some links others might find interesting.


At first glance this looks promising - they are on my "to watch" list.  
Thanks!


Konrad.

--
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, Parallel programming and Leslie Lamport

2010-12-22 Thread Tim Daly

 Clojure works well for concurrency but does not really address
the parallel question well. For that I've turned to MPI.
I am working on using MPI from Clojure.
These are some links others might find interesting.

The video interview with Leslie Lamport
http://channel9.msdn.com/Shows/Going+Deep/E2E-Erik-Meijer-and-Leslie-Lamport-Mathematical-Reasoning-and-Distributed-Systems

Time, Clocks and the Ordering of Events in a Distributed System
http://research.microsoft.com/en-us/um/people/lamport/pubs/time-clocks.pdf

In particular, I can highly recommend Leslie Lamport's site:
http://research.microsoft.com/en-us/um/people/lamport/pubs/pubs.html

Tim Daly

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