Re: Good memory profilers (program or human)?

2009-07-31 Thread Berlin Brown



On Jul 31, 12:06 pm, Berlin Brown  wrote:
> On Jul 31, 4:45 am, Andy Fingerhut 
> wrote:
>
>
>
> > I thought I'd follow up my own question with some programs that I
> > should have already known about for memory profiling, which were
> > already installed on my Mac as part of the standard Java installation
> > from Apple (who are just passing them on from Sun, I'm sure), but I
> > didn't know about them:
>
> > jconsole -- Good for seeing how fast a java process is allocating
> > memory, and garbage collecting.
>
> > jmap -- Good for a quick summary of the above, or with the "-histo"
> > option, a much more detailed list of what kinds of objects are taking
> > up the most memory.
>
> > I also learned that Clojure's cons and lazy cons structures take up 48
> > bytes per element (at least on a Mac with 'java -client' and java
> > 1.6.0_), which gets significant when your program has sequences
> > of several millions of elements about.
>
> > I've updated my github repo with a pretty decent version of the
> > reverse-complement benchmark in Clojure.  It isn't as sequence-y as it
> > could be, but the more sequence-y version generates and collects
> > garbage so fast that it really slows things down significantly.  Same
> > lesson from other flavors of Lisp, I guess -- you can write the
> > straightforward easy-to-write-and-test-and-understand code that conses
> > a lot (i.e. allocates memory quickly that typically becomes garbage
> > quite soon), or you can write the more loopy code that doesn't, but
> > typically starts to merge many things that you'd otherwise prefer to
> > separate into different functions.  Just compare revcomp.clj-5.clj and
> > revcomp.clj-6.clj in my git repo for an example.
>
> > The nice thing is that when you don't need the "uglier" code, Clojure
> > and other Lisps usually let you write code much more concisely than
> > lower level languages.  Get it working first, then optimize it.  Since
> > I'm comparing run times of the Clojure programs versus those submitted
> > to the language shootout benchmark web site, some of which appear
> > quite contorted in order to gain performance, I wanted to do some
> > optimizations that you wouldn't necessarily want to do otherwise.
>
> > git://github.com/jafingerhut/clojure-benchmarks.git
>
> > You can see my latest run time results here.  I've got 4 benchmarks
> > written in Clojure so far, with my current versions being 6x, 8x, 12x,
> > and 15x more CPU time than the Java programs submitted to the language
> > shootout benchmark web site.
>
> >http://github.com/jafingerhut/clojure-benchmarks/blob/20d21bc169d52ca...
>
> > I could make some of these significantly closer in speed to the Java
> > versions, but I suspect that they will start looking more and more
> > like the Java versions if I do, except with Clojure syntax for Java
> > calls.  I'm happy to be proved wrong on that, if someone finds better
> > Clojure versions than I've got.
>
> > Thanks,
> > Andy
>
> > On Jul 30, 11:00 am, Andy Fingerhut 
> > wrote:
>
> > > I'm gradually adding a few more Clojure benchmark programs to my
> > > repository here:
>
> > > git://github.com/jafingerhut/clojure-benchmarks.git
>
> > > The one I wrote for the "reverse-complement" benchmark is here:
>
> > >http://github.com/jafingerhut/clojure-benchmarks/blob/4ab4f41c6f96344...
>
> > > revcomp.clj-4.clj is the best I've got so far, but it runs out of
> > > memory on the full size benchmark.
>
> > > If you clone the repository, and successfully run the init.sh script
> > > to generate the big input and expected output files, the file rcomp/
> > > long-input.txt contains 3 DNA sequences in FASTA format. The first is
> > > 50,000,000 characters long, the second is 75,000,000 characters long,
> > > and the third is 125,000,000 characters long. Each needs to be
> > > reversed, have each character replaced with a different one, and
> > > printed out, so we need to store each of the strings one at a time,
> > > but it is acceptable to deallocate/garbage-collect the previous one
> > > when starting on the next. I think my code should be doing that, but I
> > > don't know how to verify that.
>
> > > I've read that a Java String takes 2 bytes per character, plus about
> > > 38 bytes of overhead per string. That is about 250 Mbytes for the
> > > longest one. I also r

Re: Good memory profilers (program or human)?

2009-07-31 Thread Berlin Brown



On Jul 31, 4:45 am, Andy Fingerhut 
wrote:
> I thought I'd follow up my own question with some programs that I
> should have already known about for memory profiling, which were
> already installed on my Mac as part of the standard Java installation
> from Apple (who are just passing them on from Sun, I'm sure), but I
> didn't know about them:
>
> jconsole -- Good for seeing how fast a java process is allocating
> memory, and garbage collecting.
>
> jmap -- Good for a quick summary of the above, or with the "-histo"
> option, a much more detailed list of what kinds of objects are taking
> up the most memory.
>
> I also learned that Clojure's cons and lazy cons structures take up 48
> bytes per element (at least on a Mac with 'java -client' and java
> 1.6.0_), which gets significant when your program has sequences
> of several millions of elements about.
>
> I've updated my github repo with a pretty decent version of the
> reverse-complement benchmark in Clojure.  It isn't as sequence-y as it
> could be, but the more sequence-y version generates and collects
> garbage so fast that it really slows things down significantly.  Same
> lesson from other flavors of Lisp, I guess -- you can write the
> straightforward easy-to-write-and-test-and-understand code that conses
> a lot (i.e. allocates memory quickly that typically becomes garbage
> quite soon), or you can write the more loopy code that doesn't, but
> typically starts to merge many things that you'd otherwise prefer to
> separate into different functions.  Just compare revcomp.clj-5.clj and
> revcomp.clj-6.clj in my git repo for an example.
>
> The nice thing is that when you don't need the "uglier" code, Clojure
> and other Lisps usually let you write code much more concisely than
> lower level languages.  Get it working first, then optimize it.  Since
> I'm comparing run times of the Clojure programs versus those submitted
> to the language shootout benchmark web site, some of which appear
> quite contorted in order to gain performance, I wanted to do some
> optimizations that you wouldn't necessarily want to do otherwise.
>
> git://github.com/jafingerhut/clojure-benchmarks.git
>
> You can see my latest run time results here.  I've got 4 benchmarks
> written in Clojure so far, with my current versions being 6x, 8x, 12x,
> and 15x more CPU time than the Java programs submitted to the language
> shootout benchmark web site.
>
> http://github.com/jafingerhut/clojure-benchmarks/blob/20d21bc169d52ca...
>
> I could make some of these significantly closer in speed to the Java
> versions, but I suspect that they will start looking more and more
> like the Java versions if I do, except with Clojure syntax for Java
> calls.  I'm happy to be proved wrong on that, if someone finds better
> Clojure versions than I've got.
>
> Thanks,
> Andy
>
> On Jul 30, 11:00 am, Andy Fingerhut 
> wrote:
>
> > I'm gradually adding a few more Clojure benchmark programs to my
> > repository here:
>
> > git://github.com/jafingerhut/clojure-benchmarks.git
>
> > The one I wrote for the "reverse-complement" benchmark is here:
>
> >http://github.com/jafingerhut/clojure-benchmarks/blob/4ab4f41c6f96344...
>
> > revcomp.clj-4.clj is the best I've got so far, but it runs out of
> > memory on the full size benchmark.
>
> > If you clone the repository, and successfully run the init.sh script
> > to generate the big input and expected output files, the file rcomp/
> > long-input.txt contains 3 DNA sequences in FASTA format. The first is
> > 50,000,000 characters long, the second is 75,000,000 characters long,
> > and the third is 125,000,000 characters long. Each needs to be
> > reversed, have each character replaced with a different one, and
> > printed out, so we need to store each of the strings one at a time,
> > but it is acceptable to deallocate/garbage-collect the previous one
> > when starting on the next. I think my code should be doing that, but I
> > don't know how to verify that.
>
> > I've read that a Java String takes 2 bytes per character, plus about
> > 38 bytes of overhead per string. That is about 250 Mbytes for the
> > longest one. I also read in a seq of lines, and these long strings are
> > split into lines with 60 characters (plus a newline) each. Thus the
> > string's data needs to be stored at least twice temporarily -- once
> > for the many 60-character strings, plus the final long one.  Also, the
> > Java StringBuilder that Clojure's (str ...) function uses probably
> > needs to be copied and reallocated periodically as it outgrows its
> > current allocation. So I could imagine needing about 3 * 250 Mbytes
> > temporarily, but that doesn't explain why my 1536 Mbytes of JVM memory
> > are being exhausted.
>
> > It would be possible to improve things by not creating all of the
> > separate strings, one for each line, and then concatenating them
> > together. But first I'd like to explain why it is using so much,
> > because I must be missing something.
>
> > Thank,
>

Re: Clojure performance tests and clojure a little slower than Java

2009-07-28 Thread Berlin Brown



On Jul 28, 2:37 pm, fft1976  wrote:
> Thanks, AndyF for writing the code! I'm glad someone's done a
> comparison of idiomatic code instead of making unsubstantiated claims.

Are you implying that my claims are unsubstantiated or non idiomatic.
I took the frequency code from clojure/contrib and it only takes up 3
lines.
--~--~-~--~~~---~--~~
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-28 Thread Berlin Brown

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

2009-07-27 Thread Berlin Brown



On Jul 27, 2:15 pm, Aaron Cohen  wrote:
> http://groups.google.com/group/clojure/browse_thread/thread/7ab7c1e62...
> <http://groups.google.com/group/clojure/browse_thread/thread/7ab7c1e62...>http://groups.google.com/group/clojure/browse_thread/thread/6cd78dea8...
>
> <http://groups.google.com/group/clojure/browse_thread/thread/6cd78dea8...>For
> more examples, please just browse the first google link I gave you.
>
> -- Aaron
>
> On Mon, Jul 27, 2009 at 2:00 PM, Berlin Brown wrote:
>
>
>
> > On Jul 27, 1:57 pm, Berlin Brown  wrote:
> > > "One thing you need to do is define what you mean exactly when you say
> > > "Java
> > > vs Clojure." "
>
> > > Like I said, I didn't want to get too focused on this particular
> > > example.  Is there code where I could run in Clojure and where I could
> > > run in Java that would end up with the same result.  And then I could
> > > see the differences in performance.  Also is there an example where
> > > Clojure code is comparable.
>
> > > For example, lets say the Euler problem number 1 wants you want to
> > > return a result of 123.
>
> > > The end result is 123, if I write code in Java and then in Clojure, I
> > > want to see the runtimes of the different versions.
>
> > > On Jul 27, 1:34 pm, Aaron Cohen  wrote:
>
> > > > One thing you need to do is define what you mean exactly when you say
> > "Java
> > > > vs Clojure."
> > > > In your example you are comparing clojure code vs java code but you are
> > also
> > > > comparing clojure data structures (PersistentMap) with traditional Java
> > data
> > > > structures (HashMap).  I'm not sure you meant to conflate the two.
>
> > > > Also, there have been plenty of threads that start off comparing java
> > and
> > > > clojure performance and eventually end up at near-equivalent
> > performance
> > > > after using type hints/coercion/etc.  It has become something of a FAQ.
> >  I'd
> > > > start with:
> >http://groups.google.com/groups/search?q=group:clojure+performance&qt...
> > > > <
> >http://groups.google.com/groups/search?q=group:clojure+performance&qt...>
> > > > -- Aaron
>
> > > > On Mon, Jul 27, 2009 at 1:06 PM, BerlinBrown 
> > wrote:
>
> > > > > I was coming up with some performance tests for Clojure, going back
> > > > > and forth between different JVM languages (JRuby, Scala) and mainly
> > > > > looking at pure Java code.  So far I have found that clojure is about
> > > > > 5-10 times as slow as comparable code in Clojure.  Of course this is
> > > > > before any optimizations.
>
> > > > > Here is my question, do you have any code both Clojure and Java where
> > > > > there is a one to one match between code where Clojure runs as fast
> > as
> > > > > Java.  It could be anything.
>
> > > > > Here is one example:
> > > > > This is code from clojure/contrib to convert a list of data into a
> > > > > frequency count map.  Pretty standard stuff.
>
> > > > > (defn frequencies
> > > > >  "Returns a map from distinct items in coll to the number of times
> > > > >  they appear."
> > > > >  [coll]
> > > > >  ;
> > > > >  (reduce (fn [counts x]
> > > > >  (assoc counts x (inc (get counts x 0
> > > > >  {} coll))
>
> > > > >  (dotimes [x 4]
> > > > >  (println "i: " (int (Math/pow 10.0 x)))
> > > > >(time
> > > > > (dotimes [_ (int (Math/pow 10.0 x))]
> > > > > (let [a (for [_ (range 1000)] (random-string 3))]
> > > > >   (frequencies a)
>
> > > > > --
>
> > > > >public static Map frequencies(final List list) {
> > > > >final Map map = new HashMap();
> > > > >// Simple Box and then unbox the count as the value for this
> > > > > map //
> > > > >for (Iterator it = list.iterator(); it.hasNext(); ) {
> > > > >final Object o = it.next();
> > > > >final String s = o.toString();
> > > > >Integer prev = (Integer) map.get(s);
> > > > >if (prev ==

Re: Clojure performance tests and clojure a little slower than Java

2009-07-27 Thread Berlin Brown



On Jul 27, 1:57 pm, Berlin Brown  wrote:
> "One thing you need to do is define what you mean exactly when you say
> "Java
> vs Clojure." "
>
> Like I said, I didn't want to get too focused on this particular
> example.  Is there code where I could run in Clojure and where I could
> run in Java that would end up with the same result.  And then I could
> see the differences in performance.  Also is there an example where
> Clojure code is comparable.
>
> For example, lets say the Euler problem number 1 wants you want to
> return a result of 123.
>
> The end result is 123, if I write code in Java and then in Clojure, I
> want to see the runtimes of the different versions.
>
> On Jul 27, 1:34 pm, Aaron Cohen  wrote:
>
> > One thing you need to do is define what you mean exactly when you say "Java
> > vs Clojure."
> > In your example you are comparing clojure code vs java code but you are also
> > comparing clojure data structures (PersistentMap) with traditional Java data
> > structures (HashMap).  I'm not sure you meant to conflate the two.
>
> > Also, there have been plenty of threads that start off comparing java and
> > clojure performance and eventually end up at near-equivalent performance
> > after using type hints/coercion/etc.  It has become something of a FAQ.  I'd
> > start 
> > with:http://groups.google.com/groups/search?q=group:clojure+performance&qt...
> > <http://groups.google.com/groups/search?q=group:clojure+performance&qt...>
> > -- Aaron
>
> > On Mon, Jul 27, 2009 at 1:06 PM, BerlinBrown  wrote:
>
> > > I was coming up with some performance tests for Clojure, going back
> > > and forth between different JVM languages (JRuby, Scala) and mainly
> > > looking at pure Java code.  So far I have found that clojure is about
> > > 5-10 times as slow as comparable code in Clojure.  Of course this is
> > > before any optimizations.
>
> > > Here is my question, do you have any code both Clojure and Java where
> > > there is a one to one match between code where Clojure runs as fast as
> > > Java.  It could be anything.
>
> > > Here is one example:
> > > This is code from clojure/contrib to convert a list of data into a
> > > frequency count map.  Pretty standard stuff.
>
> > > (defn frequencies
> > >  "Returns a map from distinct items in coll to the number of times
> > >  they appear."
> > >  [coll]
> > >  ;
> > >  (reduce (fn [counts x]
> > >  (assoc counts x (inc (get counts x 0
> > >  {} coll))
>
> > >  (dotimes [x 4]
> > >  (println "i: " (int (Math/pow 10.0 x)))
> > >(time
> > > (dotimes [_ (int (Math/pow 10.0 x))]
> > > (let [a (for [_ (range 1000)] (random-string 3))]
> > >   (frequencies a)
>
> > > --
>
> > >public static Map frequencies(final List list) {
> > >final Map map = new HashMap();
> > >// Simple Box and then unbox the count as the value for this
> > > map //
> > >for (Iterator it = list.iterator(); it.hasNext(); ) {
> > >final Object o = it.next();
> > >final String s = o.toString();
> > >Integer prev = (Integer) map.get(s);
> > >if (prev == null) {
> > >// Put a new value on th map
> > >final Integer count = ONE;
> > >map.put(s, count);
> > >} else {
> > >final Integer inc = new Integer(prev.intValue() + 1);
> > >map.put(s, inc);
> > >} // End of the if - else //
> > >}
> > >return map;
> > >}
> > > --
>
> > > Clojure Results (same machine 1.5 JDK)
>
> > > i:  1
> > > "Elapsed time: 51.657859 msecs"
> > > i:  10
> > > "Elapsed time: 212.568221 msecs"
> > > i:  100
> > > "Elapsed time: 1623.107702 msecs"
> > > i:  1000
> > > "Elapsed time: 16356.185166 msecs"
> > > (used:2M/0M [2M,63M ])
> > > Done
> > > Performing simple garbage collection cooldown
> > > (used:2M/0M [2M,63M ])
> > > (used:2M/0M [2M,63M ])
>
> > > -
>
> > > Here are the Java results.
>
> > > 14.6316069 ms
> > > 4.8283429 ms
> 

Re: Clojure performance tests and clojure a little slower than Java

2009-07-27 Thread Berlin Brown

"One thing you need to do is define what you mean exactly when you say
"Java
vs Clojure." "

Like I said, I didn't want to get too focused on this particular
example.  Is there code where I could run in Clojure and where I could
run in Java that would end up with the same result.  And then I could
see the differences in performance.  Also is there an example where
Clojure code is comparable.

For example, lets say the Euler problem number 1 wants you want to
return a result of 123.

The end result is 123, if I write code in Java and then in Clojure, I
want to see the runtimes of the different versions.

On Jul 27, 1:34 pm, Aaron Cohen  wrote:
> One thing you need to do is define what you mean exactly when you say "Java
> vs Clojure."
> In your example you are comparing clojure code vs java code but you are also
> comparing clojure data structures (PersistentMap) with traditional Java data
> structures (HashMap).  I'm not sure you meant to conflate the two.
>
> Also, there have been plenty of threads that start off comparing java and
> clojure performance and eventually end up at near-equivalent performance
> after using type hints/coercion/etc.  It has become something of a FAQ.  I'd
> start 
> with:http://groups.google.com/groups/search?q=group:clojure+performance&qt...
> 
> -- Aaron
>
> On Mon, Jul 27, 2009 at 1:06 PM, BerlinBrown  wrote:
>
> > I was coming up with some performance tests for Clojure, going back
> > and forth between different JVM languages (JRuby, Scala) and mainly
> > looking at pure Java code.  So far I have found that clojure is about
> > 5-10 times as slow as comparable code in Clojure.  Of course this is
> > before any optimizations.
>
> > Here is my question, do you have any code both Clojure and Java where
> > there is a one to one match between code where Clojure runs as fast as
> > Java.  It could be anything.
>
> > Here is one example:
> > This is code from clojure/contrib to convert a list of data into a
> > frequency count map.  Pretty standard stuff.
>
> > (defn frequencies
> >  "Returns a map from distinct items in coll to the number of times
> >  they appear."
> >  [coll]
> >  ;
> >  (reduce (fn [counts x]
> >  (assoc counts x (inc (get counts x 0
> >  {} coll))
>
> >  (dotimes [x 4]
> >  (println "i: " (int (Math/pow 10.0 x)))
> >(time
> > (dotimes [_ (int (Math/pow 10.0 x))]
> > (let [a (for [_ (range 1000)] (random-string 3))]
> >   (frequencies a)
>
> > --
>
> >public static Map frequencies(final List list) {
> >final Map map = new HashMap();
> >// Simple Box and then unbox the count as the value for this
> > map //
> >for (Iterator it = list.iterator(); it.hasNext(); ) {
> >final Object o = it.next();
> >final String s = o.toString();
> >Integer prev = (Integer) map.get(s);
> >if (prev == null) {
> >// Put a new value on th map
> >final Integer count = ONE;
> >map.put(s, count);
> >} else {
> >final Integer inc = new Integer(prev.intValue() + 1);
> >map.put(s, inc);
> >} // End of the if - else //
> >}
> >return map;
> >}
> > --
>
> > Clojure Results (same machine 1.5 JDK)
>
> > i:  1
> > "Elapsed time: 51.657859 msecs"
> > i:  10
> > "Elapsed time: 212.568221 msecs"
> > i:  100
> > "Elapsed time: 1623.107702 msecs"
> > i:  1000
> > "Elapsed time: 16356.185166 msecs"
> > (used:2M/0M [2M,63M ])
> > Done
> > Performing simple garbage collection cooldown
> > (used:2M/0M [2M,63M ])
> > (used:2M/0M [2M,63M ])
>
> > -
>
> > Here are the Java results.
>
> > 14.6316069 ms
> > 4.8283429 ms
> > i: 10
> > Elapsed time: 9.803628 msecs
> > i: 100
> > Elapsed time: 97.562451 msecs
> > i: 1000
> > Elapsed time: 972.775771 msecs
> > (used:1M/0M [1M,63M ])
> > (used:1M/0M [1M,63M ])
> > (used:1M/0M [1M,63M ])
>
> > NOTE:!!! This is just one example.  All my other examples, ended up
> > the same way.  I hope you don't nitpick this one.
>
> > I know we should take performance tests with a grain a salt.  But at
> > the same time, I feel we should at least try to measure the speed of
> > some of our code.  I haven't found many speed tests out there on
> > clojure.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: executing tasks on a schedule

2009-06-26 Thread Berlin Brown



On Jun 26, 11:43 am, Stuart Halloway 
wrote:
> I am working on a Clojure project that is becoming more and more
> schedule-oriented. So far I have been using Clojure's native
> concurrency constructs, but I am becoming tempted to use Java's
> concurrency primitives to get interruptability, etc. -- or maybe even
> wrap a Java library like Quartz.
>
> Has anyone else been down this road?
>
> Stu

Yea, I don't know about Clojure libraries, but also see Spring
Batch...which like you mentioned is based on Quartz.
--~--~-~--~~~---~--~~
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 website written using Clojure.

2009-06-25 Thread Berlin Brown



On Jun 25, 3:52 pm, Mike Hinchey  wrote:
> Instead of eval in the doseq, you could use a macro with a do block,
> something like:
> user> (defmacro deftags [tags]
>         `(do ~@(map (fn [tag]
>                       `(defn ~(symbol (str tag "-with"))
>                          [block#] (str ~tag block#)))
>                     tags)))
> #'user/deftags
>
> user> (deftags ["html"])
> #'user/html-with
>
> user> (html-with [1])
> "html[1]"
>
> -Mike
>
> On Thu, Jun 25, 2009 at 11:51 AM, CuppoJava wrote:
>
>
>
> > Thanks for the reply.
>
> > I use doseq instead of map because I need it to run immediately, and
> > I'm not interested in the return values of the functions.
>
> > I also would love to be able to simply the (eval ...) part, but I
> > don't know of any other way to dynamically define a function in
> > Clojure. If you know of a way it'd help me out a lot.
> >   -Patrick

I am not looking at the code, I hate when people nitpick every snippet
they see.  I don't think that gets anyone anywhere.

But does anyone have a problem with Lisp/S-Expressions to HTML/XHtml,
especially for the entire document.  What is wrong with using some
form of templating system.  I think that is what Lisp has (see Lisp's
Html-template).

I am not talking about this particular application, but just in
general.  I love the ability to take sections of HTML or snippets of
HTML and use that as the View and then break that off from the
application code.

But that is just me.
--~--~-~--~~~---~--~~
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: Convincing others about Clojure

2009-06-25 Thread Berlin Brown



On Jun 25, 9:39 am, Berlin Brown  wrote:
> On Jun 25, 9:31 am, Nathan Hawkins  wrote:
>
>
>
> > On Thu, 25 Jun 2009 11:29:24 +0530
>
> > Baishampayan Ghose  wrote:
>
> > > Their concerns are thus:
>
> > > 1. How do you get Clojure programmers? Lisp is not for the faint
> > > hearted.
>
> > You can always ask on this list. I'd guess that at any given point
> > in time there are probably several people who'd rather being
> > working with Clojure in their day job than whatever they're actually
> > doing now. (Me, for instance...)
>
> > > 2. What about the performance of Clojure? Is it fast?
>
> > It can be faster than a lot of other popular choices, like Ruby or
> > Python. I wish it compiled to native code instead of Java, but that's
> > mostly because I don't like Java.
>
> > > 3. People who want to use this are more academically inclined and are
> > > not practical. This will make the whole project fail.
>
> > Many innovative ideas in computer science tend to in academia
> > and only slowly make their way into more mainstream, practical
> > environments.
>
> > Consider garbage collection, or relational databases. Both very
> > "academic" at one time, and now they're everywhere.
>
> > Point being, really practical people use the best ideas they can,
> > regardless of where they came from.
>
> > Nathan
>
> This is how I think of clojure, but first I want you to do some
> experiments.  I assuming you come from a Java/J2EE background:
>
> 1. Get an image of SQL in your mind.
> 2. Now build an image of Javascript and what javascript is used for.
> 3. Now imagine JSPs or ASP, Server Pages.
> 4. Now imagine XML.
> 5. Imagine Bash scripting.
> 6. Imagine what Ruby or Python does for certain people.
> 7. Envision a J2EE or large application that takes advantage of many
> different technologies.
>
> So you have all of these images of different languages and
> technologies.  They are all different tools used to build an
> application for users.
>
> Clojure is a a language that runs on the JVM.  It is as simple or as
> complicated as you make it.  For me, I can treat it as a wrapper over
> my existing code or evolve and use complex functional programming
> techniques.
>
> This is my main point: One thing that Clojure is NOT.  It is not
> limited by the limitations of the Java programming language.
>
> Think about Clojure as another tool that you can use to write better
> code.

I think the hardest part is convincing yourself that you can use one
or more core languages for your project.  I guess we think we only
need C, or Java or C++ and that is it.  But we normally integrate with
other technologies like JSPs anyway.

I have been programming with some JVM language since the early Jython
days and I still find it a little hard to break away completely from
using Java language code.

I want to integrate a Java, Clojure, Scala app but I still haven't
included Scala into the process yet.
--~--~-~--~~~---~--~~
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: Convincing others about Clojure

2009-06-25 Thread Berlin Brown



On Jun 25, 9:31 am, Nathan Hawkins  wrote:
> On Thu, 25 Jun 2009 11:29:24 +0530
>
> Baishampayan Ghose  wrote:
>
> > Their concerns are thus:
>
> > 1. How do you get Clojure programmers? Lisp is not for the faint
> > hearted.
>
> You can always ask on this list. I'd guess that at any given point
> in time there are probably several people who'd rather being
> working with Clojure in their day job than whatever they're actually
> doing now. (Me, for instance...)
>
> > 2. What about the performance of Clojure? Is it fast?
>
> It can be faster than a lot of other popular choices, like Ruby or
> Python. I wish it compiled to native code instead of Java, but that's
> mostly because I don't like Java.
>
> > 3. People who want to use this are more academically inclined and are
> > not practical. This will make the whole project fail.
>
> Many innovative ideas in computer science tend to in academia
> and only slowly make their way into more mainstream, practical
> environments.
>
> Consider garbage collection, or relational databases. Both very
> "academic" at one time, and now they're everywhere.
>
> Point being, really practical people use the best ideas they can,
> regardless of where they came from.
>
> Nathan

This is how I think of clojure, but first I want you to do some
experiments.  I assuming you come from a Java/J2EE background:

1. Get an image of SQL in your mind.
2. Now build an image of Javascript and what javascript is used for.
3. Now imagine JSPs or ASP, Server Pages.
4. Now imagine XML.
5. Imagine Bash scripting.
6. Imagine what Ruby or Python does for certain people.
7. Envision a J2EE or large application that takes advantage of many
different technologies.

So you have all of these images of different languages and
technologies.  They are all different tools used to build an
application for users.

Clojure is a a language that runs on the JVM.  It is as simple or as
complicated as you make it.  For me, I can treat it as a wrapper over
my existing code or evolve and use complex functional programming
techniques.

This is my main point: One thing that Clojure is NOT.  It is not
limited by the limitations of the Java programming language.

Think about Clojure as another tool that you can use to write better
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: Solving memory problems with Clojure code

2009-06-22 Thread Berlin Brown



On Jun 22, 12:32 pm, Marko Kocić  wrote:
> Have you tried (.close stream) in the end of let block?
>
> On 22 јун, 16:10, BerlinBrown  wrote:
>
> > I want to make it clear, that it probably isn't Clojure's memory
> > problem but something with my code.
>
> > Anyway, I was trying to figure out my heap memory goes up so much on
> > various operations in my application.  Sure, it could be anything but
> > I know I am doing something wrong.
>
> > Here is the application, a text editor in SWT.  When I open files, the
> > heap memory goes up 10 times the size of the file.  So, if I open a
> > 3MB file, that is 30MB of heap memory used.
>
> >http://code.google.com/p/lighttexteditor/
> > 
>
> > There are also some bad designs I am using, still wouldn't explain a
> > 10 fold increase in memory.
>
> >http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojur...
>
> > So far, I have done a couple of things.
>
> > 1. Turned on warn on reflection and reduced some of the reflection
> > calls by adding type hints.
>
> > 2. Tried to reduce the number of calls to deref and not use "global?"
> > defines.
>
> > Here is the code that I think is the worst offender.  Basically, a
> > java oriented approach for opening a file.
>
> > (defn open-file-util [file file-path]
> >   #^{:doc "Use java oriented approach for loading a file into
> > memory" }
> >   ;; Java oriented approach for opening file
> >   (let [stream (new FileInputStream file-path)
> > instr (new LineNumberReader (new InputStreamReader stream))
> > ;; Use type hints to ensure a character type.
> > readBuffer #^"[C" (make-array (. Character TYPE) 2048)
> > buf (new StringBuffer)]
> > (loop [n (. instr read readBuffer)]
> >   (when (> n 0)
> > (. buf append readBuffer 0 n)
> > (recur (. instr read readBuffer
> > ;; File info data has been collected, set some of the file
> > properties
> > (set-file-info (. file getName)
> >(. file getAbsolutePath)
> >(. file lastModified)
> >(. instr getLineNumber)
> >(. file getParent)
> >(. file canWrite)
> >(. file exists)
> >(. file length))
> > (. instr close)
> > (. buf toString)))
>
> >http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojur...
>
> > Here are some notes from my early analysis, also a google doc on the
> > functions that are called.
> > "memory profiling 
> > clojure"http://groups.google.com/group/clojure/browse_thread/thread/b44e25f23...

(. instr close)

I have this, you say use stream close.
--~--~-~--~~~---~--~~
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 in "Computing in Science and Engineering"

2009-06-20 Thread Berlin Brown



On Jun 20, 3:34 am, Konrad Hinsen  wrote:
> On 19.06.2009, at 10:35, Jon Harrop wrote:
>
> > If you really do mean scientific applications in general (e.g.  
> > Mathematica,
> > MATLAB) then I would say that they are definitely almost all  
> > running on
> > multicore desktops and not distributed clusters.
>
> What I really meant is "scientific applications typically written by  
> scientists", and in my experience that is mostly number-crunching  
> stuff, if only because that's all most scientists would care to  
> write. Mathematica and MATLAB are written and maintained by  
> professional programmers.
>
> > Shared-memory parallelism is certainly a major problem in  
> > scientific computing
> > today so I, for one, would love to see parallelized Clojure  
> > solutions to
> > interesting problems (even toys). What sort of basic infrastructure  
> > would you
> > use in Clojure, e.g. equivalent to Microsoft's TPL?
>
> What't TPL?
>
> Konrad.

Pretty cool.  I went to school 10 years ago and Lisp was supposed to
be language of choice for AI but the implementations didn't seem
practical.  I think Clojure brings a lot of useful libraries and
usefulness to the Lisp world.  Maybe we will see the emergence of Lisp
again.
--~--~-~--~~~---~--~~
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: Memory usage in Clojure, hprof

2009-06-20 Thread Berlin Brown



On Jun 19, 4:18 pm, Berlin Brown  wrote:
> On Jun 19, 1:50 pm, Berlin Brown  wrote:
>
>
>
> > On Jun 19, 1:04 pm, Four of Seventeen  wrote:
>
> > > On Jun 19, 10:12 am, BerlinBrown  wrote:
>
> > > > 574 instances of class clojure.lang.DynamicClassLoader
>
> > > That is curious. Ordinarily one only needs one instance of any
> > > particular classloader, not 574 of them. :) Not that I know much about
> > > clojure's internals.
>
> > "clojure.lang.DynamicClassLoader "
>
> > Could be a misnomer.  Not really a classloader in the typical sense.
>
> > I think this is my actual code that gets loaded in memory.
> > "26625 instances of class clojure.lang.PersistentHashMap$LeafNode "
>
> > Next, I think I need some memory performance tips to see where I can
> > reduce memory.
>
> I am sorry to bother you guys with this randomness, but what I am
> looking at is pretty cool.
>
>                 Exits
> Display sleep() 368
> RT      classForName(String)    1030
> Var     deref() 701318
> core__init      load()  1
> core$filter_key__4306   invoke(Object,Object,Object)    196
> core$ns_publics__4334$fn__4336  invoke(Object)  145158
> RT      loadClassForName(String)        44
> PersistentHashMap$BitmapIndexedNode$Seq next()  261388
> PersistentHashMap$BitmapIndexedNode     find(int,Object)        145201
> Var     get()   695863
> PersistentHashMap       entryAt(Object) 139095
> octane_file_utils$open_file_util__552   invoke(Object,Object)   1
> PersistentHashMap$BitmapIndexedNode     assoc(int,int,Object,Object,Box)
> 86140
> PersistentHashMap$BitmapIndexedNode$Seq first() 332152
> PersistentHashMap$BitmapIndexedNode     bitpos(int,int) 247501
> Var     getThreadBinding()      701870
> PersistentHashMap       assoc(Object,Object)    56120
> RT      first(Object)   226620
> RT      next(Object)    178384
> core$refer__4345        doInvoke(Object,Object) 196
> core$flush__4156        invoke()        7
> RT      cons(Object,Object)     174573
> Namespace       findOrCreate(Symbol)    6751
> octane_utils__init      load()  1
> core$val__3614  invoke(Object)  168802
>
> I easily added jrat to profile the method calls.  Here is what I came
> up with.  Here are the clojure classes and how many times they were
> executed.
>
> Here is jrat.
>
> http://jrat.sourceforge.net/

OK, here is another thing I was looking at, number of calls.

The application is mostly geared around this code:

http://code.google.com/p/lighttexteditor/

http://spreadsheets.google.com/pub?key=rNB3pttScIyEdLM_kp2rejg&gid=4

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



Re: What are people using Clojure for?

2009-06-19 Thread Berlin Brown



On Jun 18, 12:39 pm, Howard Lewis Ship  wrote:
> I've been doing a number of presentations on Clojure lately (TheServerSide,
> Portland Code Camp, Open Source Bridge), and I'm getting some interest in
> Clojure and functional programming.
>
> A question that keeps coming up is: where would you use Clojure and/or
> functional?
>
> I've had to cite Rich's background in audio processing and national election
> polls.
>
> I think a slide showing different things people used Clojure for would be a
> nice addition.
>
> Personally, I don't have a specific use for Clojure yet, but I am having fun
> learning it by creating a simple web framework.
>
> BTW, trying to explain Clojure, Lisp syntax, functional programming and
> Clojure concurrency in 45 minutes is somewhat exasperating!
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
> Director of Open Source Technology at Formos

Mostly GUI/SWT development, it is one of those.  Why can't I use
Clojure for everything.

As the creator of Tapestry, I am curious on your thoughts for use of
Clojure with other frameworks.  I am more on the side of lets use
existing frameworks like Tapestry or Wicket, Spring and use Clojure
alongside those existing tools as opposed to starting from scratch.
--~--~-~--~~~---~--~~
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: Memory usage in Clojure, hprof

2009-06-19 Thread Berlin Brown



On Jun 19, 1:50 pm, Berlin Brown  wrote:
> On Jun 19, 1:04 pm, Four of Seventeen  wrote:
>
> > On Jun 19, 10:12 am, BerlinBrown  wrote:
>
> > > 574 instances of class clojure.lang.DynamicClassLoader
>
> > That is curious. Ordinarily one only needs one instance of any
> > particular classloader, not 574 of them. :) Not that I know much about
> > clojure's internals.
>
> "clojure.lang.DynamicClassLoader "
>
> Could be a misnomer.  Not really a classloader in the typical sense.
>
> I think this is my actual code that gets loaded in memory.
> "26625 instances of class clojure.lang.PersistentHashMap$LeafNode "
>
> Next, I think I need some memory performance tips to see where I can
> reduce memory.

I am sorry to bother you guys with this randomness, but what I am
looking at is pretty cool.

Exits
Display sleep() 368
RT  classForName(String)1030
Var deref() 701318
core__init  load()  1
core$filter_key__4306   invoke(Object,Object,Object)196
core$ns_publics__4334$fn__4336  invoke(Object)  145158
RT  loadClassForName(String)44
PersistentHashMap$BitmapIndexedNode$Seq next()  261388
PersistentHashMap$BitmapIndexedNode find(int,Object)145201
Var get()   695863
PersistentHashMap   entryAt(Object) 139095
octane_file_utils$open_file_util__552   invoke(Object,Object)   1
PersistentHashMap$BitmapIndexedNode assoc(int,int,Object,Object,Box)
86140
PersistentHashMap$BitmapIndexedNode$Seq first() 332152
PersistentHashMap$BitmapIndexedNode bitpos(int,int) 247501
Var getThreadBinding()  701870
PersistentHashMap   assoc(Object,Object)56120
RT  first(Object)   226620
RT  next(Object)178384
core$refer__4345doInvoke(Object,Object) 196
core$flush__4156invoke()7
RT  cons(Object,Object) 174573
Namespace   findOrCreate(Symbol)6751
octane_utils__init  load()  1
core$val__3614  invoke(Object)  168802


I easily added jrat to profile the method calls.  Here is what I came
up with.  Here are the clojure classes and how many times they were
executed.

Here is jrat.

http://jrat.sourceforge.net/
--~--~-~--~~~---~--~~
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: Memory usage in Clojure, hprof

2009-06-19 Thread Berlin Brown



On Jun 19, 1:04 pm, Four of Seventeen  wrote:
> On Jun 19, 10:12 am, BerlinBrown  wrote:
>
> > 574 instances of class clojure.lang.DynamicClassLoader
>
> That is curious. Ordinarily one only needs one instance of any
> particular classloader, not 574 of them. :) Not that I know much about
> clojure's internals.

"clojure.lang.DynamicClassLoader "

Could be a misnomer.  Not really a classloader in the typical sense.

I think this is my actual code that gets loaded in memory.
"26625 instances of class clojure.lang.PersistentHashMap$LeafNode "

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



Re: Lazy load of imports

2009-06-13 Thread Berlin Brown



On Jun 12, 10:31 am, Chouser  wrote:
> On Thu, Jun 11, 2009 at 8:48 PM, Stephen C. Gilardi wrote:
>
> > > Do you think there will be any performance hits.
>
> > I haven't run any tools on it. In looking around the reflection-related code
> > in clojure.lang, it looks to me like the performance of new-by-name should
> > be similar to that of other Clojure code that uses reflection rather than
> > direct calls.
>
> I think that's correct.  In my experience a call that
> requires runtime reflection like this is on the order of 50
> times slower than a method call that is made directly.
> Depending on how often it gets called, I think that would
> generally count as a "performance hit".
>
> Another option you could consider: moving all code that
> requires that class into a separate .clj file, then using
> 'load' when you need it.  This would allow you to AOT
> compile (or not) and suffer none of the runtime reflection
> cost.
>
> Yet another option would be to eval a constructor function.
> Something like:
>
> (defn make-foo [arg1 arg2]
>   (eval `(defn ~'make-foo [a1# a2#] (Foo. a1# a2#)))
>   (make-foo arg1 arg2))
>
> Note that's not well tested.  I'm not sure, but you may have
> trouble elsewhere if you try to type-hint Foo.  But
> basically, that defines a make-foo such that the first time
> it's called it compiles a new make-foo that will actually
> create instances of Foo.  This will be slow, but subsequent
> calls to make-foo should run at full compiled speed.
>
> Both those options may be pretty painful depending on what
> you're actually doing, so if I were you I'd try new-by-name
> first and only if you're sure it's too slow would I try
> another option.
>
> --Chouser

If I do the dynamic call to "load", and in my clojure script I have a
namespace defined.  Load will still work and I will be able to
reference that namespace later?
--~--~-~--~~~---~--~~
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: Lazy load of imports

2009-06-11 Thread Berlin Brown



On Jun 11, 6:51 pm, "Stephen C. Gilardi"  wrote:
> On Jun 11, 2009, at 2:30 PM, BerlinBrown wrote:
>
> > I have a Clojure applications with different files, different
> > namespaces and I have imports of classes within those files/
> > namespaces.
>
> I don't think the following is exactly what you're asking for, but you  
> can use "clojure.contrib.core/new-by-name" to do something like what  
> you described.
>
> Here's an example from clojure.contrib.miglayout.internal:
>
> (def MigLayout "net.miginfocom.swing.MigLayout")
>
> [...]
>
>      (.setLayout (new-by-name MigLayout layout column row))
>
> [...]
>
> Using this technique I was able to change clojure.contrib.miglayout's  
> dependence on the miglayout jar from compile time to runtime.
>
> --Steve
>
>  smime.p7s
> 3KViewDownload

Now, that is close, not entirely but close enough.

Do you think there will be any performance hits.
--~--~-~--~~~---~--~~
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: Simple idiom in clojure, mutate a value

2009-06-11 Thread Berlin Brown



On Jun 11, 3:42 pm, Chouser  wrote:
> On Thu, Jun 11, 2009 at 3:03 PM, Adrian
>
>
>
> Cuthbertson wrote:
>
> > Here's a fuller example of similar techniques extracted from a working
> > program. It reads a file of lines and applies some transformations and
> > accumulates a vector of records which it finally returns;
>
> > (defn some-fn
> >  "Read a file and return a vector of its records."
> >  [fpath]
> >  (let
> >    [r (BufferedReader. (FileReader. (File. fpath)))]
> >    (try
> >      (let [line (.readLine r)] ; discard line 1
> >        (loop [line (.readLine r) recs []]
> >          (if-not line recs
> >            (let [rec (do-something-with line)
> >                  newrecs (conj recs rec)]
> >              (recur (.readLine r) newrec)
> >      (finally
> >        (.close r)
>
> To test this I'm using:
>
> (import '(java.io File FileReader BufferedReader))
> (defn do-something-with [line] (.toUpperCase line))
>
> Note that (let [r ...] (try ... (finally (.close r is
> already packaged up in the with-open macro:
>
> (defn some-fn
>   "Read a file and return a vector of its records."
>   [fpath]
>   (with-open [r (BufferedReader. (FileReader. (File. fpath)))]
>     (.readLine r) ; discard line 1
>     (loop [line (.readLine r) recs []]
>       (if-not line
>         recs
>         (let [rec (do-something-with line)
>               newrecs (conj recs rec)]
>           (recur (.readLine r) newrecs))
>
> Also note that this is a great candidate for line-seq:
>
> (defn some-fn
>   "Read a file and return a vector of its records."
>   [fpath]
>   (with-open [r (BufferedReader. (FileReader. (File. fpath)))]
>     (vec (map do-something-with
>               (next               ; discard first line
>                 (line-seq r))
>
> --Chouser

Yea, I think conj was what I was looking for.
--~--~-~--~~~---~--~~
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: Simple idiom in clojure, mutate a value

2009-06-11 Thread Berlin Brown



On Jun 11, 12:16 pm, Daniel Lyons  wrote:
> On Jun 11, 2009, at 9:25 AM, BerlinBrown wrote:
>
>
>
> > I do this a lot but can't figure out to change the UPDATEABLE_VALUE, I
> > am using some pseudo code because I don't have a clojure solution yet.
>
> > SET UPDATEABLE_VALUE = 0
> > (loop [line (.readLine reader)]
> >  (if (or (empty? line) (> line-num max-num))
> >   SET UPDATEABLE_VALUE = UPDATEABLE_VALUE + (SOME_FUNC)
> >(recur (.readLine reader
>
> In general it's going to be something like this:
>
> (loop [line (.readLine reader) UPDATEABLE_VALUE 0]
>   (if (or (empty? line) (> line-num max-num))
> (recur (.readLine reader) (+ UPDATEABLE_VALUE (SOME_FUNC)
>
> Whenever you would have modified a local variable before, in FP you
> establish a new binding instead.
>
> —
> Daniel Lyonshttp://www.storytotell.org-- Tell It!

I can modify the value within the loop, but what is a good approach
for accessing the value outside of the loop.  For example (pseudo code
with a mix of procedural logic).

;; Init updateable value outside of 'loop'
SET UPDATEABLE_VALUE = 0
 (loop [line (.readLine reader)]
  (if (or (empty? line) (> line-num max-num))
   SET UPDATEABLE_VALUE = UPDATEABLE_VALUE + (SOME_FUNC)
(recur (.readLine reader
;; Now outside of the loop, use UPDATEABLE_VALUE with the mutated
value
(println UPDATEABLE_VALUE)



--~--~-~--~~~---~--~~
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: Every function is a thread in Clojure?

2009-04-03 Thread Berlin Brown



On Apr 3, 10:09 am, Stuart Halloway  wrote:
> No threads:
>
> (ancestors (class (fn[])))
> -> #{java.lang.Runnable java.io.Serializable clojure.lang.AFn
> clojure.lang.Obj java.lang.Object clojure.lang.Fn
> clojure.lang.AFunction clojure.lang.IObj clojure.lang.IFn
> java.util.concurrent.Callable clojure.lang.IMeta java.util.Comparator}
>
> What you are referring to is the fact that functions implement
> Callable and Runnable, so that they can trivially play nice with Java
> threads if you need them to.
>
> Stu
>
> > Someone correct me if I go wrong here.  But, from my understanding,
> > every defined function in Clojure is an implementation of a thread?
>
> > What is the goal in implementing in this fashion?  For example, if I
> > am writing in imperative style:
>
> > (println "First line")
> > (println "Second line")
> > (println "Third line")
>
> > ...
>
> > The operations have to occur synchronously.  What does adding Java
> > threading add to the mix?

oh OK, sorry about.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Ironicly Maven2 is the lightest I could come up with

2009-04-03 Thread Berlin Brown



On Apr 3, 8:18 am, Jason Warner  wrote:
> I'd be interested in seeing the ivy+ant solution. We use maven2 at
> work and there are obvious pros and cons. With clojure, part of the
> pain is initial setup and config. Maven2/ant+ivy might really help
> that. Post when you get a chance...am very interested.
>
> Thanks,
> jason
>
> On Apr 2, 8:56 pm, dysinger  wrote:
>
> > Maven2 is atrocious for big Java projects.  Lots of people have had
> > the same experience you mentioned. In fact the first few lines of the
> > readme on my clojure pom project on github says "Dont run away with
> > your hair on fire" :) Give it a try. It is really simple.
>
> > I think I'll give Ant + Ivy another run tonight.  I truly am after the
> > best KISS dependency/package management solution  and not trying to
> > push maven.
>
> > On Apr 2, 3:10 pm, Korny Sietsma  wrote:
>
> > > On Fri, Apr 3, 2009 at 4:39 AM, dysinger  wrote:
> > > > The Java world for good or bad has rallied
> > > > around maven repos.  There are 10s of thousands of libs "up in there".
>
> > > While there are lots of Java / Maven users, there are also a lot who 
> > > *don't*
> > > use it, and indeed many who actively avoid stuff that is locked in to 
> > > Maven
> > > and it's associated complexity.  It's popular, yes, but I'd debate that 
> > > the
> > > Java world has "rallied around" maven...
>
> > > My workplace (200-ish developers) is mostly Java based, and we used to use
> > > Maven 1 for a few core projects, went through some pain trying to move 
> > > them
> > > to Maven 2, gave up, and have been quite happy since then working with Ivy
> > > and Ant.
>
> > > I'm sure maven has a lot of benefits in many workplaces, and I'm sure it's
> > > more stable and reliable than it was when Maven 2 was brand new :-}  But
> > > personally, I still get post-traumatic flashbacks whenever I see the words
> > > "simple" and "maven" in the same sentence :)
>
> > > - Korny
>
> > > --
> > > Kornelis Sietsma  korny at my surname dot com
> > > "Every jumbled pile of person has a thinking part
> > > that wonders what the part that isn't thinking
> > > isn't thinking of"

I cringe and throw up a little inside everytime I hear maven.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Request for improved error reporting

2009-04-01 Thread Berlin Brown



On Apr 1, 3:23 pm, Vincent Foley  wrote:
> I have no experience with gradual typing, but I'd love to try it.  It
> seems there are many situations where dynamic typing just makes things
> easier than in a language like Haskell, however I long for their
> ability to verify correctness at compile time.
>
> Vince
>
> On Mar 29, 10:49 am, André Thieme  wrote:
>
> > On 29 Mrz., 01:55, Glen Stampoultzis  wrote:
>
> > > Hi, I've been really enjoying getting to know clojure.  It's an awesome
> > > language that has got me very interested in learning more. One thing that
> > > hasn't left me impressed is the error reporting.
> > > [...]
> > > There are a few things wrong here and with clojure error reporting in
> > > general:
>
> > > 1. I'm not getting a line number for some reason.
> > > 2. I don't get any indication what the nature of the error is.
> > > 3. I get a big (nested) stack trace that has more to do with clojure
> > > compiler internals than my program.
>
> > I would like to make a comment that does not directly talk
> > about your specific issue, but about error reporting in
> > general.
> > I would love to hear more opinions about Gradual Typing for
> > Clojure. That would allow the compiler to catch errors before
> > the program is actually run. Your example that you gave at some
> > other point in this thread could have been caught during
> > compilation.
> > Please have a look at this 
> > thread:http://groups.google.com/group/clojure/browse_thread/thread/7a48f48e4...

I have seen that NullPointer before, especially when you use a proxy
and don't have the import of the class defined.  But on error
reporting.  Clojure is the best 'new' language I have seen that has
good error reporting.  It has really increased my productivity. For
example, if there is an error at a line of clojure code, I can go to
it (OK except for that particular one), that seems like a bug.  But
the majority of the time when I have a code error on my end, I kind of
easily navigate to it.

Can you say that in the common lisp world?   I laugh at the premise.

Good job on the error reporting in my opinion.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Scala vs Clojure

2009-03-31 Thread Berlin Brown



On Mar 31, 4:52 pm, Luc Prefontaine 
wrote:
> I was searching for a Java alternative for our medical bus product and
> looked at Scala during summer 2008.
> I found it was too tied to an object model. The lack of a complete macro
> system was in my view also a short coming.
>
> I concluded that it was not a significant departure from Java. I really
> wanted an alternative
> that shortened the project time line while providing future growth and a
> better concurrency model.
>
> Looked also at Erlang for better concurrency but found it was too
> "foreign" to the Java world
> and that we would end up coding a lot more.
>
> I then looked at Lisp alternatives running on the JVM and I stepped on
> Clojure while searching.
>
> We now start all our projects using Clojure and thunk down to
> Spring/Java when needed.
>
> It's a hell of a combination up to now :)))
>
> In terms of maturity age is not the significant factor. The more complex
> is the core
> of your new language, the bigger it is, the harder it it to get it out
> and stabilize it.
> Clojure has a small footprint/syntax, is extensible easily and can use
> the existing Java library base
> transparently.
>
> Stability wise, Clojure has been conceived by one guy, Rich.
> There is nothing more painful than developing by consensus. Endless
> discussions,
> addition bits by bits of new concepts, twisted solutions, 
>
> I believe that a single person should lead the way. Listening to other
> ideas is fine
> and integrating the best of them is the way to go but the final
> decisions have to rest in a single pair of hands
> otherwise the product becomes chaotic and points in every directions.
>
> Luc
>
>
>
> On Tue, 2009-03-31 at 17:44 +0200, Christian Vest Hansen wrote:
> > On Tue, Mar 31, 2009 at 5:20 PM, Chas Emerick  wrote:
>
> > > We shipped production software built in Scala last year, but likely
> > > will never do so again given clojure.  Our primary motivating factor
> > > is the degree of complexity in the Scala, but since you're looking for
> > > "auxiliary" factors:
>
> > > - clojure has a far richer "ecosystem" -- there's a metric ton of
> > > community-contributed libraries and lots of people moving in very
> > > interesting directions.  Maybe I missed them, or they've sprung up
> > > since I moved over to clojure last summer, but I've not seen a lot of
> > > scala libraries floating around.
>
> > > - clojure's community is, in general, more friendly, more helpful.
> > > There are certainly lots of pleasant people in the scala world, too,
> > > but I've yet to see a pissing match in #clojure, whereas #scala has
> > > had a number of them (despite the former being more heavily
> > > populated).  I attribute this to the attitudes, demeanor, and near-
> > > constant presence of Rich and other "core" contributors.
>
> > I find myself caught by surprise by these observations, as Scala has
> > been covered in the media for a longer period of time.
>
> > I don't know about the availability of 3'rd party libraries, but the
> > IRC numbers, as of right now, is certainly correct.
>
> > It could be taken to indicate that Clojure has a greater momentum than 
> > Scala.
>
> > > - The tooling story is roughly equivalent, I think.  Neither community
> > > has a home-run effort, but both have lots of promising contenders for
> > > various IDEs.
>
> > > All of the above is obviously, gratuitously IMHO.
>
> > > - Chas
>
> > > On Mar 27, 2009, at 4:20 PM, Jon Harrop wrote:
>
> > >> Can anyone who has tried both of these languages to a decent degree
> > >> compare
> > >> them in practical terms? In other words, I am not interested in the
> > >> technical
> > >> aspects of the languages themselves (e.g. dynamic vs static typing)
> > >> but
> > >> things like IDE support, tools (lexers and parsers), standard
> > >> libraries,
> > >> books and their quality, existing commercial applications and the
> > >> commercial
> > >> viability of shipping products targeted at their programmers (e.g.
> > >> libraries)?
>
> > >> I've never done anything significant on the JVM so I'm interested in
> > >> picking
> > >> one of these two languages and shipping a product for it. I've done
> > >> a lot of
> > >> commercial work with F# over the past 2 years but all Microsoft-
> > >> related sales
> > >> have died this year so I'm looking to diversify...
>
> > >> Many thanks,
> > >> --
> > >> Dr Jon Harrop, Flying Frog Consultancy Ltd.
> > >>http://www.ffconsultancy.com/?e
>
> Luc Préfontaine
>
> Armageddon was yesterday, today we have a real problem...

I have used both and used Clojure way more.  So my knowledge of Scala
is lacking.  When I look at both of them, these are the things that
come to mind.  (Note: I could be completely off).

1. Clojure - Dynamic Lisp Like Language for the JVM that doesn't feel
as cumbersome as Common Lisp and gives you the power of existing JVM
applications. Quickly allows you to get practical work done.

2. Scala - Rigid Static/Strong typed language 

Re: Running multiple scripts from the Java realm

2009-03-25 Thread Berlin Brown



On Mar 25, 3:16 am, Berlin Brown  wrote:
> On Mar 25, 3:12 am, BerlinBrown  wrote:
>
>
>
> > I know it isn't advised but I have my various reasons.
>
> > What are some of the best ways to invoke clojure scripts from Java but
> > still maintain the state of the current session.
>
> > For example, if I run a script from Java, is there a way to ensure
> > that script has already been run...say if I run another script.
> > I was doing the following.
>
> > --
>
> > package test.toolkit.clojure;
>
> > import clojure.lang.Namespace;
> > import clojure.lang.RT;
> > import clojure.lang.Symbol;
> > import clojure.lang.Var;
>
> > public class TestSpringLoadClojure  {
>
> >         final static private Symbol CLOJURE_MAIN = Symbol.create
> > ("clojure.main");
> >         final static private Namespace CLOJURE_MAIN_NS =
> > Namespace.findOrCreate(CLOJURE_MAIN);
> >         final static private Var REQUIRE = Var.intern(RT.CLOJURE_NS,
> > Symbol.create("require"));
> >         final static private Var LEGACY_REPL = Var.intern(CLOJURE_MAIN_NS,
> > Symbol.create("legacy-repl"));
> >         final static private Var LEGACY_SCRIPT = Var.intern(CLOJURE_MAIN_NS,
> > Symbol.create("legacy-script"));
> >         final static private Var MAIN = Var.intern(CLOJURE_MAIN_NS,
> > Symbol.create("main"));
>
> >         private static void legacy_script(String[] args) throws Exception {
> >                 REQUIRE.invoke(CLOJURE_MAIN);
> >                 LEGACY_SCRIPT.invoke(RT.seq(args));
> >         }
>
> >         private static void invoke_script(String[] args) throws Exception {
> >                 LEGACY_SCRIPT.invoke(RT.seq(args));
> >         }
>
> >         public static void main(final String [] args) throws Exception {
>
> >                 final String [] scripts  = {  };
> >                 final String [] scripts2 = { "clj/utils/test_use_utils.clj" 
> > };
> >                 legacy_script(scripts);
> >                 Var.intern(Namespace.findOrCreate(Symbol.create("clojure")),
> > Symbol.create("*console*"), "abc");
> >                 invoke_script(scripts2);
>
> >         }
>
> > }
>
> > But I get an error message:
>
> >      [java] java.lang.Exception: Unable to resolve symbol: *console*
> > in this context (test_use_utils.clj:45)
> >      [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute
> > (ExecuteJava.java:194)
>
> Nevermind.
>
> (println "-->" clojure/*console*)
>
> if I do this, I get it


Anyone?  Use the Java clojure code directly at all, ever?
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Running multiple scripts from the Java realm

2009-03-25 Thread Berlin Brown



On Mar 25, 3:12 am, BerlinBrown  wrote:
> I know it isn't advised but I have my various reasons.
>
> What are some of the best ways to invoke clojure scripts from Java but
> still maintain the state of the current session.
>
> For example, if I run a script from Java, is there a way to ensure
> that script has already been run...say if I run another script.
> I was doing the following.
>
> --
>
> package test.toolkit.clojure;
>
> import clojure.lang.Namespace;
> import clojure.lang.RT;
> import clojure.lang.Symbol;
> import clojure.lang.Var;
>
> public class TestSpringLoadClojure  {
>
>         final static private Symbol CLOJURE_MAIN = Symbol.create
> ("clojure.main");
>         final static private Namespace CLOJURE_MAIN_NS =
> Namespace.findOrCreate(CLOJURE_MAIN);
>         final static private Var REQUIRE = Var.intern(RT.CLOJURE_NS,
> Symbol.create("require"));
>         final static private Var LEGACY_REPL = Var.intern(CLOJURE_MAIN_NS,
> Symbol.create("legacy-repl"));
>         final static private Var LEGACY_SCRIPT = Var.intern(CLOJURE_MAIN_NS,
> Symbol.create("legacy-script"));
>         final static private Var MAIN = Var.intern(CLOJURE_MAIN_NS,
> Symbol.create("main"));
>
>         private static void legacy_script(String[] args) throws Exception {
>                 REQUIRE.invoke(CLOJURE_MAIN);
>                 LEGACY_SCRIPT.invoke(RT.seq(args));
>         }
>
>         private static void invoke_script(String[] args) throws Exception {
>                 LEGACY_SCRIPT.invoke(RT.seq(args));
>         }
>
>         public static void main(final String [] args) throws Exception {
>
>                 final String [] scripts  = {  };
>                 final String [] scripts2 = { "clj/utils/test_use_utils.clj" };
>                 legacy_script(scripts);
>                 Var.intern(Namespace.findOrCreate(Symbol.create("clojure")),
> Symbol.create("*console*"), "abc");
>                 invoke_script(scripts2);
>
>         }
>
> }
>
> But I get an error message:
>
>      [java] java.lang.Exception: Unable to resolve symbol: *console*
> in this context (test_use_utils.clj:45)
>      [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute
> (ExecuteJava.java:194)

Nevermind.

(println "-->" clojure/*console*)

if I do this, I get 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
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 release 20090320

2009-03-20 Thread Berlin Brown



On Mar 20, 10:15 am, Rich Hickey  wrote:
> New release 20090320 -http://clojure.googlecode.com/files/clojure_20090320.zip
>
> Incorporates all the recent additions - fully lazy seqs, :let option
> for doseq/for, letfn for mutually recursive local fns, synchronous
> watches, multi-arg set/union/difference/intersection, counted?, per-
> defmulti hierarchies, #_ ignore form reader macro, future-calls,
> future and pcalls/pvalues, defmulti docstrings and metadata, methods/
> prefers for multimethod reflection, uniform metadata handling for
> atoms/refs/agents/vars/namespaces, condp, release-pending-sends, AOT
> tweaks to support applets and Android, etc. All this in addition to
> many fixes and enhancements.
>
> The API docs page is now current - changes to the rest of the site
> will come soon.
>
> This release includes many patches from contributors, and input and
> reports from many users - thanks all!
>
> Rich

Thanks and this is great.  I haven't look at the change log, but do
you see that we will have to update major parts of our code with this
release from the previous release.  Are many functions removed or have
name changes.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Web Framework, what I want to add

2009-03-16 Thread Berlin Brown



On Mar 16, 10:42 pm, Shawn Hoover  wrote:
> On Mon, Mar 16, 2009 at 9:18 PM, Stuart Sierra
> wrote:
>
>
>
>
>
> > On Mar 16, 7:17 pm, BerlinBrown  wrote:
> > > After many years (decade) of web development, here are the things that
> > > I want in a framework, mostly based in clojure:
>
> > > What do you think and what you add.  This is ambitious and just a
> > > "ideas" of what I would add.  What would you want from your ideal
> > > framework?
>
> > Nothing much to add, but I'm doing well with a combination of Restlet,
> > StringTemplate, Derby, and Solr.
>
> > After a couple of years with Rails, I felt that I wanted to work
> > "closer to the metal", with the metal, in this case, being HTTP.
> > Javascript/CSS-generation was more trouble than it was worth.
>
> > -Stuart Sierra
>
> Stuart, thanks for mentioning your stack. I've played with StringTemplate
> from Clojure, but I hadn't seen it in use in a project before. Your
> implementation is great, and at 88 lines of mainly imports and tests it's a
> great example of using Java (and clojure-contrib). Stringify the keys and
> away you go!
>
> Shawn

Nothing much to add, but I'm doing well with a combination of Restlet,
StringTemplate, Derby, and Solr.

Derby and Solr are both good.

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Web Framework, what I want to add

2009-03-16 Thread Berlin Brown



On Mar 16, 7:52 pm, Jeffrey Straszheim 
wrote:
> I'd love to see something built around very-high scalability, using NIO and
> thread pools and such.
>
> On Mon, Mar 16, 2009 at 7:40 PM, Sean  wrote:
>
> > I'm not sure if some of the design inputs make sense, specifically
> > Spring and Hibernate.
>
> > Point 1 - I've found the strength of Spring to be making up for the
> > weaknesses of Java.  Once you have first class functions, macros, and
> > multi-methods (to name a few), Spring doesn't bring much to the table
> > any more.  Add in a few Unix utilities like cron and others, you
> > remove the rest of the features.
>
> > Point 2 - As for Hibernate, ORM doesn't make much sense with a
> > functional language either.  The SQL library in clojure-contrib lets
> > you load a map, and you can create way more interesting queries with
> > clojure than hibernate.  S-expressions are that powerful.
>
> > Point 3 - I'd follow Rails example and use strong defaults, and resort
> > to XML only when necessary.
>
> > Point 4 - Sounds good.
>
> > Point 5 - Have you looked into compojure?  It does a really good job
> > of turning s-expressions into HTML.
>
> > Point 5 (the second one) - See compojure again.
>
> > Point 6 & 7 - This is where a lot of work is to be done.  I'm not sure
> > how to respond right now.  I'll think about it.
>
> > Point 8 - This is why clojure is awesome.  I'll leave this as an
> > exercise to the user :)
>
> > Point 9 - Yeah, this would be a great feature.
>
> > That's my thoughts.
>
> > On Mar 16, 7:17 pm, BerlinBrown  wrote:
> > > After many years (decade) of web development, here are the things that
> > > I want in a framework, mostly based in clojure:
>
> > > What do you think and what you add.  This is ambitious and just a
> > > "ideas" of what I would add.  What would you want from your ideal
> > > framework?
>
> > > 1. Based on Spring Framework for middleware:
> > > Reason: there are years and years and years of development spent on
> > > spring and there are many things done right.  If I were integrating
> > > with any other third party libraries, I would use spring.  Spring is
> > > added to my framework.
>
> > > 2. Based on Hibernate for ORM mapping:
> > > Reason: the defacto standard for ORM mapping with Java.  And also used
> > > by NHibernate.  There is a lot of support for most popular databases.
>
> > > 3. Clojure/Lisp based configuration AND default XML configurations.
> > > This has become the standard way to configure a J2EE web application
> > > including spring and hibernate.  But I would like a lisp oriented
> > > configuration.
>
> > > 4. Easy mapping to URLs.  I like python's approach for URL mapping
>
> > > 5. Clojure based, framework based server pages AND JSPs.  I have
> > > always hated some aspects of JSP and ASPs, etc, etc.  They are just
> > > too complicated.  I would want to use Clojure code within the
> > > framework oriented server page and other predefined tags.
>
> > > 5. Lift like reusable server pages.  Lift has an interesting approach
> > > for resuing the same page.  E.g. you have an if-else statement within
> > > the page.
>
> > > If request == GET
> > > ...render this
> > > if request == POST
> > >  ...render this.
> > > if URL == 'abc.html'
> > >  .. render this.
>
> > > I want to embed this in my framework.  You only touch one page, but
> > > you get different outputs depending on the request method or URL, etc,
> > > etc.
>
> > > 6. Use of Clojure syntactic sugar -- TO BE DETERMINED.   There is the
> > > ability to use powerful Clojure constructs  with this framework but I
> > > haven't figured out how yet.
>
> > > 7. Better integration of CSS, Javascript, HTML.   A lot of a web
> > > application still resides with the client side.   I have yet to see an
> > > web framework that addresses client development (besides GWT).   Maybe
> > > something as simple as server page tags for CSS?  Javascript?
>
> > > 8.  Additional third party libraries:
>
> > > Lucene, iText, jFreeChart, optional Terracotta integration
> > > 
>
> > > Other optional/additional thoughts.
>
> > > 9. Clear separation between back-end and front-end layers
"Point 1 - I've found the strength of Spring to be making up for the
weaknesses of Java.  Once you have first class functions, macros, and
multi-methods (to name a few), Spring doesn't bring much to the table
any more.  Add in a few Unix utilities like cron and others, you
remove the rest of the features."

Assuming a person is able to re-engineer what Spring has already done
including the simplistic dependency injection oriented web framework.
For me, I just to hate to ignore all that work has been done as well
as making it easier for integrating 'this' framework with pre-existing
code.

"Point 2 - As for Hibernate, ORM doesn't make much sense with a
functional language either.  The SQL library in clojure-contrib lets
you load a map, and you can create way more interesting queries with
clojure than hibernate.  S-e

Re: First Clojure Application, Light Text Editor in Clojure/SWT

2009-03-09 Thread Berlin Brown



On Mar 5, 6:29 pm, BerlinBrown  wrote:
> http://code.google.com/p/lighttexteditor/
>
> * Simpletexteditor.
> * Simple File Manager for accessing important files quickly.
> * Search tools using Linux or Win32 applications (unxutils).
> * Built on Java 1.5 and the Clojure programming language.
>
> It is a simpletexteditorand one critical feature is missing, can't
> save files.  I am working on that, should be available by the weekend.

OK, I update the docs some more, added more features to Light.

http://code.google.com/p/lighttexteditor/

* Simple light-weight text editor.
* Cross-platform, tested on Windows, Linux and OSX.
* Simple File Manager for accessing important files quickly.
* Search tools using Linux or Win32 applications (unxutils).
* Create PDF Documents with PDF create tools.
* Built on Java 1.5 and the Clojure programming language.

http://code.google.com/p/lighttexteditor/wiki/Screenshots

This does not intend to be waterfront or jedit but I am already
finding it useful for my workflow.

Also, I plan on adding Clojure syntax highlighting and editing
support. I am looking for ideas on the best way to tackle.  I am
trying to avoid using a heavy lexer like ANTLR but for this smaller
project, I don't see the harm in using it.  Should I roll my own
syntax highlighter.  Plus, I plan on adding other languages like Java/
Python support in the future.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: functional programming idiom

2009-03-01 Thread Berlin Brown



On Mar 1, 12:19 pm, linh  wrote:
> thank you for the information
>
> On Mar 1, 5:09 pm, "Michel S."  wrote:
>
> > On Mar 1, 11:02 am, "Michel S."  wrote:> On Feb 
> > 28, 6:16 pm, linh  wrote:> hello,
> > > > what's the common idiom in functional programming regarding checking
> > > > the validity of arguments to functions. i think this is called
> > > > defensive programming vs contract programming.
>
> > > Mostly defensive, I think. Some languages (e.g. PLT Scheme) have
> > > contracts:http://docs.plt-scheme.org/guide/contracts.html
>
> > Also, constructs such as Haskell's Maybe monad (available in clojure-
> > contrib) simplifies doing defensive programming on a chain of
> > computation.
>
> > Which reminds me. We have no error monad yet (not as important since
> > Clojure has Java exceptions, though).
>
> > --
> > Michel S.


Good that you brought this up.  I was considering of writing more
design by contract code.  It is definitely a good coding style
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Example JUnit 4.4 use with Clojure

2009-02-28 Thread Berlin Brown



On Feb 28, 12:05 pm, Berlin Brown  wrote:
> On Feb 28, 12:04 pm, BerlinBrown  wrote:
>
> > If you want to use junit with clojure, this is what I ended up doing.
> > Yes, I know there are many clojure test frameworks.  But if you are
> > stuck with a junit mind, then here is an example approach.
>
> >http://clojure.googlegroups.com/web/junit_example_clojure.clj?gsc=rSQ...
>
> The source is contained within one file, but in reality they should be
> broken up into three files.
>
> 1. The Test Case
> 2. The Test Suite
> 3. The compile class.

Here is the output:

Running Test Suite
.Dog
F
Time: 0.002
There was 1 failure:
1) testDog(test.OctaneSampleTestGen)
junit.framework.AssertionFailedError: Test not implemented
at test.OctaneSampleTestGen$_testDog__10.invoke
(OctaneSampleTestGen.clj:55)
at test.OctaneSampleTestGen.testDog(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at test.OctaneSampleTestGen.runTest(Unknown Source)
at test.OctaneSampleTestGen.runBare(Unknown Source)
at test.OctaneSampleTestGen.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:86)
at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:192)
at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:178)
at test.OctaneTestSuite$_main__19.doInvoke(OctaneTestSuite.clj:58)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at test.OctaneTestSuite.main(Unknown Source)

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Example JUnit 4.4 use with Clojure

2009-02-28 Thread Berlin Brown



On Feb 28, 12:04 pm, BerlinBrown  wrote:
> If you want to use junit with clojure, this is what I ended up doing.
> Yes, I know there are many clojure test frameworks.  But if you are
> stuck with a junit mind, then here is an example approach.
>
> http://clojure.googlegroups.com/web/junit_example_clojure.clj?gsc=rSQ...

The source is contained within one file, but in reality they should be
broken up into three files.

1. The Test Case
2. The Test Suite
3. The compile class.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: What's this?

2009-02-20 Thread Berlin Brown



On Feb 20, 11:08 pm, Feng  wrote:
> Exception java.lang.StackOverflowError:
>   [1] clojure.lang.PersistentHashMap$LeafNode.nodeSeq
> (PersistentHashMap.java:567), pc = 2
>   [2] clojure.lang.PersistentHashMap$BitmapIndexedNode$Seq.create
> (PersistentHashMap.java:503), pc = 21
>   [3] clojure.lang.PersistentHashMap$BitmapIndexedNode.nodeSeq
> (PersistentHashMap.java:478), pc = 2
>   [4] clojure.lang.PersistentHashMap$FullNode$Seq.create
> (PersistentHashMap.java:345), pc = 21
>   [5] clojure.lang.PersistentHashMap$FullNode$Seq.next
> (PersistentHashMap.java:356), pc = 41
>   [6] clojure.lang.ASeq.more (ASeq.java:115), pc = 1
>   [7] clojure.lang.RT.more (RT.java:590), pc = 11
>   [8] clojure.core$rest__3032.invoke (core.clj:61), pc = 3
>   [9] clojure.core$concat__3174$cat__3188$fn__3189.invoke (core.clj:
> 445), pc = 71
>   [10] clojure.lang.LazySeq.seq (LazySeq.java:36), pc = 12
>   [11] clojure.lang.RT.seqFrom (RT.java:481), pc = 11
>   [12] clojure.lang.RT.seq (RT.java:451), pc = 19
>   [13] clojure.core$seq__3046.invoke (core.clj:107), pc = 3
>   [14] clojure.core$filter__3749$step__3751.invoke (core.clj:1518), pc
> = 10
>   [15] clojure.core$filter__3749$fn__3755.invoke (core.clj:1522), pc =
> 30
>   [16] clojure.lang.LazySeq.seq (LazySeq.java:36), pc = 12
>   [17] clojure.lang.RT.seqFrom (RT.java:481), pc = 11
>   [18] clojure.lang.RT.seq (RT.java:451), pc = 19
>   [19] clojure.core$seq__3046.invoke (core.clj:107), pc = 3
>   [20] clojure.core$map__3719$fn__3721.invoke (core.clj:1485), pc = 13
>   [21] clojure.lang.LazySeq.seq (LazySeq.java:36), pc = 12
>   [22] clojure.lang.Cons.next (Cons.java:37), pc = 4
>   [23] clojure.lang.RT.next (RT.java:581), pc = 11
>   [24] clojure.core$next__3030.invoke (core.clj:54), pc = 3
>   [25] clojure.core$concat__3174$cat__3188$fn__3189.invoke (core.clj:
> 447), pc = 163
>   [26] clojure.lang.LazySeq.seq (LazySeq.java:36), pc = 12
>   [27] clojure.lang.RT.seqFrom (RT.java:481), pc = 11
>   [28] clojure.lang.RT.seq (RT.java:451), pc = 19
>
>   thousands of [26] [27] [28] ...
>
>   [11159] clojure.lang.LazySeq.seq (LazySeq.java:36), pc = 15
>   [11160] clojure.lang.RT.seqFrom (RT.java:481), pc = 11
>   [11161] clojure.lang.RT.seq (RT.java:451), pc = 19
>   [11162] clojure.core$seq__3046.invoke (core.clj:107), pc = 3


It might help if you provide a little bit more context.

Do you have a unit test that generated the error?

What were you trying to do?

What operating system were you and what version of clojure?

You might improve the title also.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Example use of agent with macro

2009-02-20 Thread Berlin Brown



On Feb 20, 10:29 am, Laurent PETIT  wrote:
> Hello Rich, thanks for answering.
>
> You may not have followed the following of the thread, where I precised my
> mind by saying what I really wanted to do (but did not at first) was using
> with-local-vars, since the value to be mutated is confined in the function,
> and the macro ensures (via the use of a gensymed symbol) that only code
> generated by the macro could try to mutate the var from within the call to
> with-local-vars.
>
> So my question could be rephrased : now that there are atoms :
>  * is 'with-local-vars usage deprecated ?
>  * if not, what could be a typical use case for 'with-local-vars ?
>  * if not, would the scenario we are talking about be appropriate for use of
> 'with-local-vars ?
>
> Thanks in advance,
>
> --
> Laurent
>
> 2009/2/20 Rich Hickey 
>
>
>
> > On Feb 20, 2009, at 5:33 AM, Christophe Grand wrote:
>
> > > Laurent PETIT a écrit :
> > >> If I'm damn sure that the value will be set once from within the same
> > >> thread (here we are in the SWT UI Thread), is there a reason to
> > >> prefer
> > >> atoms ?
> > >> (This is a real question, not a disguised affirmation that I'm doing
> > >> the right thing, so please arguments welcome)
>
> > > Well I would pick atoms because I would ask myself the question the
> > > other way round "is there any reason not to prefer atoms?" and since
> > > the
> > > only reason I can think of is performance...
>
> > > You didn't choose to use an array because of its concurrency model but
> > > because its lack of and that's why, to me, it's a lower-level solution
> > > with which it's not worth to bother about unless you are forced to (by
> > > performance or interop). I understand that in this use-case you don't
> > > need concurrency but it doesn't appear to me as a sufficient reason to
> > > rule out a solution just because it happens to have a concurrency
> > > model
> > > — using an array didn't make the code simpler.
>
> > > I'm not sure I'm doing the right thing either, I'm just trying and
> > > explain how I came to the opposite conclusion.
>
> > I agree with Christophe here. Why stray from the Clojure constructs?
> > The whole point of having them is that, should you decide later to
> > have some/more concurrency, you are using safe constructs in the first
> > place. When people see them in your code they know what can and can't
> > be happening with them. And atoms are very fast.
>
> > Rich

All this made available under the EPL license here :
http://groups.google.com/group/clojure/web/swt_wrapper.clj

Cool example though, make sure that sticks around.  I have referenced
4 or  5 times already.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: General Question Clojure(Lisp) Idiom, cross cutting? What is the terminology

2009-02-20 Thread Berlin Brown



On Feb 20, 10:35 am, Tom Ayerst  wrote:
> You probably don't want to be doing this.  Your function looks like it could
> use a lazy sequency and a filter.
>
> e.g. (doseq [e (filter odd? [1 2 3 4 5 6 7])] (prn e))
>
> You can get a long way with partition, for, filter and reduce;  It is a pain
> to get your head around it at first if your are not used to it (well, it
> was/is for me) but it is worth the effort, the functional programming
> chapter in Stuart Halloway's book is a very good start.
>
> Cheers
>
> Tom
>
> 2009/2/20 BerlinBrown 
>
> > For example, I do that a lot, where I loop through a file and then
> > want to call a function on one particular line string.
>
> > (defn my-func [line no]
> >  ...
> >  ...
>
> > ---
>
> > (defun something
> >(loop [srch-res? (. lm find) line-no 0]
> >  (when srch-res?
> >   
> >(my-func (. lm group) line-no)
> >  ***
>
> >(recur (. lm find) (+ line-no 1))

"You probably don't want to be doing this.  Your function looks like
it could
use a lazy sequency and a filter. "

Slow down, just a pseudo example to ask about the terminology.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Example use of agent with macro

2009-02-19 Thread Berlin Brown



On Feb 19, 6:24 pm, Laurent PETIT  wrote:
> Yes, thank you, I did the simplification.
>
> I couldn't resist continue to do some work around the problem, and I finally
> got both a working version of :
>
> swt-wrapper/sync-exec : a (debugged) macro that does what the initial thread
> was about
> swt-wrapper/swt-app : a macro to be called from the -main method of a
> generated class (that will be the main class of the SWT app) and that
> encapsulates the main readDispatch loop.
>
> All this made available under the EPL license here 
> :http://groups.google.com/group/clojure/web/swt_wrapper.clj
>
> HTH,
>
> --
> Laurent
>
> 2009/2/19 Stephen C. Gilardi 
>
>
>
> > On Feb 19, 2009, at 1:10 PM, Laurent PETIT wrote:
>
> >  Interesting, but is that an implementation detail, or an exposed feature ?
>
> > It's documented at:
>
> >http://clojure.org/special_forms#fn
>
> > (at the bottom)
>
> > --Steve

Good code Laurent.  What was the purpose of the array though?
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---