Re: Parallel garbage collection worthwhile?

2009-07-29 Thread Tassilo Horn

Daniel Lyons  writes:

Hi Daniel,

> In your particular case I think you might want to take a look at the
> source code in the contrib project which implements a lazy list of
> primes:
>
> http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/lazy_seqs.clj

I came up with another approach on lazily calculating primes using the
Miller Rabin algorithm.  Calculating the primes < 100.000 akes about 12
seconds on my 2.2 GHz dual core.  Here it is:

--8<---cut here---start->8---
(ns de.tsdh.math.primes
  (:use [clojure.contrib [math :only [expt]]
 [test-is :only [deftest is]]
 [def :only [defvar defvar-]]]))

(defvar *pseudo-accuracy* 10
  "The chances that prime? returns true for a composite is (expt 4 (* -1
*pseudo-accuracy*)).")

(defn factorize-out
  "Factorizes out all x factors from n.
Examples:
  (factorize-out 10 2) ==> {:exponent 1, :rest 5}, because 2^1 * 5 = 10
  (factorize-out 90 3) ==> {:exponent 2, :rest 10}, because 3^2 * 10 = 90"
  [n x]
  (loop [acc n exp 0]
(if (= 0 (mod acc x))
  (recur (/ acc x) (inc exp))
  (hash-map :exponent exp :rest acc

(defn expt-mod
  "Equivalent to (mod (expt n e) m), but faster.
http://en.wikipedia.org/wiki/Modular_exponentiation#An_efficient_method:_the_right-to-left_binary_algorithm";
  [n e m]
  (loop [r 1, b n, e e]
(if (= e 0)
  r
  (recur (if (odd? e)
   (mod (* r b) m)
   r)
 (mod (expt b 2) m)
 (bit-shift-right e 1)

(defn prime?
  "Checks if n is a prime using the Miller-Rabin pseudo-primality test.  Also
see *pseudo-accuracy*."
  [n]
  (cond
(< n 2)   false
(= n 2)   true
(even? n) false
:else (let [m (factorize-out (dec n) 2)
d (:rest m)
s (:exponent m)]
(loop [k 1]
  (if (> k *pseudo-accuracy*)
true
(let [a (+ 2 (rand-int (- n 4)))
  x (expt-mod a d n)]
  (if (or (= x 1) (= x (dec n)))
(recur (inc k))
(if (loop [r 1
   x (expt-mod x 2 n)]
  (cond
   (or (= x 1) (>  r (dec s)))  false
   (= x (dec n))true
   :else (recur (inc r) (mod (* x x) n
  (recur (inc k))
  false

(defn next-prime
  "Returns the next prime greater than n."
  [n]
  (cond
(< n 2) 2
:else (loop [n (inc n)]
(if (prime? n)
  n
  (recur (inc n))

(defn primes
  "Returns a lazy sequence of prime numbers"
  []
  (iterate next-prime 2))
--8<---cut here---end--->8---

Bye,
Tassilo

--~--~-~--~~~---~--~~
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: Parallel garbage collection worthwhile?

2009-07-29 Thread ataggart

I threw this together, how does it measure up?


(defn prime? [x primes]
  (not (first (filter #(zero? (rem x %)) primes

(defn next-prime [xs primes]
  (lazy-seq
(let [xs (drop-while #(not (prime? % primes)) xs)
  prime (first xs)
  primes (conj primes prime)]
  (cons prime
(next-prime (rest xs) primes)

(defn primes []
  (next-prime (iterate inc 2) []))

(time (first (drop-while #(< % 10) (primes


On Jul 28, 8:16 pm, Seth  wrote:
> I found a simple, worthwhile improvement for a CPU bound
> implementation of the Sieve of Eratosthenes in Clojure and thought I'd
> share it. Also attached are a few metrics and code for the curious.
>
> So I'm using Clojure to solve some of the problems on Project Euler.
> I'd solved some of them before with other languages, but not in new
> lazy/immutable way Clojure is encouraging me to think.
>
> Anyways, my Sieve of Eratosthenes was too slow. It took about three
> minutes on a 2GHz Intel Core Duo MacBook Pro to find the primes lesser
> than 100,000. The blame's on me here -- I'm trying to do it the
> immutable/lazy/??? way rather than the big mutable array way. Patience
> is appreciated as I am still low on the learning curve.
>
> I enabled local jmx monitoring and attached JConsole to the Clojure
> 1.0 process. Almost all the time was spent in garbage collection. JMap
> showed scary things like this:
>
> 
>
> New Generation (Eden + 1 Survivor Space):
>    capacity = 589824 (0.5625MB)
>    used     = 524288 (0.5MB)
>    free     = 65536 (0.0625MB)
>    88.89% used
> Eden Space:
>    capacity = 524288 (0.5MB)
>    used     = 524288 (0.5MB)
>    free     = 0 (0.0MB)
>    100.0% used
> From Space:
>    capacity = 65536 (0.0625MB)
>    used     = 0 (0.0MB)
>    free     = 65536 (0.0625MB)
>    0.0% used
> To Space:
>    capacity = 65536 (0.0625MB)
>    used     = 65536 (0.0625MB)
>    free     = 0 (0.0MB)
>    100.0% used
>
> [...]
>
> 
>
> So the young spaces are both a.) small and b.) full. Much to my
> surprise enabling parallel garbage collection of the young space was
> the biggest win:
>
> 1.0 = official release
> 1.1a = compiled from git 2009-07-27
>
> * clojure version, jvm flags, seconds to find primes <= 100,000
>
> 1.0, (default), 230
> 1.1a, (default), 190
> 1.1a, -XX:NewRatio=2 -Xmx128m, 148
> 1.1a, -XX:+UseParallelGC, 51
> 1.1a, -XX:NewRatio=2 -Xmx128m -XX:+UseParallelGC, 49
>
> So it looks like my code makes Clojure generate a lot of young
> objects... I tried to stick to the immutable/lazy approach... all
> suggestions would be very welcome -- don't spare the corrections
> please!
>
> 
>
> (defn subsequent-multiples [val]
>   (fn [candidate]
>     (or (not= 0 (mod candidate val))
>         (= val candidate
>
> (defn build-sieve-slow [ceiling]
>   (loop [primes ()
>          field (range 2 (+ 1 ceiling))]
>     (let [cur (first field)
>           remnants (filter (subsequent-multiples cur) field)]
>       (if (> cur (/ ceiling 2))
>         (concat primes remnants)
>         (recur
>          (concat primes (list (first remnants)))
>          (rest remnants))
>
> (time (apply + (build-sieve-slow 10)))
>
> 
--~--~-~--~~~---~--~~
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: Confusion with namespaces and SLIME

2009-07-29 Thread martin_clausen

I have had the same experience. I solved it by using (ns ...) and (use
separately).

/mac

On Jul 27, 9:41 pm, Tom Emerson  wrote:
> Hi all,
>
> I'm working with a Clojure file that creates a namespace to include
> all of its functions:
>
> (ns foobar)
>
> I load slime and then compile/load the file (C-c C-k), then switch the
> slime REPL to use the 'foobar' namespace. So far, so good: symbols in
> that namespace are accessible in the repl without any problems.
>
> When I switch back to the clojure file and modify or add a function
> that refers to another symbol defined in that namespace, and attempt
> to evaluate the sexp with C-c C-e then the SLIME repl throws an
> exception saying that the symbols cannot be resolved (even though I
> know they're in the namespace that is current in the SLIME repl).
>
> However, if I use C-c C-e to evaluate the ns call and the subsequent
> calls that set the values being referred to, all is fine.
>
> Anyway, tips are appreciate for working with namespaces with SLIME.
>
> Thanks in advance,
>
>     -tree
>
> --
> Tom Emerson
> tremer...@gmail.comhttp://treerex.blogspot.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: Parallel garbage collection worthwhile?

2009-07-29 Thread Seth

That worked pretty well! It completed in about 9 seconds with the
default JVM flags. Better yet I switched to the 64bit server 1.6 VM
and it completed in 2.9 seconds. Unlike my code, which threw a stack
overflow exception. Sigh.

I *really* appreciate everyone's friendly and helpful feedback. Time
permitting I'll dig back into this tonight.

On Jul 29, 4:07 am, ataggart  wrote:
> I threw this together, how does it measure up?
>
> (defn prime? [x primes]
>   (not (first (filter #(zero? (rem x %)) primes
>
> (defn next-prime [xs primes]
>   (lazy-seq
>     (let [xs (drop-while #(not (prime? % primes)) xs)
>           prime (first xs)
>           primes (conj primes prime)]
>       (cons prime
>             (next-prime (rest xs) primes)
>
> (defn primes []
>   (next-prime (iterate inc 2) []))
>
> (time (first (drop-while #(< % 10) (primes
>
> On Jul 28, 8:16 pm, Seth  wrote:
>
>
>
> > I found a simple, worthwhile improvement for a CPU bound
> > implementation of the Sieve of Eratosthenes in Clojure and thought I'd
> > share it. Also attached are a few metrics and code for the curious.
>
> > So I'm using Clojure to solve some of the problems on Project Euler.
> > I'd solved some of them before with other languages, but not in new
> > lazy/immutable way Clojure is encouraging me to think.
>
> > Anyways, my Sieve of Eratosthenes was too slow. It took about three
> > minutes on a 2GHz Intel Core Duo MacBook Pro to find the primes lesser
> > than 100,000. The blame's on me here -- I'm trying to do it the
> > immutable/lazy/??? way rather than the big mutable array way. Patience
> > is appreciated as I am still low on the learning curve.
>
> > I enabled local jmx monitoring and attached JConsole to the Clojure
> > 1.0 process. Almost all the time was spent in garbage collection. JMap
> > showed scary things like this:
>
> > 
>
> > New Generation (Eden + 1 Survivor Space):
> >    capacity = 589824 (0.5625MB)
> >    used     = 524288 (0.5MB)
> >    free     = 65536 (0.0625MB)
> >    88.89% used
> > Eden Space:
> >    capacity = 524288 (0.5MB)
> >    used     = 524288 (0.5MB)
> >    free     = 0 (0.0MB)
> >    100.0% used
> > From Space:
> >    capacity = 65536 (0.0625MB)
> >    used     = 0 (0.0MB)
> >    free     = 65536 (0.0625MB)
> >    0.0% used
> > To Space:
> >    capacity = 65536 (0.0625MB)
> >    used     = 65536 (0.0625MB)
> >    free     = 0 (0.0MB)
> >    100.0% used
>
> > [...]
>
> > 
>
> > So the young spaces are both a.) small and b.) full. Much to my
> > surprise enabling parallel garbage collection of the young space was
> > the biggest win:
>
> > 1.0 = official release
> > 1.1a = compiled from git 2009-07-27
>
> > * clojure version, jvm flags, seconds to find primes <= 100,000
>
> > 1.0, (default), 230
> > 1.1a, (default), 190
> > 1.1a, -XX:NewRatio=2 -Xmx128m, 148
> > 1.1a, -XX:+UseParallelGC, 51
> > 1.1a, -XX:NewRatio=2 -Xmx128m -XX:+UseParallelGC, 49
>
> > So it looks like my code makes Clojure generate a lot of young
> > objects... I tried to stick to the immutable/lazy approach... all
> > suggestions would be very welcome -- don't spare the corrections
> > please!
>
> > 
>
> > (defn subsequent-multiples [val]
> >   (fn [candidate]
> >     (or (not= 0 (mod candidate val))
> >         (= val candidate
>
> > (defn build-sieve-slow [ceiling]
> >   (loop [primes ()
> >          field (range 2 (+ 1 ceiling))]
> >     (let [cur (first field)
> >           remnants (filter (subsequent-multiples cur) field)]
> >       (if (> cur (/ ceiling 2))
> >         (concat primes remnants)
> >         (recur
> >          (concat primes (list (first remnants)))
> >          (rest remnants))
>
> > (time (apply + (build-sieve-slow 10)))
>
> > 
--~--~-~--~~~---~--~~
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: Confusion on Clojure 1.0, compatible clojure-contrib, git-hub, svn, ...

2009-07-29 Thread Isak Hansen

On Mon, Jul 6, 2009 at 9:59 PM, Laurent PETIT wrote:
>
> Hi,
>
> 2009/7/6 Stephen C. Gilardi :
>>
>> On Jul 6, 2009, at 3:13 PM, Tom Emerson wrote:
>>
>> Thanks Paul, for the quick response.
>>
>> On Mon, Jul 6, 2009 at 12:56 PM, Phil Hagelberg wrote:
>>
>> That's right. Side note to folks with commit access: it would be a good
>>
>> idea to check in a note to the deprecated repositories telling people
>>
>> where to go for the latest versions.
>>
>> Or, better, do away with those obsolete repos entirely. But whatever.
>>
>> In the case of SourceForge, they have a strong preference for keeping old
>> repos around. I think it's confusing, but I recall looking into it and
>> finding that was their policy. I'm not sure whether or not Google Code has a
>> similar preference. Some clear, local indication in each repository that
>> marks it as "no longer maintained, see clojure.org for current info" would
>> be a win of course.
>>
>
> I think there could be a way to make both parts happy : rather than
> just adding the info that it is an old repo in some README file in the
> root directory of the svn repo, committing also an svn delete command
> on all the contents of trunk could help clarify this : by default,
> users checking (or updating !) trunk would have an empty working copy
> as a result (and also just the informative README file).
> But tags would still be there, and also the entire repository history,
> as a svn delete is just deleting files in the commited revision, not
> deleting the history (one could retrieve a working copy by just
> emitting svn up -r N-1  where N would be the "deletion" commit.
>

Sounds good.


-Isak

--~--~-~--~~~---~--~~
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 performance tests and clojure a little slower than Java

2009-07-29 Thread Andy Fingerhut

I have added a script that uses the Java version of the benchmark
programs to generate the large files that were in the distribution
file I gave a link to earlier, so it is much smaller.  I've also
published it on github and added a COPYING file that makes the
licenses more explicit (revised BSD for everything, some copyright by
me, the rest by the owner of the benchmark web site).  You can get it
here:

git://github.com/jafingerhut/clojure-benchmarks.git

Again, submissions for new benchmark programs, or improvements to
existing ones, are welcome.

Thanks,
Andy


On Jul 28, 8:52 am, AndyF  wrote:
> Anybody is welcome to take the Clojure sources and do what they will
> with them -- publish the original or modified code under their own
> license, sell it, etc.
>
> For the Perl, Common Lisp, Haskell, etc. sources, those are published
> under this license.  It isn't my code.
>
> http://shootout.alioth.debian.org/u32q/miscfile.php?file=license&titl...
>
> Andy
>
> On Jul 28, 5:09 am, Berlin Brown  wrote:
>
> > Thanks AndyF, do you mind if I use some of your examples and put my
> > own spin on them.  I was curious and want to run my own tests and see
> > if I get similar output?
>
> > On Jul 28, 12:03 am, ataggart  wrote:
>
> > > On Jul 27, 10:06 am, BerlinBrown  wrote:
>
> > > > So far I have found that clojure is about
> > > > 5-10 times as slow as comparable code in Clojure.
>
> > > I infer you mean clojure execution times are about 5-10 times longer
> > > than in java.  It depends on what you're doing, but that sounds
> > > plausible.
>
> > > Here's are some slides of a comparison between a number of JVM
> > > languages:
>
> > >http://www.slideshare.net/michael.galpin/performance-comparisons-of-d...
>
> > > Note that in the "reversible" section, he has a loop in the clojure
> > > code with unnecessary Integer object creation which ends up doubling
> > > the execution time.

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



Re: a denilling macro

2009-07-29 Thread nchubrich

Gentlemen---
Thanks for fixing my newbish error and showing me a better way to
do it!

Nick.

--~--~-~--~~~---~--~~
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: Java based DocDB

2009-07-29 Thread Niels Mayer
On Mon, Jul 27, 2009 at 7:46 AM, Sean Devlin 
 wrote:
>
> Howdy everyone,
> I've got a project that needs a Doc DB.  It will need to run on
> windows (and probably OS X), so I am looking for something that works
> with Java.  I thought I'd ask for some help here before I re-invent
> the wheel.
>
> 1.  Has anyone here worked with a Java based doc DB?
> 2.  Does anyone have Clojure bindings for said doc DB?
> 3.  Does anyone know of good guide for said doc DB?


Take a look at Xwiki , a 5-year-old open source project,
implemented in Java, which has database-backed documents, objects that can
be attached to documents, collaborative document versioning, and the ability
to write scripts in Velocity or
Groovy
and
jRuby , and hopefully
if I have my way with it, Clojure too:
http://groups.google.com/group/clojure/browse_thread/thread/297861670c2f5611 .
This is an old Google Tech Talk on Xwiki's documents, and application
programming in Xwiki: http://www.youtube.com/watch?v=xs3LuzwqemM .. They've
gone "2.0" since this talk, but the overall flavor is the same.
For example, here's a trivial app I wrote which queries the Xwiki document
database that comprises my website, and returns a timeline of documents
published on the site:
http://nielsmayer.com/xwiki/bin/view/Main/SiteTimeline
(source code xar/jar:
http://nielsmayer.com/xwiki/bin/download/Main/SiteTimeline/SiteTimelinePkg.xar)

The wiki
codeof
this app is boilerplate; the main business of this app happens inside
the
document's "XWiki.JavaScriptExtension[0] object, via Hibernate Query,
processed via the Xwiki API, and "scripted" in Velocity. This code is used
to generate Javascript for the Simile-Widgets
Timelineused for the display.
(The Xwiki Java API calls are prefixed with "$xwiki."
"$util." "$request."  below):

#set( $at_start_p = true )## #set( $hqlQuery = ", XWikiRCSNodeInfo as ni
where doc.id=ni.id.docId and ni.id.version2=1 and doc.space<>'XWiki' and
doc.space<>'Main' and doc.space<>'Panels' group by doc.space, doc.name order
by max(ni.date) desc")## #set( $recentlyChangedDocuments =
$xwiki.searchDocuments($hqlQuery, $util.parseInt($request.changesNb), 0))##
var tl_events = [ #foreach( $rcName in $recentlyChangedDocuments )##{ #set(
$rcDoc = $xwiki.getDocument($rcName) )## #set( $docTitle =
$rcDoc.getDisplayTitle().replaceAll('"','\\"') )## #set( $docEpoch =
$rcDoc.date.getTime() )## #if($at_start_p == true) ## { #set( $at_start_p =
false )## #else ## }{ ,## #end ## } new Timeline.DefaultEventSource.Event({
start: epoch_date($docEpoch), end: null, latestStart: epoch_date($docEpoch),
latestEnd: null, instant: true, text: "$docTitle", description:
"Link: ${rcName}Date:
$xwiki.formatDate($rcDoc.date) #if("$!rcDoc.author" !=
"") Author: $xwiki.getLocalUserName(${rcDoc.author}, false) #end
#if("$!rcDoc.creator" != "") Creator: $xwiki.getLocalUserName(${rcDoc.creator}, false) #end
", image: null, link: null, icon: null, color: null,
textColor: null }) #end ];
It would be much nicer to be able to use Clojure to dynamically generate
JSON on the server side. That's certainly one of the things you can do with
Xwiki, even though normally you'd be using it to dynamically generate HTML
documents or applications. For example, I'm looking at using closure to
access the Xwiki API to persist some information from my application in
Xwiki "documents" (everything in xwiki is a wiki-document) implemented via
Exhibit , that look like this:
http://nielsmayer.com/xwiki/bin/view/Exhibit/NPRpods3 (a work in progress).

Niels
http://nielsmayer.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: Parallel garbage collection worthwhile?

2009-07-29 Thread John Harrop
On Wed, Jul 29, 2009 at 2:59 AM, Daniel Lyons wrote:

> Probably it would help to try and implement a lazy
> list of the Fibonacci sequence before looking at that code, and then
> maybe try some other mathematical sequences that are a little easier
> to construct too.
>

Using the super-lazy-seq macro Wrexsoul posted a month or so ago, that's
dead easy:

(super-lazy-seq [a 0 b 1] (next-item b b (+ a b)))

On the other hand,

(defn fibs [] (cons 1 (cons 1 (lazy-seq (map + (fibs) (rest (fibs)))
(def fibs (memoize fibs))

works and is done with map rather than a looping-like construct. (Without
the memoize, the latter is exponential in time; with it, though, all
generated terms are retained in memory. This could be scoped, by using
(binding [fibs (memoize fibs)] (take n fibs)) or whatever whenever you
needed to do something with (part of) fibs, and returning something.
Downside: binding doesn't work well with lazy seqs. It's actually probably
easier to use the first version efficiently in a pure-functional way, even
if its less pure-functional "inside". On the other hand, I'm a bit
suspicious of that macro. It seems to work for common cases, but I suspect
it will not work properly if you shadow one of its loop bindings with a let
in the loop body, as I think it doesn't care if it's the same var so long as
it has the same name when it wraps the loop vars in a deref.

(map second (iterate (fn [[a b]] [b (+ a b)]) [0 1]))

seems to work though and avoids the memory problems of the memoized
function, the exponential tendencies of the un-memoized function, AND the
super-lazy-seq macro (and even the lazy-seq macro). Interestingly, it works
identically to the super-lazy-seq macro in that both start with a pair of [a
= 0, b = 1] and transform it according to [a -> b, b -> (+ a b)].

In fact, there's a general correspondence between
(map #(nth % n) (iterate (fn [[a b c ... z]] [exprs]) [a0 b0 c0 ... z0]))
and
(super-lazy-seq [a a0 b b0 c c0 ... z z0] (next-item an exprs))
and I suspect the map/iterate versions to be more efficient since they avoid
atoms. (On the other hand, if the sequence is generated in a non-functional
way, such as from network I/O, super-lazy-seq seems to me to be a better fit
as long as you avoid shadowing any of its loop bindings internally.)

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



fibonacci sequence using lazy-cat

2009-07-29 Thread swaroop belur

Hello all,

Just started learning clojure recently - initial examples were easy to
understand, until I found this example

fibonacci sequence using lazy-cat :
(def fibs (lazy-cat [0 1]   (map + fibs (rest fibs

I am trying to understand how this works ..not sure i fully comprehend
it.

Can anyone please explain how clojure evaluates this.
1. so if we call (take 5 fibs) for example, what does fibs initially
refer to?
2. how does lazy-cat exactly work over here?

Apologize if this has already been asked earlier.

Thanks
swaroop

--~--~-~--~~~---~--~~
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: Parallel garbage collection worthwhile?

2009-07-29 Thread Niels Mayer
FYI, some potentially useful info here:

http://n2.nabble.com/Does-JDK6u14-%22Garbage-First-garbage-collector-%28G1%29%22-work-and-or-improve-Xwiki-performance-size-mem-locality--tp2344358p2344358.html
Does JDK6u14 "Garbage-First garbage collector (G1)" work and/or improve
Xwiki performance/size/mem-locality?
*Date:* Feb 17, 2009; 05:13pm
*Author:* Niels Mayer
*XWiki- Dev* (http://n2.nabble.com/XWiki--Dev-f475773.html)
I usually have found that the garbage collector is the hardest-working
thing
in a java-web app (unfortunately) so when I noticed this new GC option in
*Java
HotSpot 14*, I figured it might help (potentially a lot w/ high-volume
sites, which are the real GC churners).

Has anybody tried the "Garbage-First garbage collector (G1)"  with Xwiki?

http://platform.xwiki.org/xwiki/bin/view/AdminGuide/Performances suggests
>
> CATALINA_OPTS="-server -Xms128m -Xmx1024m -XX:MaxPermSize=128m
-Dfile.encoding=utf-8 -Djava.awt.headless=true -XX:+UseParallelGC
-XX:MaxGCPauseMillis=100"
>
> However these instructions don't work, as-is, since UseParallelGC is the
default nowadays:

https://jdk6.dev.java.net/6uNea.html says:

> The parallel collector is still the default GC and is the most efficient
GC
> for common household usage. G1 is meant to be an alternative for the
> concurrent collector. It is designed to be more predictable and enable
fast
> allocation with memory regions design.

Here's more info

Java SE 6 Update 14 Milestone Schedule b01 (1st available build) 02/11/09
 FCS
> Q2, 2009 *Feature List:*
>
>- *Service Tag creation for Windows JRE (CR 6676849<
http://bugs.sun.com/view_bug.do?bug_id=6676840>
>)*: For more information about Service Tag, check out this technical
>article
>.
>
>- *Java HotSpot 14*: including the new garbage collector, G1, Big
>Decimal enhancements, TreeMap and HashMap enhancements, optimized
compressed
>OOP code generation.
>
> The Garbage-First garbage collector (G1) is currently in beta. It is not
> enabled by default. The parallel collector is still the default GC and is
> the most efficient GC for common household usage. G1 is meant to be an
> alternative for the concurrent collector. It is designed to be more
> predictable and enable fast allocation with memory regions design.
>
> To use it: -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
>
> For more information about GC & G1, please see:
>
>- G1 Technical Session in JavaOne 2008<
http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-5419&yr=2008&track=javase
>
>- Java SE 6 GC tunning<
http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html>
>- Analysis of the Garbage-First Garbage Collection<
http://research.sun.com/jtech/pubs/04-g1-paper-ismm.pdf>
>
>
Niels
http://nielsmayer.com

PS:  some things that cause big-growth, like importing and exporting, might
not grow as large with a "generation scavenging" style GC as provided by
"Garbage-First Collection." Sometimes, just GCing a large structure being
iterated-over uses a lot more memory than it needs to; because the gc is
letting objects that should get collected early, like the incremental
results of an iteration, "build up"  and increase overall memory size while
decreasing locality and cache-hits. This seems to cause a nearly
exponential
performance dropoff when very little memory churn might occur if only
things
got collected "at the right time."

http://research.sun.com/jtech/pubs/04-g1-paper-ismm.pdf suggests this new
GC
will help:

> 2.4 Generational GarbageFirst
> Generational garbage collection [34, 26] has several advantages, which a
> collection strategy ignores at its peril. Newly allocated objects are
> usually more likely to become garbage than older objects, and newly
> allocated objects are also more likely to be the target of pointer
> modi cations, if only because of initialization. We can take advantage of
> both of these properties in Garbage-First in a flexible way. We can
> heuristically designate a region as young when it is chosen as a mutator
> allocation region. This commits the region to be a member of the next
> collection set. In return for this loss of heuristic flexibility, we gain
an
> important benefit: remembered set processing is not required to consider
> modifications in young regions. Reachable young objects will be scanned
> after they are evacuated as a normal part of the next evacuation pause.
>
> Note that a collection set can contain a mix of young and non-young
> regions. Other than the special treatment for remembered sets described
> above, both kinds of regions are treated uniformly.
> ...
> 2.5 Concurrent Marking
> Concurrent marking is an important component of the system. It provides
> collector completeness without imposing any order on region choice for
> collection sets (as, for example, the Train algorithm of Hudson and Moss
> [22] does). Further, it provides the live data informat

Re: Parallel garbage collection worthwhile?

2009-07-29 Thread Christophe Grand
Hi all,

I thought about this naive (it considers even numbers!) implementation of
the sieve:

(defn primes [max]
  (let [enqueue (fn [sieve n factor]
  (let [m (+ n factor)]
(assoc sieve m
  (conj (sieve m) factor
next-sieve (fn [sieve candidate]
 (if-let [factors (sieve candidate)]
   (reduce #(enqueue %1 candidate %2)
 (dissoc sieve candidate)
 factors)
   (enqueue sieve candidate candidate)))]
(apply concat (vals (reduce next-sieve {} (range 2 max))

Here the sieve is a map where keys are next known non-primes and values a
list of their prime factors.

It's not lazy and doesn't return a sorted seq but, despite being naive, it
surprisingly doesn't perform that bad:
(time (apply + (primes 10)))
"Elapsed time: 285.23304 msecs"
454396537

lazy version:
(defn lazy-primes []
  (letfn [(enqueue [sieve n factor]
(let [m (+ n factor)]
  (assoc sieve m
(conj (sieve m) factor
  (next-sieve [sieve candidate]
(if-let [factors (sieve candidate)]
  (reduce #(enqueue %1 candidate %2)
(dissoc sieve candidate)
factors)
  (enqueue sieve candidate candidate)))
  (next-primes [sieve candidate]
(if (sieve candidate)
  (recur (next-sieve sieve candidate) (inc candidate))
  (cons candidate
(lazy-seq (next-primes (next-sieve sieve candidate)
(inc candidate))]
   (lazy-seq (next-primes {} 2


Christophe




On Wed, Jul 29, 2009 at 5:16 AM, Seth  wrote:

>
> I found a simple, worthwhile improvement for a CPU bound
> implementation of the Sieve of Eratosthenes in Clojure and thought I'd
> share it. Also attached are a few metrics and code for the curious.
>
> So I'm using Clojure to solve some of the problems on Project Euler.
> I'd solved some of them before with other languages, but not in new
> lazy/immutable way Clojure is encouraging me to think.
>
> Anyways, my Sieve of Eratosthenes was too slow. It took about three
> minutes on a 2GHz Intel Core Duo MacBook Pro to find the primes lesser
> than 100,000. The blame's on me here -- I'm trying to do it the
> immutable/lazy/??? way rather than the big mutable array way. Patience
> is appreciated as I am still low on the learning curve.
>
> I enabled local jmx monitoring and attached JConsole to the Clojure
> 1.0 process. Almost all the time was spent in garbage collection. JMap
> showed scary things like this:
>
> 
>
> New Generation (Eden + 1 Survivor Space):
>   capacity = 589824 (0.5625MB)
>   used = 524288 (0.5MB)
>   free = 65536 (0.0625MB)
>   88.89% used
> Eden Space:
>   capacity = 524288 (0.5MB)
>   used = 524288 (0.5MB)
>   free = 0 (0.0MB)
>   100.0% used
> From Space:
>   capacity = 65536 (0.0625MB)
>   used = 0 (0.0MB)
>   free = 65536 (0.0625MB)
>   0.0% used
> To Space:
>   capacity = 65536 (0.0625MB)
>   used = 65536 (0.0625MB)
>   free = 0 (0.0MB)
>   100.0% used
>
> [...]
>
> 
>
> So the young spaces are both a.) small and b.) full. Much to my
> surprise enabling parallel garbage collection of the young space was
> the biggest win:
>
> 1.0 = official release
> 1.1a = compiled from git 2009-07-27
>
> * clojure version, jvm flags, seconds to find primes <= 100,000
>
> 1.0, (default), 230
> 1.1a, (default), 190
> 1.1a, -XX:NewRatio=2 -Xmx128m, 148
> 1.1a, -XX:+UseParallelGC, 51
> 1.1a, -XX:NewRatio=2 -Xmx128m -XX:+UseParallelGC, 49
>
> So it looks like my code makes Clojure generate a lot of young
> objects... I tried to stick to the immutable/lazy approach... all
> suggestions would be very welcome -- don't spare the corrections
> please!
>
> 
>
> (defn subsequent-multiples [val]
>  (fn [candidate]
>(or (not= 0 (mod candidate val))
>(= val candidate
>
> (defn build-sieve-slow [ceiling]
>  (loop [primes ()
> field (range 2 (+ 1 ceiling))]
>(let [cur (first field)
>  remnants (filter (subsequent-multiples cur) field)]
>  (if (> cur (/ ceiling 2))
>(concat primes remnants)
>(recur
> (concat primes (list (first remnants)))
> (rest remnants))
>
> (time (apply + (build-sieve-slow 10)))
>
> 
>
> >
>


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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 

Re: Emacs clojure mode: how to set current directory & classpath

2009-07-29 Thread Luke Amdor

I wrote a emacs macro to help set up different slime implementations
for clojure. It has been really helpful. It's at

http://github.com/rubbish/rubbish-emacs-setup/blob/ad5bfc6f74cc9f794470e50080f8076b5599fb24/mine/mine-slime.el#L19

I probably should contribute it back to swank-clojure though.

Luke

On Jul 28, 9:32 am, Baishampayan Ghose  wrote:
> Luke,
>
> >> Is there any way for me to just put the JAR files somewhere and get them
> >> added to the classpath?
>
> > Put them in a lib/ folder at your project root.
>
> Many thanks Luke. That worked. I should have looked at the source of
> clojure-project before.
>
> Thanks again.
>
> Regards,
> BG
>
> --
> Baishampayan Ghose 
> oCricket.com
>
>  signature.asc
> < 1KViewDownload
--~--~-~--~~~---~--~~
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: Parallel garbage collection worthwhile?

2009-07-29 Thread Christophe Grand
On Wed, Jul 29, 2009 at 9:49 AM, John Harrop  wrote:

> On Wed, Jul 29, 2009 at 2:59 AM, Daniel Lyons wrote:
>
>> Probably it would help to try and implement a lazy
>> list of the Fibonacci sequence before looking at that code, and then
>> maybe try some other mathematical sequences that are a little easier
>> to construct too.
>>
>
> Using the super-lazy-seq macro Wrexsoul posted a month or so ago, that's
> dead easy:
>
> (super-lazy-seq [a 0 b 1] (next-item b b (+ a b)))
>


Or, using rec-seq/rec-cat from seq-utils:
 (rec-cat fibs [1 1] (map + fibs (rest fibs)))

http://github.com/richhickey/clojure-contrib/blob/e20e8effe977640592b1f285d6c666492d74df00/src/clojure/contrib/seq_utils.clj#L97


> On the other hand,
>
> (defn fibs [] (cons 1 (cons 1 (lazy-seq (map + (fibs) (rest (fibs)))
> (def fibs (memoize fibs))
>

That's roughly what rec-seq does but using an atom and a local instead of a
var to keep the mutable state local.

Christophe

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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: fibonacci sequence using lazy-cat

2009-07-29 Thread Lauri Pesonen

Hi swaroop,

2009/7/29 swaroop belur :
>
> fibonacci sequence using lazy-cat :
> (def fibs (lazy-cat [0 1]   (map + fibs (rest fibs
>
> I am trying to understand how this works ..not sure i fully comprehend
> it.
>
> Can anyone please explain how clojure evaluates this.

I'll do my best, but I might get some details wrong.

> 1. so if we call (take 5 fibs) for example, what does fibs initially
> refer to?

Initially fibs will refer to 0, 1, and a function that will return the
rest of the sequence when evaluated. That's what the lazy-cat does: it
combines the first two elements of the sequence [0 1] with the
function for computing the remainder of the sequence.

Se when you ask for the first item in fibs, you'll get 0. When you ask
for the second item in fibs, you'll get 1. When you ask for the third
item in fibs you will get (+ (first fibs) (first (rest fibs))), which
is the same as (+ 0 1). The map form effectively produces this stream
(fixed font):

   fibs: 0 1 1 2 3 5...
(rest fibs): 1 1 2 3 5 8...
   +: 1 2 3 5 8 13...

which is possible because of lazy evaluation.

> 2. how does lazy-cat exactly work over here?

A lazy sequence is effectively a pair where the first element is a
value (e.g. 0 in fibs) and the second element is a function that when
evaluated returns another pair. That pair will again consist of the
next value in the sequence and a function for producing the rest of
the sequence. As an optimization the lazy sequence will cache the
elements of the sequence when they are evaluated, i.e. when you call
(nth 3 fibs) the third value of the fibs sequence will be cached for
future reference.

So in the fibs example fibs will originally be something like [0, 1,
(map + fibs (rest fibs))] and when you force the evaluation of the
third item fibs will be [0, 1, 1, (map + (rest fibs) (rest (rest
fibs)))], and so on.

Also, lazy-cat is itself lazy, so it will produce the next element of
the resulting sequence only when needed, which allows the user to call
lazy-cat with a number of lazy sequences without forcing them:

user> (def foo (map #(println "foo:" %) (range 0 10)))
#'user/foo
user> (def bar (map #(println "bar:" %) (range 10 20)))
#'user/bar
user> (def baz (lazy-cat foo bar))
#'user/baz
user> baz
(foo: 0
foo: 1
nil foo: 2
nil foo: 3
nil foo: 4
nil foo: 5
nil foo: 6
nil foo: 7
nil foo: 8
nil foo: 9
nil bar: 10
nil bar: 11
nil bar: 12
nil bar: 13
nil bar: 14
nil bar: 15
nil bar: 16
nil bar: 17
nil bar: 18
nil bar: 19
nil nil)

I.e. the println forms are evaluated only when the baz lazy sequence
is actually forced.

HTH

> swaroop

-- 
  ! Lauri

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



a regular expression for matching and for generating?

2009-07-29 Thread Rowdy Rednose

Does anybody know an elegant way to have a regex pattern with
capturing groups like in this simple example:

user=> (def pat #"^foo=([^;]*);bar=([^;]*);$")
#'user/pat

user=> (re-seq pat "foo=F0o;bar=bAr;")
(["foo=F0o;bar=bAr;" "F0o" "bAr"])

And reuse that pattern to generate a text that replaces the groups
like this:

user=> (re-gen pat "foo-gen" "bar-gen")
"foo=foo-gen;bar=bar-gen"

Actually, I wouldn't mind if the common representation was not a
Pattern, but something else, as long as I can use just one
representation as input and can do both matching and generating with
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
-~--~~~~--~~--~--~---



java 1.4 class files

2009-07-29 Thread Frank

Hi there,

is it possible to compile clojure source to Java 1.4 class files? If
so, how?

Thanks
Frank

--~--~-~--~~~---~--~~
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: fibonacci sequence using lazy-cat

2009-07-29 Thread Baishampayan Ghose
Swaroop,

> Just started learning clojure recently - initial examples were easy to
> understand, until I found this example
> 
> fibonacci sequence using lazy-cat :
> (def fibs (lazy-cat [0 1]   (map + fibs (rest fibs
> 
> I am trying to understand how this works ..not sure i fully comprehend
> it.
> 
> Can anyone please explain how clojure evaluates this.
> 1. so if we call (take 5 fibs) for example, what does fibs initially
> refer to?
> 2. how does lazy-cat exactly work over here?
> 
> Apologize if this has already been asked earlier.

Welcome to the fantastic world of Clojure! The implementation of the
fibonacci sequence that you cited above is a really neat example of
recursion over data (or corecursion) and lazy eavaluation.

This is possible because we are generating a lazy sequence using the
macro `lazy-cat'.

What `lazy-cat' actually does is that it first calls `lazy-seq' on all
the forms provided to it and then calls `concat' on all of them together.

So in this example, it eventually becomes something like this -

(def fibs (concat (lazy-seq [0 1]) (lazy-seq (map + fibs (rest fibs)

Now, how does this work?

Let's take an example.

When you do a (take 1 fibs) it doesn't need to run the `map' function as
the first two elements of `fibs' is already provided in the first lazy-seq.

Ditto for (take 2 fibs).

Now what if you do (take 3 fibs)? We need the third fibonacci number and
for that, we need to execute the map function which runs like this -

(map + [0 1] [1])

Why? you say. Well this is Corecursion :) The value of fibs which is
known till then is [0 1] and that's the value which is used inside the
map function, and with every call of map the value is changed to the
latest known value of fibs.

In case of (take 5 fibs), these are the steps in which the values are
calculated:

[0 1] -> [0 1]
[0 1] + (map + [0 1] [1]) -> [0 1 1]
[0 1] + (map + [0 1 1] [1 1]) -> [0 1 1 2]
[0 1] + (map + [0 1 1 2] [1 1 2]) -> [0 1 1 2 3]

And so on.

This is really cool, isn't it?

Regards,
BG

-- 
Baishampayan Ghose 
oCricket.com



signature.asc
Description: OpenPGP digital signature


Re: a regular expression for matching and for generating?

2009-07-29 Thread Stuart Sierra

Look at clojure.contrib.str-utils2/replace.  It accepts a function --
the fn will be called on each match, and its return value will be
inserted into the result string.

But that may not be quite what you want.  If you want true string
generation, you'd need a template library.
-SS


On Jul 29, 9:49 am, Rowdy Rednose  wrote:
> Does anybody know an elegant way to have a regex pattern with
> capturing groups like in this simple example:
>
> user=> (def pat #"^foo=([^;]*);bar=([^;]*);$")
> #'user/pat
>
> user=> (re-seq pat "foo=F0o;bar=bAr;")
> (["foo=F0o;bar=bAr;" "F0o" "bAr"])
>
> And reuse that pattern to generate a text that replaces the groups
> like this:
>
> user=> (re-gen pat "foo-gen" "bar-gen")
> "foo=foo-gen;bar=bar-gen"
>
> Actually, I wouldn't mind if the common representation was not a
> Pattern, but something else, as long as I can use just one
> representation as input and can do both matching and generating with
> 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: java 1.4 class files

2009-07-29 Thread Stuart Sierra

The Clojure runtime classes target Java 1.5.  Compiled clojure source
files still require clojure.jar.  So the answer is probably no, it's
not possible.
-SS

On Jul 29, 9:26 am, Frank  wrote:
> Hi there,
>
> is it possible to compile clojure source to Java 1.4 class files? If
> so, how?
>
> Thanks
> Frank
--~--~-~--~~~---~--~~
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: a regular expression for matching and for generating?

2009-07-29 Thread Chouser

On Wed, Jul 29, 2009 at 9:49 AM, Rowdy Rednose wrote:
>
> Does anybody know an elegant way to have a regex pattern with
> capturing groups like in this simple example:
>
> user=> (def pat #"^foo=([^;]*);bar=([^;]*);$")
> #'user/pat
>
> user=> (re-seq pat "foo=F0o;bar=bAr;")
> (["foo=F0o;bar=bAr;" "F0o" "bAr"])

user=> (re-seq #"(.*?)=(.*?);" "foo=F0o;bar=bAr;")
(["foo=F0o;" "foo" "F0o"] ["bar=bAr;" "bar" "bAr"])

> And reuse that pattern to generate a text that replaces the groups
> like this:
>
> user=> (re-gen pat "foo-gen" "bar-gen")
> "foo=foo-gen;bar=bar-gen"

(def my-keys (map second (re-seq #"(.*?)=(.*?);" "foo=F0o;bar=bAr;")))

user=> my-keys
("foo" "bar")

user=> (apply str (mapcat #(vector %1 "=" %2 ";") my-keys ["foo-gen"
"bar-gen"]))
"foo=foo-gen;bar=bar-gen;"

--Chouser

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



New JDK 7 Feature: Support for Dynamically Typed Languages in the JVM

2009-07-29 Thread Baishampayan Ghose
Hello,

It seems JDK 7 is going to implement JSR 223 which explicitly adds
support for Dynamic Programming languages running on the JVM.

http://java.sun.com/developer/technicalArticles/DynTypeLang/index.html

I would like to know how it will help the Clojure Runtime.

Regards,
BG

-- 
Baishampayan Ghose 
oCricket.com



signature.asc
Description: OpenPGP digital signature


Re: New JDK 7 Feature: Support for Dynamically Typed Languages in the JVM

2009-07-29 Thread Chouser

On Wed, Jul 29, 2009 at 11:41 AM, Baishampayan
Ghose wrote:
> Hello,
>
> It seems JDK 7 is going to implement JSR 223 which explicitly adds
> support for Dynamic Programming languages running on the JVM.
>
> http://java.sun.com/developer/technicalArticles/DynTypeLang/index.html
>
> I would like to know how it will help the Clojure Runtime.

http://clojure-log.n01se.net/date/2008-09-03.html#09:13a

--~--~-~--~~~---~--~~
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: Approaching Clojure-Hibernate integration using hibernate.default_entity_mode = dynamic-map (Feedback Request)

2009-07-29 Thread Shantanu Kumar

Hi Lico,

Please find the Hibernate-backed Clojure CRUD-test code here --
http://paste.lisp.org/+1T46

You will notice that I have NOT mentioned default_entity_mode=dynamic-
map anywhere in the config. I have simply used the syntax that goes
with dynamic map style. You could set that config as well in the
hibernate.properties or hibernate.cfg.xml file. Let me know if you
have any questions.

Regards,
Shantanu

On Jul 29, 5:45 am, Lico  wrote:
> Hi Shantanu,
>
> I am trying to do mapping without pojo. I will be very thankful if you
> could post me some crud examples you mentioned here.
>
> Thanks,
> Lico
>
> On Jul 23, 9:12 am, Shantanu Kumar  wrote:
>
>
>
> > I have an update since my last post. It is technically possible to
> > completely bypass the HBM-XML files and do the mapping stuff
> > programmatically, a route that I will likely take (XML generation does
> > not fit well in the arrangement and should be avoided). Taking this
> > route will bring the defmodel/hbm-property arrangement at par with
> > Java POJOs + annotations. Please check these links below on how to do
> > Hibernate mapping programmatically:
>
> >https://www.hibernate.org/hib_docs/v3/api/org/hibernate/cfg/Configura...()
>
> >https://www.hibernate.org/hib_docs/v3/api/org/hibernate/cfg/Mappings
>
> > > I've also looked into the dynamic-map stuff, but found only
> > > rudimentary documentation, which caused me to give up. It's nice to
> > > see that you seem to have gotten further.
>
> > I got some simple tests working - CRUD sort of (no relationships yet).
> > If you would like to take a look at the code, please let me know.
>
> > > Also, I think the design should allow for future integration of
> > > Hibernate-validation (bean-validation).
>
> > That's a great alert - thanks! :-)
>
> > Regards,
> > Shantanu
>
> > On Jul 23, 4:26 pm, pmf  wrote:
>
> > > I've also looked into the dynamic-map stuff, but found only
> > > rudimentary documentation, which caused me to give up. It's nice to
> > > see that you seem to have gotten further.
>
> > > For me personally, well-polished defmodel/hbm-property functionality
> > > would be much more important than a query-DSL (since you plan to make
> > > HQL accessible, this would be enough for me).
>
> > > To ease the transition from Java + Hibernate-annotations to Clojure +
> > > hbm-property, it would be nice to have a strong (semantic)
> > > correspondence between Hibernate-annotations and the hbm-property
> > > construct (using lispified names and casing, as you already did, but
> > > otherwise staying very close to the structure of the Hibernate-
> > > annotations).
>
> > > Also, I think the design should allow for future integration of
> > > Hibernate-validation (bean-validation).
--~--~-~--~~~---~--~~
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: java 1.4 class files

2009-07-29 Thread Daniel Janus

I'd try to first compile Clojure to 1.5 bytecode, then translate it to
1.4 using Retroweaver (http://retroweaver.sourceforge.net/).  I don't
know whether that'll work, though, since I think the Clojure compiler
generates and loads bytecode at runtime.  You might need to patch
Clojure to somehow squeeze retroweaving between the compiling and
loading phases.

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



inlining bitwise operations?

2009-07-29 Thread Daniel Janus

Hello,

Is there any reason for some of the bitwise functions (bit-and-not,
bit-clear, bit-set, bit-flip, bit-test, bit-shift-left and bit-shift-
right) not having inline variants?

Thanks,
Daniel

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



Exit delay from java when lazy?

2009-07-29 Thread mwillson

Hi,

I was experimenting with Clojure and XML and stumbled upon a lengthy
hang when exiting java which was tracked down to the use of
clojure.contrib.lazy-xml.  Here's a toy example which exhibits the
issue:

Script started on Wed Jul 29 15:06:44 2009
[~/dev/clojure]$ cat read-xml-lazy.clj
(ns strange
  (:use clojure.contrib.lazy-xml)
  (import (java.io ByteArrayInputStream)))

(time (clojure.contrib.lazy-xml/parse-trim
   (ByteArrayInputStream. (.getBytes (slurp "msgs.xml")
#_(System/exit 0)

[~/dev/clojure]$ time java -cp clojure-1.0.0.jar\;clojure-contrib.jar
clojure.lang.Script read-xml-lazy.clj
"Elapsed time: 691.81977 msecs"

real1m1.796s
user0m0.031s
sys 0m0.061s
[~/dev/clojure]$ # now without laziness
[~/dev/clojure]$ cat read-xml-nonlazy.clj
(ns strange
  (import (java.io ByteArrayInputStream)))

(time (clojure.xml/parse
   (ByteArrayInputStream. (.getBytes (slurp "msgs.xml")
#_(System/exit 0)


[~/dev/clojure]$ time java -cp clojure-1.0.0.jar\;clojure-contrib.jar
clojure.lang.Script read-xml-nonlazy.clj
"Elapsed time: 15493.727555 msecs"

real0m16.406s
user0m0.047s
sys 0m0.031s

[~/dev/clojure]$ java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

[~/dev/clojure]$ exit
exit

Script done on Wed Jul 29 15:11:14 2009

While the time to perform the lazy xml read is much less than the non-
lazy, it takes nearly a minute to exit java.  If the (System/exit 0)
form is enabled, then the exit from java is immediate.

This is on a Windows XP platform, using cygwin as the shell, although
the same issue occurs when run under cmd.exe.  The version of clojure-
contrib is that provided by the "Programming Clojure" download.

The msgs.xml file is about 3.7MB and contains about 1300 XML elements
under the root.  It looks a bit like:



...many elements in message


...many elements in message



So, it looks like my mother was right and laziness costs in the end.
Is anyone able to shed light on what might be going on here?

Many thanks,
Mark Willson

--~--~-~--~~~---~--~~
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: New JDK 7 Feature: Support for Dynamically Typed Languages in the JVM

2009-07-29 Thread Robert Fischer

It's actually JSR 292 (invoke_dynamic) that's the big news.

~~ Robert.

Baishampayan Ghose wrote:
> Hello,
> 
> It seems JDK 7 is going to implement JSR 223 which explicitly adds
> support for Dynamic Programming languages running on the JVM.
> 
> http://java.sun.com/developer/technicalArticles/DynTypeLang/index.html
> 
> I would like to know how it will help the Clojure Runtime.
> 
> Regards,
> BG
> 

-- 
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

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



Setting-up clojure, clojure-mode and slime with Common-Lisp on Emacs

2009-07-29 Thread Felipe

This is my blog post about how to set up clojure in emacs, using
clojure-mode. I hope you enjoy:
http://felipero.posterous.com/1446961

--~--~-~--~~~---~--~~
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: fibonacci sequence using lazy-cat

2009-07-29 Thread swaroop belur


cool - thanks guys  for the detailed reply.  crystal clear now -:)

Thx
swaroop

--~--~-~--~~~---~--~~
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 performance degraded

2009-07-29 Thread Nico Swart
I recently got clojure source and rebuilt clojure.jar. I noticed that the
performance is significantly worse with the new clojure.jar compared to a
older clojure.jar. Everything else is the same, I just change
the clojure.jar file and the performance is 4x slower. Below the output  -
Note the runtimes.
The application is just a solution finder to a solitaire type problem.
Incidently, the equivalent solution
in Clisp runs in < 10s.

-
With new clojure.jar
-
user=> (time (find-sol-biz 25000))

  OOO
  OOO
OOO
OOOXOOO
OOO
  OOO
  OOO

"Elapsed time: 108985.946259 msecs"
((10 24) (15 17) (30 16) (17 15) (19 17) (4 18) (2 4) (25 11) (4 18) (14 16)
(9 23) (17 19) (20 18) (39 25) (18 32) (44 30) (23 37) (21 23) (23 25) (25
39) (27 25) (46 32) (25 39) (28 30) (30 44) (34 32) (31 33) (44 46) (46 32)
(33 31) (38 24))
user=>


With previous clojure.jar
---
(time (find-sol-biz 25000))

  OOO
  OOO
OOO
OOOXOOO
OOO
  OOO
  OOO

"Elapsed time: 27402.569601 msecs"
((10 24) (15 17) (30 16) (17 15) (19 17) (4 18) (2 4) (25 11) (4 18) (14 16)
(9 23) (17 19) (20 18) (39 25) (18 32) (44 30) (23 37) (21 23) (23 25) (25
39) (27 25) (46 32) (25 39) (28 30) (30 44) (34 32) (31 33) (44 46) (46 32)
(33 31) (38 24))
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: Clojure performance degraded

2009-07-29 Thread Baishampayan Ghose
Nico Swart wrote:
> I recently got clojure source and rebuilt clojure.jar. I noticed that
> the performance is 
> significantly worse with the new clojure.jar compared to a older
> clojure.jar. Everything else is the same, I just change
> the clojure.jar file and the performance is 4x slower. Below the output
>  - Note the runtimes.
> The application is just a solution finder to a solitaire type problem.
> Incidently, the equivalent solution
> in Clisp runs in < 10s.
> 
> -
> With new clojure.jar
> -
> user=> (time (find-sol-biz 25000))
> 
>   OOO  
>   OOO  
> OOO
> OOOXOOO
> OOO
>   OOO  
>   OOO  
> 
> "Elapsed time: 108985.946259 msecs"
> ((10 24) (15 17) (30 16) (17 15) (19 17) (4 18) (2 4) (25 11) (4 18) (14
> 16) (9 23) (17 19) (20 18) (39 25) (18 32) (44 30) (23 37) (21 23) (23
> 25) (25 39) (27 25) (46 32) (25 39) (28 30) (30 44) (34 32) (31 33) (44
> 46) (46 32) (33 31) (38 24))
> user=> 
> 
> 
> With previous clojure.jar
> ---
> (time (find-sol-biz 25000))
> 
>   OOO  
>   OOO  
> OOO
> OOOXOOO
> OOO
>   OOO  
>   OOO  
> 
> "Elapsed time: 27402.569601 msecs"
> ((10 24) (15 17) (30 16) (17 15) (19 17) (4 18) (2 4) (25 11) (4 18) (14
> 16) (9 23) (17 19) (20 18) (39 25) (18 32) (44 30) (23 37) (21 23) (23
> 25) (25 39) (27 25) (46 32) (25 39) (28 30) (30 44) (34 32) (31 33) (44
> 46) (46 32) (33 31) (38 24))
> user=> 

Can you kindly attach the code that you used to test?

Regards,
BG

-- 
Baishampayan Ghose 
oCricket.com



signature.asc
Description: OpenPGP digital signature


Re: fibonacci sequence using lazy-cat

2009-07-29 Thread Stuart Halloway

While fibs is a nice small example, it is not idiomatic Clojure.  
Pointing the fibs var to the head of the list keeps the whole list in  
memory as it realizes. Better is to expose fibs as a *function* return  
the sequence, so the head is not retained.

(defn fibo []
  (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))

This and several inferior examples are demonstrated in the sample code  
for the book [1].

Cheers,
Stu

[1] http://bit.ly/Ew6It

> cool - thanks guys  for the detailed reply.  crystal clear now -:)
>
> Thx
> swaroop
>
> >


--~--~-~--~~~---~--~~
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: Exit delay from java when lazy?

2009-07-29 Thread Michael Wood

2009/7/29 mwillson :
>
> Hi,
>
> I was experimenting with Clojure and XML and stumbled upon a lengthy
> hang when exiting java which was tracked down to the use of
> clojure.contrib.lazy-xml.  Here's a toy example which exhibits the
> issue:

I haven't looked at clojure.contrib.lazy-xml, but this sounds like
what happens if you make use of agents.  Shutting down the agents with
(shutdown-agents) should fix it if so.  Perhaps
clojure.contrib.lazy-xml uses agents.

See also:
http://groups.google.com/group/clojure/browse_thread/thread/409054e3542adc1f

I couldn't find anything better because Google Groups' search was
telling me it couldn't find anything I tried looking for.

-- 
Michael Wood 

--~--~-~--~~~---~--~~
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: REQUEST: Add seqable? to core

2009-07-29 Thread Chris Kent

I was thinking exactly the same thing.  It feels like there should be
a better way than instance? ...Sequable.  Unless there's a reason
that's a bad idea.

Chris

On Jul 27, 6:49 pm, Sean Devlin  wrote:
> Rich,
>
> There have been a few times in this thread that people have tried to
> determine if a function was seqable, and used the following code
>
> (seq? a-collection)
>
> While this code is great for determining if a-collection is a
> sequence, it is sometimes not what people want.  Often the following
> code is meant to be used:
>
> (instance? clojure.lang.Seqable a-collection)
>
> I speculate that many people have something like the following code in
> their library collection:
>
> (defn seqable?
>   "Returns true if (seq x) should work.  That is, it tests if x
> implements clojure.lang.Seqable"
>   [x]
>   (instance? clojure.lang.Seqable x))
>
> Could something like seqable? be added to core?  Am I mistaken in the
> need for standardizing this function?
>
> Sean
>
> PS - Sorry if this isn't the right avenue for feature requests.
--~--~-~--~~~---~--~~
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: REQUEST: Add seqable? to core

2009-07-29 Thread Chouser

On Mon, Jul 27, 2009 at 1:49 PM, Sean Devlin wrote:
>
> There have been a few times in this thread that people have tried to
> determine if a function was seqable, and used the following code
>
> (seq? a-collection)
>
> While this code is great for determining if a-collection is a
> sequence, it is sometimes not what people want.  Often the following
> code is meant to be used:
>
> (instance? clojure.lang.Seqable a-collection)

I think the only thing that currently extends Seqable is
IPersistentCollection, which is testable with 'coll?'

> (defn seqable?
>  "Returns true if (seq x) should work.  That is, it tests if x
> implements clojure.lang.Seqable"
>  [x]
>  (instance? clojure.lang.Seqable x))

Note however that seq works on things that are not
IPersistentCollections nor Seqable, like java collections,
strings, etc.

user=> (filter #(Character/isUpperCase %) "Works For Me")
(\W \F \M)

user=> (seq (java.util.HashMap. {:a 1, :b 2, :c 3}))
(# # #)

> PS - Sorry if this isn't the right avenue for feature requests.

No worries -- you're going about this exactly the right way.
:-)

--Chouser

--~--~-~--~~~---~--~~
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: REQUEST: Add seqable? to core

2009-07-29 Thread Rich Hickey



On Jul 29, 3:45 pm, Chris Kent  wrote:
> I was thinking exactly the same thing.  It feels like there should be
> a better way than instance? ...Sequable.  Unless there's a reason
> that's a bad idea.
>

There's some discussion here and the linked-to message:

http://groups.google.com/group/clojure/msg/385098fabfcaad9b

Rich

>
> On Jul 27, 6:49 pm, Sean Devlin  wrote:
>
>
>
> > Rich,
>
> > There have been a few times in this thread that people have tried to
> > determine if a function was seqable, and used the following code
>
> > (seq? a-collection)
>
> > While this code is great for determining if a-collection is a
> > sequence, it is sometimes not what people want.  Often the following
> > code is meant to be used:
>
> > (instance? clojure.lang.Seqable a-collection)
>
> > I speculate that many people have something like the following code in
> > their library collection:
>
> > (defn seqable?
> >   "Returns true if (seq x) should work.  That is, it tests if x
> > implements clojure.lang.Seqable"
> >   [x]
> >   (instance? clojure.lang.Seqable x))
>
> > Could something like seqable? be added to core?  Am I mistaken in the
> > need for standardizing this function?
>
> > Sean
>
> > PS - Sorry if this isn't the right avenue for feature requests.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Possible bug report

2009-07-29 Thread Jason Wolfe

Is this a bug?

user> (eval `(make-array ~Byte/TYPE 2))
; Evaluation aborted. (ExceptionInInitializerError)

Compare:

user> (eval `(make-array ~Byte 2))
#

user> (eval `(make-array Byte/TYPE 2))
#

user> (make-array (eval Byte/TYPE) 2)
#

If not, can someone please help me understand what's going on here?

Thanks!
Jason
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Has anyone tried using Clojure with JavaFX?

2009-07-29 Thread samppi

I haven't tried JavaFX much myself, but has anyone tried or thought
about using Clojure to manage the logic and data of a JavaFX
application yet? What limitations would there be, other than having to
compile its Clojure code?
--~--~-~--~~~---~--~~
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 performance degraded

2009-07-29 Thread Nico
Baishampayan Ghose wrote:
> Nico Swart wrote:
>   
>> I recently got clojure source and rebuilt clojure.jar. I noticed that
>> the performance is 
>> significantly worse with the new clojure.jar compared to a older
>> clojure.jar. Everything else is the same, I just change
>> the clojure.jar file and the performance is 4x slower. Below the output
>>  - Note the runtimes.
>> The application is just a solution finder to a solitaire type problem.
>> Incidently, the equivalent solution
>> in Clisp runs in < 10s.
>>
>> -
>> With new clojure.jar
>> -
>> user=> (time (find-sol-biz 25000))
>>
>>   OOO  
>>   OOO  
>> OOO
>> OOOXOOO
>> OOO
>>   OOO  
>>   OOO  
>>
>> "Elapsed time: 108985.946259 msecs"
>> ((10 24) (15 17) (30 16) (17 15) (19 17) (4 18) (2 4) (25 11) (4 18) (14
>> 16) (9 23) (17 19) (20 18) (39 25) (18 32) (44 30) (23 37) (21 23) (23
>> 25) (25 39) (27 25) (46 32) (25 39) (28 30) (30 44) (34 32) (31 33) (44
>> 46) (46 32) (33 31) (38 24))
>> user=> 
>>
>> 
>> With previous clojure.jar
>> ---
>> (time (find-sol-biz 25000))
>>
>>   OOO  
>>   OOO  
>> OOO
>> OOOXOOO
>> OOO
>>   OOO  
>>   OOO  
>>
>> "Elapsed time: 27402.569601 msecs"
>> ((10 24) (15 17) (30 16) (17 15) (19 17) (4 18) (2 4) (25 11) (4 18) (14
>> 16) (9 23) (17 19) (20 18) (39 25) (18 32) (44 30) (23 37) (21 23) (23
>> 25) (25 39) (27 25) (46 32) (25 39) (28 30) (30 44) (34 32) (31 33) (44
>> 46) (46 32) (33 31) (38 24))
>> user=> 
>> 
>
> Can you kindly attach the code that you used to test?
>
> Regards,
> BG
>
>   
Attached the code I used. I did not include it at first since it was the 
same on
both occasions.

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

;; Solitaire solution finder.

(use 'clojure.contrib.math)

(defstruct game-position :pos :moves)

(def solution-pos (struct game-position  (vector 'ill 'ill 'emp 'emp 'emp 'ill 
'ill
 'ill 'ill 'emp 'emp 'emp 'ill 
'ill
 'emp 'emp 'emp 'emp 'emp 'emp 
'emp
 'emp 'emp 'emp 'pin 'emp 'emp 
'emp
 'emp 'emp 'emp 'emp 'emp 'emp 
'emp
 'ill 'ill 'emp 'emp 'emp 'ill 
'ill
 'ill 'ill 'emp 'emp 'emp 'ill 
'ill
 ), nil))

(def test-pos (struct game-position  (vector 'ill 'ill 'emp 'emp 'pin 'ill 'ill
 'ill 'ill 'emp 'pin 'pin 'ill 'ill
 'emp 'emp 'emp 'pin 'emp 'pin 'pin
 'emp 'pin 'pin 'emp 'emp 'emp 'emp
 'emp 'emp 'emp 'emp 'emp 'emp 'emp
 'ill 'ill 'emp 'emp 'emp 'ill 'ill
 'ill 'ill 'emp 'emp 'emp 'ill 'ill
 ), nil))

(defn pin<->emp [elem]
  (cond (= elem 'pin) 'emp
(= elem 'emp) 'pin
true 'ill))

;; map-vector : (vectorof elem)  ->  (vectorof elem)
;; apply f to v and produce a new vector
;; example: (map-vector (lambda (x) x) v) produces a copy of v
(defn map-vector [f v]
  (vec (map f v)))

;; start is inverse of solution
(def start-pos (struct game-position (map-vector pin<->emp (:pos solution-pos)) 
nil))

(defn add1 [val] (+ 1 val))
(defn sub1 [val] (- val 1))

(defn valid-right [{pos :pos} from]
  (let [to (+ from 2)
jump (add1 from)]
(if (and (>= to 0) (< to 49)
 (> jump 0) (< jump 49)
 (= (int (/ to 7)) (int (/ from 7)))
 (= (nth pos from) 'pin) 
 (= (nth pos to) 'emp) 
 (= (nth pos jump) 'pin))
(list from to) nil)))

(defn valid-left [{pos :pos} from]
  (let [to (- from 2)
jump (sub1 from)]
(if (and (>= to 0) (< to 49)
 (> jump 0) (< jump 49)
 (= (int (/ to 7)) (int (/ from 7)))
 (= (nth pos from) 'pin) 
 (= (nth pos to) 'emp) 
 (= (nth pos jump) 'pin))
(list from to) nil)))

(defn valid-down [{pos :pos} from]
  (let [to (+ from 14)
jump (+ from 7)]
(if (and (>= to 0) (< to 49)
 (> jump 0) (< jump 49)
 (= (mod to 7) (mod from 7)

Re: REQUEST: Add seqable? to core

2009-07-29 Thread John Harrop
How about defining seqable? in terms of whether seq works, using try catch?
Or better yet:

(defmacro if-seq
  "If (seq obj) makes sense, evaluates expr1 with name bound to (seq obj);
otherwise evaluates expr2."
  [[name obj] expr1 expr2]
  `(let [[~name failed#] (try
   [(seq ~obj) false]
   (catch Throwable _# [~expr2 true]))]
(if failed# ~name ~expr1)))

user=> (if-seq [foo [1 2 3]] foo 0)
(1 2 3)
user=> (if-seq [foo (let [a (java.util.ArrayList.)] (.add a 17) a)] foo 0)
(17)
user=> (if-seq [foo "string"] foo 0)
(\s \t \r \i \n \g)
user=> (if-seq [foo 'bar] foo 0)
0

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



Re: Possible bug report

2009-07-29 Thread John Harrop
On Wed, Jul 29, 2009 at 6:09 PM, Jason Wolfe  wrote:

>
> Is this a bug?
>
> user> (eval `(make-array ~Byte/TYPE 2))
> ; Evaluation aborted. (ExceptionInInitializerError)
>
> Compare:
>
> user> (eval `(make-array ~Byte 2))
> #
>
> user> (eval `(make-array Byte/TYPE 2))
> #
>
> user> (make-array (eval Byte/TYPE) 2)
> #
>
> If not, can someone please help me understand what's going on here?


It's some sort of classloader error:

Caused by: java.lang.ClassNotFoundException: byte
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:55)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)

If you eval `(make-array Byte/TYPE 2) that's two Symbols and an Integer in
the s-expr it evaluates.

user=> (map type `(make-array Byte/TYPE 2))
(clojure.lang.Symbol clojure.lang.Symbol java.lang.Integer)

This works as it does at the REPL. If you eval `(make-array ~Byte/TYPE 2)
the s-expr has a Symbol, a literal Class object, and an Integer:

user=> (map type `(make-array ~Byte/TYPE 2))
(clojure.lang.Symbol java.lang.Class java.lang.Integer)

Apparently eval doesn't like it if a Class object is in an s-expr and is a
primitive type's Class, but does not mind if it is a reference type's Class
(as when it's just ~Byte in there).

It must be that different class-loading is done by eval when it sees a
literal Class object than when it sees a Symbol that references a Class. The
latter case apparently correctly handles the corner-case that it's a
primitive type's Class object, such as Byte/TYPE, while the former case
screws up in the same corner-case.

I'd consider this to be a bug, or at least a wart. Clojure actually has
relatively few of them, far fewer than Java itself or C++, but I'm not too
surprised to see the occasional one in such a large and complex software
system.

Rich will have to make the final decision as to whether this is officially a
bug, is expected (though somewhat broken-seeming) behavior, or what, and
whether to fix it or not.

--~--~-~--~~~---~--~~
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: REQUEST: Add seqable? to core

2009-07-29 Thread J. McConnell
On Wed, Jul 29, 2009 at 11:06 PM, John Harrop  wrote:

> How about defining seqable? in terms of whether seq works, using try catch?
>

I think this is the only DRY way to do it, but I know Rich has expressed in
the past the he does not approve of using exception handling as a form of
flow control.

Stephen Gilardi added a seqable? function to clojure.contrib.core here:

http://github.com/richhickey/clojure-contrib/commit/bc07de7c3b1058f4263bd7b1c424f771fb010005

Regards,

- J.

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