Re: Multiple indexing for vectors/maps

2008-10-19 Thread Meikel Brandmeyer

Hello,

Am 19.10.2008 um 00:12 schrieb kwatford:


I don't think adding this should conflict with any existing code,
though I did notice that get currently accepts and apparently
ignores one extra parameter.

No. It does not ignore the extra parameter! This is a default value,
which is returned in case the index is not contained in the vector.

user= (def x [:a :b])
#=(var user/x)
user= (get x 0 :foo)
:a
user= (get x 1 :foo)
:b
user= (get x 2 :foo)
:foo

See also the help of get:

user= (doc get)
-
clojure/get
([map key] [map key not-found])
  Returns the value mapped to key, not-found or nil if key not present.

This works also for maps and sets, not only vectors.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


CTPOP emulation in JVM

2008-10-19 Thread Krukow

I was reading though Phil Bagwells paper Ideal Hash Trees, when I
encountered this paragraph:

Note that the performance of the algorithm is seriously impacted
by the poor execution speed of the CTPOP emulation in Java, a problem
the Java
designers may wish to address.


I am assuming he means the JVM and not Java. How does this affect
Clojure? do you know if it has been fixed? Does it mean that there is
a potential performance boost for Clojure  waiting in the future?


/krukow
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Fibonacci function performance compare between clojure and scala

2008-10-19 Thread [EMAIL PROTECTED]

Clojure's

(defn fib [n]
   (if  (or (zero? n) (= n 1))
   1
  (+  (fib (dec n) )  (fib (- n 2)

(time (fib 36))

Elapsed Time:  10475.325226 msecs
24157817

Scala's

def fib(n:Int):Int=if (n==0||n==1)1 else fib(n-1)+fib(n-2)
def time(cal: =Int)={
 val beginTime=System.currentTimeMillis
 cal
 val endTime=System.currentTimeMillis
 println(endTime-beginTime)
}
fib(36)
res70:Int=24157817
time(fib(36))
263

Both not tail recursive,both running on Repl (scala's interpreter),but
the difference between two is huge
10475~263
My box : Intel core2 cpu 1.86G,2G mem
Clojure and scala both latest build from svn

any ideas?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Parth Malwankar



On Oct 19, 7:49 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Clojure's

 (defn fib [n]
(if  (or (zero? n) (= n 1))
1
   (+  (fib (dec n) )  (fib (- n 2)

 (time (fib 36))

 Elapsed Time:  10475.325226 msecs
 24157817

 Scala's

 def fib(n:Int):Int=if (n==0||n==1)1 else fib(n-1)+fib(n-2)
 def time(cal: =Int)={
  val beginTime=System.currentTimeMillis
  cal
  val endTime=System.currentTimeMillis
  println(endTime-beginTime)}

 fib(36)
 res70:Int=24157817
 time(fib(36))
 263


I am not a scala expert but I suspect scala Int maps directly to
java ints.

In clojure, the number are boxed and checked by default IIRC.
This would roughly correspond to BigInt in scala.

For clojure, you could coerce ints to native java types using
(int ..).
Also, unchecked-dec could be used.
Doing this should make the code as fast as java or scala.
There was some discussion along these lines here:
http://groups.google.com/group/clojure/browse_thread/thread/4274ce8bd44664ef#

That said, for most practical uses the default behavior
should be fast enough. Its not considered idiomatic to
use coersion and unchecked operation unless absolutely
necessary.

Parth


 Both not tail recursive,both running on Repl (scala's interpreter),but
 the difference between two is huge
 10475~263
 My box : Intel core2 cpu 1.86G,2G mem
 Clojure and scala both latest build from svn

 any ideas?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread [EMAIL PROTECTED]

Scala is sure to use java primitive int type underline, i.e value
type  and boxed to java Integer when necessarily

But  why not  Clojure auto make this ?




gerry


On Oct 19, 11:31 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Here is coersion version for Clojure

 (defn fib [n]
   (let [n  (int n)]
    (if  (or (zero? n) (= n 1))
        1
       (+  (fib (dec n) )  (fib (- n 2))

 (time (fib 36))
 Elapsed time 8848.865149

 not much better   and how to type hint for a int  type?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Lauri Oherd

There is also a faster way to calculate fibonacci numbers in Clojure
(code taken from from
http://en.wikibooks.org/wiki/Clojure_Programming#Lazy_Fibonacci):

(defn fib-seq []
  ((fn rfib [a b]
   (lazy-cons a (rfib b (+ a b
0 1))

user= (time (take 38 (fib-seq)))
Elapsed time: 0.032965 msecs
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
1346269 2178309 3524578 5702887 9227465 14930352 24157817)

Lauri


2008/10/19 [EMAIL PROTECTED] [EMAIL PROTECTED]:

 Clojure's

 (defn fib [n]
   (if  (or (zero? n) (= n 1))
   1
  (+  (fib (dec n) )  (fib (- n 2)

 (time (fib 36))

 Elapsed Time:  10475.325226 msecs
 24157817

 Scala's

 def fib(n:Int):Int=if (n==0||n==1)1 else fib(n-1)+fib(n-2)
 def time(cal: =Int)={
  val beginTime=System.currentTimeMillis
  cal
  val endTime=System.currentTimeMillis
  println(endTime-beginTime)
 }
 fib(36)
 res70:Int=24157817
 time(fib(36))
 263

 Both not tail recursive,both running on Repl (scala's interpreter),but
 the difference between two is huge
 10475~263
 My box : Intel core2 cpu 1.86G,2G mem
 Clojure and scala both latest build from svn

 any ideas?

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Submitting patches

2008-10-19 Thread Matt Revelle

Rich,

I submitted a patch that adds support for exposing protected fields
inherited indirectly through the super class in gen-class.  No problem
if it's unwanted, but would be good to know either way.  Suppose the
original message should've had patch in the subject line; it's
exposing ancestral protected fields with gen-class.

Take care,
Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread [EMAIL PROTECTED]

This lazy cached calculate is wonderful ,but i think the benefit from
it  mostly due to cache .





On Oct 19, 11:56 pm, Lauri Oherd [EMAIL PROTECTED] wrote:
 There is also a faster way to calculate fibonacci numbers in Clojure
 (code taken from 
 fromhttp://en.wikibooks.org/wiki/Clojure_Programming#Lazy_Fibonacci):

 (defn fib-seq []
   ((fn rfib [a b]
(lazy-cons a (rfib b (+ a b
 0 1))

 user= (time (take 38 (fib-seq)))
 Elapsed time: 0.032965 msecs
 (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
 1346269 2178309 3524578 5702887 9227465 14930352 24157817)

 Lauri

 2008/10/19 [EMAIL PROTECTED] [EMAIL PROTECTED]:



  Clojure's

  (defn fib [n]
(if  (or (zero? n) (= n 1))
1
   (+  (fib (dec n) )  (fib (- n 2)

  (time (fib 36))

  Elapsed Time:  10475.325226 msecs
  24157817

  Scala's

  def fib(n:Int):Int=if (n==0||n==1)1 else fib(n-1)+fib(n-2)
  def time(cal: =Int)={
   val beginTime=System.currentTimeMillis
   cal
   val endTime=System.currentTimeMillis
   println(endTime-beginTime)
  }
  fib(36)
  res70:Int=24157817
  time(fib(36))
  263

  Both not tail recursive,both running on Repl (scala's interpreter),but
  the difference between two is huge
  10475~263
  My box : Intel core2 cpu 1.86G,2G mem
  Clojure and scala both latest build from svn

  any ideas?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-10-19 Thread J . Pablo Fernández

I think it might be more important where people are, where they live,
than where they come from. I live in Zürich, Switzerland.

On Oct 17, 11:27 am, Rastislav Kassak [EMAIL PROTECTED] wrote:
 Hello Clojurians,

 I think after 1st year of Clojure life it's good to check how far has
 Clojure spread all over the world.

 So wherever are you come from, be proud and say it.

 I'm from Slovakia. :)

 RK

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Meikel Brandmeyer

Hello,

Am 19.10.2008 um 17:56 schrieb Lauri Oherd:


There is also a faster way to calculate fibonacci numbers in Clojure
(code taken from from
http://en.wikibooks.org/wiki/Clojure_Programming#Lazy_Fibonacci):

(defn fib-seq []
((fn rfib [a b]
  (lazy-cons a (rfib b (+ a b
   0 1))

user= (time (take 38 (fib-seq)))
Elapsed time: 0.032965 msecs
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
1346269 2178309 3524578 5702887 9227465 14930352 24157817)


This timing is wrong. Since take returns a lazy sequence
you only get the timing for the call to take. The sequence
is forced later on when the Repl prints it.

The correct way is to force the evaluation with doall.

  user= (time (take 38 (fib-seq)))
  Elapsed time: 0.055 msecs
  ...
  user= (time (doall (take 38 (fib-seq
  Elapsed time: 0.3 msecs
  ...

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Testing Clojure (was Re: Bug? Strange set equality (r1075))

2008-10-19 Thread Stephen C. Gilardi


On Oct 19, 2008, at 5:11 PM, J. McConnell wrote:

 I've been thinking the same thing for awhile now and I'd love to help
 contribute to an effort like this. Thanks for getting the idea out
 there.

You're welcome. It seems like clojure.contrib could be a more  
convenient place to keep this than the wiki.

Direct or indirect contributions to clojure.contrib require that the  
contributed code be written by the contributor and that the  
contributor have a contributor agreement on file with Rich. Would that  
be acceptable to people interested in participating? I appreciate the  
care Rich showed and long view he took in coming up with the  
Contributor Agreement process. I think it would be a good idea to  
leverage that process for this effort as well.

Discussion of alternative proposals for a good way to do this and  
place to keep it are welcome.

I made a start on this today. I started with the Reader page at  
clojure.org and started making tests. I'm thinking of a structure like  
this:

Run tests with:

(require 'clojure.contrib.test-clojure)

The definition of clojure.contrib.test-clojure requires subordinate  
test namespaces like

'clojure.contrib.test-clojure.Reader
'clojure.contrib.test-clojure.Evaluation
'clojure.contrib.test-clojure.Special-Forms
...

with names that correspond to pages on the Clojure web site. After  
requiring the individual test namespaces, test-clojure runs  
clojure.contrib.test-is/run-tests on each one.

Here's a sample from clojure.contrib.test-clojure.

(ns clojure.contrib.test-clojure.Reader
  (:use clojure.contrib.test-is))

(deftest t-Symbols
  (is (= 'abc (symbol abc)))
  (is (= '*+!-_? (symbol *+!-_?)))
  (is (= 'abc:def:ghi (symbol abc:def:ghi)))
  (is (= 'abc/def (symbol abc def)))
  (is (= 'abc.def/ghi (symbol abc.def ghi)))
  (is (= 'abc/def.ghi (symbol abc def.ghi)))
  (is (= 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno)))
  (is (instance? clojure.lang.Symbol 'alphabet))
  )

; additional tests to flesh out
(deftest t-Numbers)
(deftest t-Characters)
(deftest t-nil)
(deftest t-Booleans)
(deftest t-Keywords)
(deftest t-Lists)
(deftest t-Vectors)
(deftest t-Maps)
(deftest t-Sets)
(deftest t-Quote)
(deftest t-Character)
(deftest t-Comment)
(deftest t-Meta)
(deftest t-Deref)
(deftest t-Regex)
(deftest t-Metadata)
(deftest t-read)

and a run:

user= (require 'clojure.contrib.test-clojure)
Testing #Namespace: clojure.contrib.test-clojure.Reader

Ran 18 tests with 10 assertions.
0 failures, 0 exceptions.
nil
user=

(Currently the number of tests exceeds the number of assertions by so  
much because of the placeholders.)

Tesing Clojure is a big project and will take a lot of work over time.  
There many pieces and many interactions among them to test. The hope  
is that having it available will allow Rich to make changes with an  
even higher degree of confidence that they didn't have unintended  
consequences and to support efforts like Chouser's ClojureScript to  
bring Clojure to new platforms

Discussion and suggestions are welcome.

--Steve


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Swank-clojure: slime-eval-print-last-expression failing.

2008-10-19 Thread Luke Hope

Hello,

I am a common lisp programmer and I use Slime extensively. I am
looking into using Clojure for an upcoming project (I have experience
with ABCL, but it is too slow) and I have clojure and swank-clojure
installed.  Unfortunately slime-eval-print-last-expression (C-j in
*slime-scratch*) is failing (evaluation aborted), I think because it
uses asynchronous evaluation.  Is this a known issue or a regression?
Is it fixable?

I really want to be able to adapt my workflow for working with
clojure, and I use C-j all the time.

All code except for Emacs itself is current as of 2 hours ago.  The
behaviour was duplicated by a member of #clojure.

Hope you can help,

-Luke

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Testing Clojure (was Re: Bug? Strange set equality (r1075))

2008-10-19 Thread Paul Barry

I like this idea and I would be willing to contribute.

On Oct 19, 6:43 pm, Stephen C. Gilardi [EMAIL PROTECTED] wrote:
 On Oct 19, 2008, at 5:11 PM, J. McConnell wrote:

  I've been thinking the same thing for awhile now and I'd love to help
  contribute to an effort like this. Thanks for getting the idea out
  there.

 You're welcome. It seems like clojure.contrib could be a more  
 convenient place to keep this than the wiki.

 Direct or indirect contributions to clojure.contrib require that the  
 contributed code be written by the contributor and that the  
 contributor have a contributor agreement on file with Rich. Would that  
 be acceptable to people interested in participating? I appreciate the  
 care Rich showed and long view he took in coming up with the  
 Contributor Agreement process. I think it would be a good idea to  
 leverage that process for this effort as well.

 Discussion of alternative proposals for a good way to do this and  
 place to keep it are welcome.

 I made a start on this today. I started with the Reader page at  
 clojure.org and started making tests. I'm thinking of a structure like  
 this:

 Run tests with:

         (require 'clojure.contrib.test-clojure)

 The definition of clojure.contrib.test-clojure requires subordinate  
 test namespaces like

         'clojure.contrib.test-clojure.Reader
         'clojure.contrib.test-clojure.Evaluation
         'clojure.contrib.test-clojure.Special-Forms
         ...

 with names that correspond to pages on the Clojure web site. After  
 requiring the individual test namespaces, test-clojure runs  
 clojure.contrib.test-is/run-tests on each one.

 Here's a sample from clojure.contrib.test-clojure.

         (ns clojure.contrib.test-clojure.Reader
           (:use clojure.contrib.test-is))

         (deftest t-Symbols
           (is (= 'abc (symbol abc)))
           (is (= '*+!-_? (symbol *+!-_?)))
           (is (= 'abc:def:ghi (symbol abc:def:ghi)))
           (is (= 'abc/def (symbol abc def)))
           (is (= 'abc.def/ghi (symbol abc.def ghi)))
           (is (= 'abc/def.ghi (symbol abc def.ghi)))
           (is (= 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno)))
           (is (instance? clojure.lang.Symbol 'alphabet))
           )

         ; additional tests to flesh out
         (deftest t-Numbers)
         (deftest t-Characters)
         (deftest t-nil)
         (deftest t-Booleans)
         (deftest t-Keywords)
         (deftest t-Lists)
         (deftest t-Vectors)
         (deftest t-Maps)
         (deftest t-Sets)
         (deftest t-Quote)
         (deftest t-Character)
         (deftest t-Comment)
         (deftest t-Meta)
         (deftest t-Deref)
         (deftest t-Regex)
         (deftest t-Metadata)
         (deftest t-read)

 and a run:

         user= (require 'clojure.contrib.test-clojure)
         Testing #Namespace: clojure.contrib.test-clojure.Reader

         Ran 18 tests with 10 assertions.
         0 failures, 0 exceptions.
         nil
         user=

 (Currently the number of tests exceeds the number of assertions by so  
 much because of the placeholders.)

 Tesing Clojure is a big project and will take a lot of work over time.  
 There many pieces and many interactions among them to test. The hope  
 is that having it available will allow Rich to make changes with an  
 even higher degree of confidence that they didn't have unintended  
 consequences and to support efforts like Chouser's ClojureScript to  
 bring Clojure to new platforms

 Discussion and suggestions are welcome.

 --Steve
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Testing Clojure (was Re: Bug? Strange set equality (r1075))

2008-10-19 Thread Michael Beauregard

Ditto. I've been thinking about this for a few weeks and would be
happy to help out where I can.

On Sun, Oct 19, 2008 at 6:22 PM, Paul Barry [EMAIL PROTECTED] wrote:

 I like this idea and I would be willing to contribute.

 On Oct 19, 6:43 pm, Stephen C. Gilardi [EMAIL PROTECTED] wrote:
 On Oct 19, 2008, at 5:11 PM, J. McConnell wrote:

  I've been thinking the same thing for awhile now and I'd love to help
  contribute to an effort like this. Thanks for getting the idea out
  there.

 You're welcome. It seems like clojure.contrib could be a more
 convenient place to keep this than the wiki.

 Direct or indirect contributions to clojure.contrib require that the
 contributed code be written by the contributor and that the
 contributor have a contributor agreement on file with Rich. Would that
 be acceptable to people interested in participating? I appreciate the
 care Rich showed and long view he took in coming up with the
 Contributor Agreement process. I think it would be a good idea to
 leverage that process for this effort as well.

 Discussion of alternative proposals for a good way to do this and
 place to keep it are welcome.

 I made a start on this today. I started with the Reader page at
 clojure.org and started making tests. I'm thinking of a structure like
 this:

 Run tests with:

 (require 'clojure.contrib.test-clojure)

 The definition of clojure.contrib.test-clojure requires subordinate
 test namespaces like

 'clojure.contrib.test-clojure.Reader
 'clojure.contrib.test-clojure.Evaluation
 'clojure.contrib.test-clojure.Special-Forms
 ...

 with names that correspond to pages on the Clojure web site. After
 requiring the individual test namespaces, test-clojure runs
 clojure.contrib.test-is/run-tests on each one.

 Here's a sample from clojure.contrib.test-clojure.

 (ns clojure.contrib.test-clojure.Reader
   (:use clojure.contrib.test-is))

 (deftest t-Symbols
   (is (= 'abc (symbol abc)))
   (is (= '*+!-_? (symbol *+!-_?)))
   (is (= 'abc:def:ghi (symbol abc:def:ghi)))
   (is (= 'abc/def (symbol abc def)))
   (is (= 'abc.def/ghi (symbol abc.def ghi)))
   (is (= 'abc/def.ghi (symbol abc def.ghi)))
   (is (= 'abc:def/ghi:jkl.mno (symbol abc:def ghi:jkl.mno)))
   (is (instance? clojure.lang.Symbol 'alphabet))
   )

 ; additional tests to flesh out
 (deftest t-Numbers)
 (deftest t-Characters)
 (deftest t-nil)
 (deftest t-Booleans)
 (deftest t-Keywords)
 (deftest t-Lists)
 (deftest t-Vectors)
 (deftest t-Maps)
 (deftest t-Sets)
 (deftest t-Quote)
 (deftest t-Character)
 (deftest t-Comment)
 (deftest t-Meta)
 (deftest t-Deref)
 (deftest t-Regex)
 (deftest t-Metadata)
 (deftest t-read)

 and a run:

 user= (require 'clojure.contrib.test-clojure)
 Testing #Namespace: clojure.contrib.test-clojure.Reader

 Ran 18 tests with 10 assertions.
 0 failures, 0 exceptions.
 nil
 user=

 (Currently the number of tests exceeds the number of assertions by so
 much because of the placeholders.)

 Tesing Clojure is a big project and will take a lot of work over time.
 There many pieces and many interactions among them to test. The hope
 is that having it available will allow Rich to make changes with an
 even higher degree of confidence that they didn't have unintended
 consequences and to support efforts like Chouser's ClojureScript to
 bring Clojure to new platforms

 Discussion and suggestions are welcome.

 --Steve
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Newbie question on the use of functional hash maps

2008-10-19 Thread wwmorgan

If you're interested only in counting the number of unique words, then
you don't even need a map. You can get by with a set, like this:

(defn unique-words-in-file
  [file]
(count (set (split-on-whitespace (slurp file)

slurp reads file into a String object in memory. The hypothetical
split-on-whitespace takes a String and returns a collection of word
objects. set takes a collection and produces a set of the elements in
that collection. count counts the number of elements in the set.

If, on the other hand, you wanted a map from each word in the file to
the number of times that it appears, you might do it like this:

(defn word-counts
  [file]
(reduce
  (fn [map word] (assoc map word (inc (get map word 0
  {}
  (split-on-whitespace (slurp file

The reduce starts with the empty map {}, and then for each word in the
file, produces a new map by invoking the anonymous function supplied
as the first argument to reduce.

You could also get the same result with a list comprehension, using
for:

(defn word-counts
  [file]
(apply merge-with +
  (for [word (split-on-whitespace (slurp file))]
{word 1})))

Here we emit a map for each word in the file, mapping that word to 1.
Then we merge all the maps together, using + when two maps contain the
same key.  This function has a small bug: it throws an exception if
the file contains no words. To fix it, you would insert an additional
argument to apply, the empty map {}.

On Oct 19, 9:16 pm, Tom Emerson [EMAIL PROTECTED] wrote:
 Hi all,

 I have a somewhat embarassing newbie question on the use of hash maps
 in a functional environment.

 Consider a little utility that counts the number of unique words in a
 file. A hash map mapping strings to integers is the obvious data
 structure for this, but the fact that (assoc) returns a new map each
 time it is called is tripping me up: since I can't define a 'global'
 hash map to accumulate the counts, do you pass one around in a
 function? or do you structure the code a different way? This is a
 difference from what I would do in Common Lisp, where I would just
 have a global that is used for the collection.

 Thanks in advance for your wisdom.

 -tree

 --
 Tom Emerson
 [EMAIL PROTECTED]://www.dreamersrealm.net/~tree
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-10-19 Thread [EMAIL PROTECTED]

Austin, Texas, USA.

On Oct 17, 9:18 am, Eric Rochester [EMAIL PROTECTED] wrote:
 Atlanta, Georgia, US

 On Fri, Oct 17, 2008 at 5:27 AM, Rastislav Kassak [EMAIL PROTECTED]wrote:



  Hello Clojurians,

  I think after 1st year of Clojure life it's good to check how far has
  Clojure spread all over the world.

  So wherever are you come from, be proud and say it.

  I'm from Slovakia. :)

  RK

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure + Terracotta

2008-10-19 Thread Alex Miller

Rich, I'm the tech lead for the transparency team at Terracotta and
this is not exactly correct.  For example, while you can read
clustered state outside of a clustered lock, it's possible for the tc
memory manager to clear that state at any time, allowing you to see a
null instead of the real value.  Generally, if you're not reading
under at least a read lock, you can see nulls.

Now, all is not lost because an immutable data structure requires only
a read lock and read locks can be checked out to all the nodes in the
cluster and used locally as a write will never occur.  Read locks like
that will be served locally without crossing the network and will not
generate tc transactions.  So, this will be a really cheap lock to get
even in the cluster.

Maps (especially CHM) are also a fairly specialized case as we heavily
instrument and modify the internal behavior.  Map impls like HashMap,
Hashtable, and CHM are all partial in tc, meaning that the keys must
always be in all nodes but values are faulted lazily as needed.

Currently, volatiles are not really treated any differently than other
non-volatile fields - we require that they be accessed under a
clustered lock.  The whole purpose of volatile isn't really possible
with Terracotta so we can't really do anything special.  We do have
some internal support for automatically wrapping volatiles in
clustered locks but haven't surfaced that out to our config file
yet.

You're correct on the CAS - in general the stuff that really makes
single VM concurrency fly (like fine-grained locks with lightweight
impls like CAS) are awful for clustering.  For things like sequences,
it's generally better to use checked out blocks of ids.  We've got an
implementation of this if you want it (it's pretty straightforward).
If that's not sufficient, I'm sure we could come up with some other
solution.

I have a keen interest in Clojure (awesome stuff Rich) and obviously
also Terracotta.  If only I had another 5 hrs/day, I'd spend it on
Clojure/TC integration.  :)  I (and others at Terracotta) are
certainly happy to answer questions and help where we can.  Probably
best to ask on our mailing lists as everyone in eng monitors the user
and dev lists:

http://www.terracotta.org/confluence/display/wiki/Mailing+Lists

Alex Miller


On Oct 18, 7:50 am, Rich Hickey [EMAIL PROTECTED] wrote:
 On Fri, Oct 17, 2008 at 8:01 PM, Luc Prefontaine



 [EMAIL PROTECTED] wrote:
  I am not very far from tackling this issue. In our bus messaging system, we
  are using Terracotta with some Java components
  and it's a matter of weeks before we start to investigate how we can bridge
  Clojure and Terracotta.

  A customer asked us about some new functionality today and I see a need to
  fill the Terracotta/Clojure gap
  somehow.

  I'll comeback toward the end of November with some proposal.

  Any comments Rich about how you would see this integration and what Clojure
  semantics you would like to share through Terracotta ?
  I might enlarge the scope beyond what we need in our system even if not all
  the pieces are delivered in the very short term.

 There are lots of potential synergies. I think that one key benefit of
 using Clojure is that the immutable data structures can be shared, yet
 read outside of locks. As you know, Terracotta requires shared objects
 to be accessed under a lock. However, once the object has been
 propagated, it need not be acceessed under a lock iff it is immutable.
 This was one of the first things I verified with Terracotta.

 So, for instance, you can do the normal Terracotta cache thing and put
 Clojure's persistent data structures in a ConcurrentHashMap shared
 root. Once you pull one out of the map, you can use it henceforth
 without locking - a huge benefit IMO. Plus, since the data structures
 share structure, updates are also efficient. A current hitch, which I
 am looking to enhance anyway, is that some of the data structures do
 lazy hash creation with volatile caches. In proc this is no problem,
 nor out of proc since the hash value is a pure function of the
 immutable structure value, but I think Terracotta may not be happy
 with the volatile members. I have already on my todo list moving to
 incrementally calculated hash values (had to wait for the unification
 of hash logic with java.util's, now done).

 Of course, this leaves you with ConcurrentHashMap's last-one-in-wins,
 no coordinated activity semantics. When that's not good enough, you'll
 want to try STM refs + transactions. Here too, I think a lot is
 possible. As I've said, I once had this working, but haven't tracked
 whether or not all mechanisms I am using are supported by Terracotta.
 Underneath the STM are all standard Java concurrency things -
 reentrant locks, wait/notify, java.util.concurrent.atomic stuff etc.
 To the extent these are supported, it should function correctly right
 away.

 That said, there's one aspect of the STM I think could be tweaked for
 a clustering situation. The 

Re: Beginners (and idiomatic Clojure)

2008-10-19 Thread Krukow



On Oct 20, 12:30 am, Paul Barry [EMAIL PROTECTED] wrote:
 Krukow,

 I agree, it would help to have a resource for learning Clojure.  For
 now, my best advice is to pick a real project to start working and
 then specific questions in the IRC room, #clojure on irc.freenode.net.

 Within a few months, we'll have the beta 
 book:http://www.pragprog.com/titles/shcloj/programming-clojure

Wow, I wasn't expecting a book this early. Hope the quality will be as
high as the other material on the web -- will definitely pre-order it.
Thanks for the hint.


/krukow


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---