Re: clueless hash-map question

2009-06-30 Thread Meikel Brandmeyer

Hi,

Am 30.06.2009 um 08:22 schrieb Laurent PETIT:


Here would be the function returning a lazy seq of the map entries :

(def #^{:docstring "Returns a lazy seq of java.util.Map.MapEntry for
the map given as an argument." } mapentries (partial map identity))

(mapentries {:a 1 :b 2}) => ([:a 1] [:b 2])  (lazy seq)


Isn't (seq the-map) sufficient? (see Rich's message)

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: clueless hash-map question

2009-06-30 Thread Laurent PETIT

2009/6/30 Meikel Brandmeyer :
> Hi,
>
> Am 30.06.2009 um 08:22 schrieb Laurent PETIT:
>
>> Here would be the function returning a lazy seq of the map entries :
>>
>> (def #^{:docstring "Returns a lazy seq of java.util.Map.MapEntry for
>> the map given as an argument." } mapentries (partial map identity))
>>
>> (mapentries {:a 1 :b 2}) => ([:a 1] [:b 2])  (lazy seq)
>
> Isn't (seq the-map) sufficient? (see Rich's message)

Yes, totally :-$

>
> Sincerely
> Meikel
>
>

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



Binary Tree

2009-06-30 Thread Emeka
Hello All,

I have a BinaryTree Nodes that I want to resolve it's depth and the
BinaryTree may be unbalanced. How do I do this? Can't just figure it out on
my own?
It is in the form of vector of vectors, and from one cell of any vector I
can move to the next row  however the column index has to be either
increased by one or decreased by one(and the new cell is empty).

Regards,
Emeka

--~--~-~--~~~---~--~~
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 for Scientific and other CPU-intensive Computing

2009-06-30 Thread Konrad Hinsen

On 29.06.2009, at 20:41, fft1976 wrote:

> It's been argued by some that Clojure is as fast as Java, because at
> worst, you can implement your bottlenecks in Java. I have a problem
> with this argument, because the data structures that your Java has to
> work with are still (wasteful) Clojure ones.
>
> For example, a matrix data structure in Clojure could be based on Seqs
> (or Seqs of Seqs) of dynamically typed elements. There is overhead
> associated with this dynamic typing and mutation of the elements.

Choosing the right data structures is at least as important as  
choosing the right language. If you have to deal with 10 MB of  
floats, the right data structure (in the JVM world) is the Java  
array, no matter whether your code is written in Clojure or in Java.

> When you discover that some procedure working on such data structure
> is slow, you can reimplement it in Java, but do you think it could
> compete with Java working on native statically typed arrays of floats?

What is particularly nice about Clojure is that in most situations  
you don't need to switch to Java for speed. You can optimize your  
code by adding type hints and switching to low-level data structures  
(unboxed ints and floats, arrays, ...) and get performance equal to  
Java. The main limitation is that unboxed numbers can't be used at  
the interface between two functions.

Low-level Clojure code is better than Java code because you still  
have the full macro system. Instead of hand-coding, you can often  
write a few macros that generate the low-level code for you.

> I would be curious to know if anyone is using Clojure for CPU-
> intensive work where performance really counts.

Not yet, but I plan to experiment with it in the near future.

Konrad.


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



Re: Clojure for Scientific and other CPU-intensive Computing

2009-06-30 Thread Daniel Lyons


On Jun 29, 2009, at 12:41 PM, fft1976 wrote:

>
> Based on the recent survey "What are people using Clojure for?",
> people are mostly using it for non-CPU-intensive work, like parsing,
> report generation, GUIs, "glue" code.
>
> It's been argued by some that Clojure is as fast as Java, because at
> worst, you can implement your bottlenecks in Java. I have a problem
> with this argument, because the data structures that your Java has to
> work with are still (wasteful) Clojure ones.

You can use (make-array) and work with native Java arrays of native  
Java types if you like. And you can use Java's native interface if  
Java's too slow too, though I hear there is non-negligible cost to  
crossing the interface.

> For example, a matrix data structure in Clojure could be based on Seqs
> (or Seqs of Seqs) of dynamically typed elements. There is overhead
> associated with this dynamic typing and mutation of the elements.

(make-array) can make higher dimensional arrays as well.

> When you discover that some procedure working on such data structure
> is slow, you can reimplement it in Java, but do you think it could
> compete with Java working on native statically typed arrays of floats?

I don't see why that wouldn't be the case, if you were using Java's  
native multidimensional arrays. I don't think it would be as much fun,  
since it would become an exercise in managing mutable state, but if  
performance is the first priority, sacrifices have to be made.

> I would be curious to know if anyone is using Clojure for CPU-
> intensive work where performance really counts.

This is kind of a dodge, but for most of my apps the perception of  
performance is more important than real performance, and  
responsiveness is the essential ingredient to that perception. Clojure  
does great once it's started up and performs better than most of the  
languages I'm accustomed to (Ruby, PHP, JavaScript, etc.) even before  
we throw in concurrency.

Clojure's real value for me probably lies in helping with the glue  
code though. Most of my code seems to be glue code these days, and  
Clojure really minimizes the unfun and makes the rest quite short and  
pleasurable to write. As libraries have exploded I think more people  
find themselves writing more glue code than (?)leaf code.

> I get the impression that Jon Harrop is gearing up to write Clojure
> for Scientists. Also I remember someone saying they are working on the
> Shootout entry for Clojure. Has this happened?

Of course I would be interested if Dr. Harrop did write Clojure for  
Scientists. I think some of his ideas could use wider circulation. I'd  
be a little surprised if he did write it though; isn't he busy with F#  
still?

As an aside, I wouldn't worry too much about wooing scientists. The  
ones I know aren't using Fortran because they like it so much as  
because their ancient simulations are huge and complex and they run on  
supercomputers with expensive compilers. The ones I know that aren't  
using Fortran are using Mathematica, where speed isn't the winning  
feature so much as the attractive environment. If single-core  
performance is your first priority, you probably are going to use C  
and sacrifice some portability. Being comparable in speed to Java in a  
language hosted on the JVM and implemented in Java is no small feat.  
For me, Clojure is a big improvement over Ruby or PHP. If one instead  
arrived from a lower level language, it would mean a loss of  
performance but a gain in productivity and abstraction. Sometimes  
those just aren't the right priorities. To each his own.

—
Daniel Lyons


--~--~-~--~~~---~--~~
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: Binary Tree

2009-06-30 Thread Meikel Brandmeyer

Hi,

Am 30.06.2009 um 09:05 schrieb Emeka:

I have a BinaryTree Nodes that I want to resolve it's depth and the  
BinaryTree may be unbalanced. How do I do this? Can't just figure it  
out on my own?
It is in the form of vector of vectors, and from one cell of any  
vector I can move to the next row  however the column index has to  
be either increased by one or decreased by one(and the new cell is  
empty).


I'm not an algorithm specialist for such things,
but you might want to look into clojure.zip (in
particular clojure.zip/vector-zip). You can
traverse the tree keeping the max depth as
you go.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Troll in our midst - please ignore them

2009-06-30 Thread Daniel Lyons


On Jun 29, 2009, at 8:21 AM, Andrew Garman wrote:

> I'd also suggest that folks rate the posts that are exceptionally good
> or exceptionally bad.  If a user account is noted predominately for
> bad posts, a moderator - whether in this group or another - will think
> twice about allowing the user to freely post.  And vice versa, posts
> from a user with 5 star rating, like yourself, should be welcomed
> anywhere.


I'd take this with a grain of salt. I think trolls are in it for fame  
but they'll take notoriety, and in their immaturity they are likely to  
see quantification as a form of scoring. Seems to me that Slashdot's  
moderation system has created systemic trolls precisely because it  
makes the site more game-like by tracking "karma" which is a lot like  
this. I believe managing the side-effects of this kind of system would  
be about as hard as just managing the troll problem on a case-by-case  
basis.

—
Daniel Lyons


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



ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Meikel Brandmeyer

Dear Clojurians,

I herewith announce a new library: clj-forms.

It provides a small embedded DSL to allow easy creation
of forms by providing a sequence of maps giving the
necessary information. The boilerplate is hidden in the
Forms driver.

Here you can find an example:
  http://kotka.de/projects/clojure/clj-forms.html

The code is as usual on bitbucket.org:
  http://bitbucket.org/kotarak/clj-forms

This is a very new library. At the moment only PanelBuilder
is supported.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Binary Tree

2009-06-30 Thread Daniel Lyons

On Jun 30, 2009, at 1:05 AM, Emeka wrote:

> Hello All,
>
> I have a BinaryTree Nodes that I want to resolve it's depth and the  
> BinaryTree may be unbalanced. How do I do this? Can't just figure it  
> out on my own?
> It is in the form of vector of vectors, and from one cell of any  
> vector I can move to the next row  however the column index has to  
> be either increased by one or decreased by one(and the new cell is  
> empty).


If you had a balanced binary tree, you could just take log_2(N) where  
N is the number of nodes. :) But since you don't you have to do  
something like get the max depth of the left branch and the right  
branch and add one to it (pseudocode):

(defn depth [tree]
   (if (nil? tree) 0
   (+ 1 (max (depth (left tree)) (depth (right tree)

If you're storing this binary tree in an array, I vaguely remember  
doing something like storing the left node at 2*i where i is the index  
of the current node, and the right node at 2*i+1. I'm not sure how  
you'd do that with an unbalanced tree unless you did something like  
have nils in your array. If you did that, you just need to take  
log_2(I) where I is the index of the last non-nil value in the array.

I'm not sure exactly what data structure you're working with to make  
your binary tree though. Can you send an example of the tree you have  
as vectors?

Are you also trying to compute whether or not it's unbalanced or is  
that just a given that it might be?

—
Daniel Lyons


--~--~-~--~~~---~--~~
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: ClassNotFoundException turn up randomly at compilation

2009-06-30 Thread C. Florian Ebeling

>>> I randomly get ClassNotFoundExceptions when I try to compile a file.
>>> This is a paste from the repl:
>>>
>>> Clojure 1.0.0-
>>> user=> (compile 'app.hello)
>>> java.lang.RuntimeException: java.lang.ClassNotFoundException:
>>> app.hello$exec__4 (NO_SOURCE_FILE:0)

It doesn't happen under linux with the same setup.

Florian

-- 
Florian Ebeling
Twitter: febeling
florian.ebel...@gmail.com

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



Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Laurent PETIT

Hi Meikel,

the name of the library is very general, while when reading its
description it seems that it handles just a particular kind of
implementation forms (JGoodies). I can also see that the use by a user
requires the explicit usage of swing constructors.

So I was wondering whether you could make the name reflect the fact
that it is more specific (to swing or jgoodies) ? Because it could be
misleading.

In fact, I thought at first (by just reading the name) that it was an
abstraction over the creation of forms, be they swing or swt ?

Just a suggestion, of course :-)

2009/6/30 Meikel Brandmeyer :
> Dear Clojurians,
>
> I herewith announce a new library: clj-forms.
>
> It provides a small embedded DSL to allow easy creation
> of forms by providing a sequence of maps giving the
> necessary information. The boilerplate is hidden in the
> Forms driver.
>
> Here you can find an example:
>  http://kotka.de/projects/clojure/clj-forms.html
>
> The code is as usual on bitbucket.org:
>  http://bitbucket.org/kotarak/clj-forms
>
> This is a very new library. At the moment only PanelBuilder
> is supported.
>
> Sincerely
> Meikel
>
>

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



Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Meikel Brandmeyer

Hi Laurent,

Am 30.06.2009 um 10:56 schrieb Laurent PETIT:


the name of the library is very general, while when reading its
description it seems that it handles just a particular kind of
implementation forms (JGoodies). I can also see that the use by a user
requires the explicit usage of swing constructors.

So I was wondering whether you could make the name reflect the fact
that it is more specific (to swing or jgoodies) ? Because it could be
misleading.

In fact, I thought at first (by just reading the name) that it was an
abstraction over the creation of forms, be they swing or swt ?

Just a suggestion, of course :-)


At the moment, it's really only a very small wrapper around
the JGoodies library to take away the boilerplate. It doesn't
really deserve an "own" name.

But on the other hand it might be also a good idea to expand
it's functionality to also construct the swing components needed.

(make-panel
  [{:label "Flogiston Pressure" :constraints "1, 1"}
   {:editor Integer :initial 0 :min 0 :max 5 :atom flogiston- 
pressure :constraints "2, 1"}

   {:label "Security Override" :constraints "1, 3"}
   {:editor Boolean :initial false :atom sec-override :constraints  
"2, 3"}]

  :layout my-configured-layout)

The first would create some kind of Spin control, the second
a check box. Changing their state would then modify the supplied
atoms. One could also think of validators, etc...

Was that, what you had in mind? Then a name like clj-swing-forms,
would maybe justifiable. Or maybe Jazz, Blues, ... ?

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Laurent PETIT

Hi,

2009/6/30 Meikel Brandmeyer :
> Hi Laurent,
>
> Am 30.06.2009 um 10:56 schrieb Laurent PETIT:
>
>> the name of the library is very general, while when reading its
>> description it seems that it handles just a particular kind of
>> implementation forms (JGoodies). I can also see that the use by a user
>> requires the explicit usage of swing constructors.
>>
>> So I was wondering whether you could make the name reflect the fact
>> that it is more specific (to swing or jgoodies) ? Because it could be
>> misleading.
>>
>> In fact, I thought at first (by just reading the name) that it was an
>> abstraction over the creation of forms, be they swing or swt ?
>>
>> Just a suggestion, of course :-)
>
> At the moment, it's really only a very small wrapper around
> the JGoodies library to take away the boilerplate. It doesn't
> really deserve an "own" name.
>
> But on the other hand it might be also a good idea to expand
> it's functionality to also construct the swing components needed.
>
> (make-panel
>  [{:label "Flogiston Pressure" :constraints "1, 1"}
>   {:editor Integer :initial 0 :min 0 :max 5 :atom flogiston-pressure
> :constraints "2, 1"}
>   {:label "Security Override" :constraints "1, 3"}
>   {:editor Boolean :initial false :atom sec-override :constraints "2, 3"}]
>  :layout my-configured-layout)

Yes, what I have in mind is that, in some point in time, parts of
clojuredev (ouch, still not decided on a new name :) will be
implemented in clojure, and so I'll have to somewhat create the same
kind of dsl for swt based "forms".

So I was challenging your dsl to see how it could make a good basis
for a cross-way to declare forms (swing based or swt based).
The idea of getting rid of explicit Swing constructors seems good to
me. The only part that remains somewhat very tied to swing in the spec
may be the :constraints specification.

Have you tried the MigLaout layout manager ? (
http://www.miglayout.com/ ). It enables one to specify layout
constraints without strong adherance to either swing or swt or a
particular swing/swt layout manager.


>
> The first would create some kind of Spin control, the second
> a check box. Changing their state would then modify the supplied
> atoms. One could also think of validators, etc...
>
> Was that, what you had in mind? Then a name like clj-swing-forms,
> would maybe justifiable. Or maybe Jazz, Blues, ... ?

I'm pretty bad at finding names, so I won't give you any advice ... :-)

--~--~-~--~~~---~--~~
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: Binary Tree

2009-06-30 Thread Nicolas Oury

If you use depth/size a lot, it might be faster to store them in the
nodes. (it is pseudo code)

(defstruct bintree :head :left :right :size :depth)

(defn make-tree [head left right]
(struct bintree head left right 
  (+ (left :size) (right :size))   
  ( + 1 (max (left :depth) (right :depth)

You have a constant overhead to node construction, but then depth and
size are O(1).
Of course, it makes use of immutability of the children.

That is really useful if you want to balance trees.

I don't get how you store trees in a vector, but you should be able to
store size/depth in the vector too.

Best,

Nicolas.
 


On Tue, 2009-06-30 at 02:28 -0600, Daniel Lyons wrote:
> 
> On Jun 30, 2009, at 1:05 AM, Emeka wrote:
> 
> > Hello All,
> > 
> > I have a BinaryTree Nodes that I want to resolve it's depth and the
> > BinaryTree may be unbalanced. How do I do this? Can't just figure it
> > out on my own?
> > It is in the form of vector of vectors, and from one cell of any
> > vector I can move to the next row  however the column index has to
> > be either increased by one or decreased by one(and the new cell is
> > empty).
> 
> 
> If you had a balanced binary tree, you could just take log_2(N) where
> N is the number of nodes. :) But since you don't you have to do
> something like get the max depth of the left branch and the right
> branch and add one to it (pseudocode):
> 
> 
> (defn depth [tree]
>   (if (nil? tree) 0
>   (+ 1 (max (depth (left tree)) (depth (right tree)
> 
> 
> If you're storing this binary tree in an array, I vaguely remember
> doing something like storing the left node at 2*i where i is the index
> of the current node, and the right node at 2*i+1. I'm not sure how
> you'd do that with an unbalanced tree unless you did something like
> have nils in your array. If you did that, you just need to take
> log_2(I) where I is the index of the last non-nil value in the array.
> 
> 
> I'm not sure exactly what data structure you're working with to make
> your binary tree though. Can you send an example of the tree you have
> as vectors?
> 
> 
> Are you also trying to compute whether or not it's unbalanced or is
> that just a given that it might be?
> 
> — 
> Daniel Lyons
> 
> 
> > 


--~--~-~--~~~---~--~~
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 for Scientific and other CPU-intensive Computing

2009-06-30 Thread fft1976

On Jun 30, 12:55 am, Daniel Lyons  wrote:

> I don't see why that wouldn't be the case, if you were using Java's  
> native multidimensional arrays. I don't think it would be as much fun,  

That's my point. It's often argued that you can just optimize the
teeny "bottleneck" by adding type declarations or rewriting in Java,
but in fact, replacing your Lisp data structures in much of your code
base with Java data structures may be necessary to match Java's speed.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Nicolas Oury

Hi Meikel,

> (make-panel
>[{:label "Flogiston Pressure" :constraints "1, 1"}
> {:editor Integer :initial 0 :min 0 :max 5 :atom flogiston- 
> pressure :constraints "2, 1"}
> {:label "Security Override" :constraints "1, 3"}
> {:editor Boolean :initial false :atom sec-override :constraints  
> "2, 3"}]
>:layout my-configured-layout)
> 
> The first would create some kind of Spin control, the second
> a check box. Changing their state would then modify the supplied
> atoms. One could also think of validators, etc...

It seems a very nice idea. I would suggest the use of agents, for the
states, rather than atom. Especially, the possibility to
have watchers seems good. 
But I am a newbie so I can be wrong.


Best,

Nicolas.


--~--~-~--~~~---~--~~
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: Binary Tree

2009-06-30 Thread Daniel Lyons


On Jun 30, 2009, at 3:50 AM, Nicolas Oury wrote:

>
> If you use depth/size a lot, it might be faster to store them in the
> nodes. (it is pseudo code)
>
> (defstruct bintree :head :left :right :size :depth)
>
> (defn make-tree [head left right]
>   (struct bintree head left right
>  (+ (left :size) (right :size))
> ( + 1 (max (left :depth) (right :depth)
>
> You have a constant overhead to node construction, but then depth and
> size are O(1).
> Of course, it makes use of immutability of the children.

Very good call!

> That is really useful if you want to balance trees.
>
> I don't get how you store trees in a vector, but you should be able to
> store size/depth in the vector too.


It's not working for me right now because I'm tired, but basically the  
observation is that index 1 is the root. Then index 2 and 3 are the  
left and right children respectively. The left and right children of  
index 2 are 4 and 5. The left and right children of index 3 are 6 and  
7. So if you had this tree:

  x
/   \
   y z
  / \   / \
a   b c   d

You could store it in this vector:

[nil x y z a b c d]

And in general you can get from parent to child by doing (i * 2) or (i  
* 2 + 1) and get from child to parent by doing floor [i / 2]. I  
remember doing this in C because it was less intensive than making a  
bunch of structs and making sure the pointers got managed correctly (I  
was a sophomore, give me a break ;). This method doesn't have many  
advantages in Clojure though. :)

—
Daniel Lyons


--~--~-~--~~~---~--~~
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 for Scientific and other CPU-intensive Computing

2009-06-30 Thread Daniel Lyons


On Jun 30, 2009, at 3:53 AM, fft1976 wrote:

>
> On Jun 30, 12:55 am, Daniel Lyons  wrote:
>
>> I don't see why that wouldn't be the case, if you were using Java's
>> native multidimensional arrays. I don't think it would be as much  
>> fun,
>
> That's my point. It's often argued that you can just optimize the
> teeny "bottleneck" by adding type declarations or rewriting in Java,
> but in fact, replacing your Lisp data structures in much of your code
> base with Java data structures may be necessary to match Java's speed.

I don't recall hearing anyone on the list complain about this in  
practice and in the absence of a concrete example of a performance  
problem in actual code to be addressed I'm not sure what else there is  
to say. Usually performance problems *are* teeny bottlenecks and type  
declarations (or better algorithms) are usually sufficient  
improvement. I think if performance demands it be rewritten in Java  
there wouldn't be much to be gained from gutting your Clojure code of  
Clojure data structures, but then again, from what I know about  
Clojure's performance, if it's necessary to rewrite the whole app in  
Java for performance it's probably a better idea to rewrite in  
something else that doesn't run under a VM in the first place. The  
performance difference between Clojure and Java just isn't that great.

Do you have some poorly-performing code we can take a look at? Perhaps  
we can find a way to improve it without such drastic measures. :)

—
Daniel Lyons


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



Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Meikel Brandmeyer

Hi,

Am 30.06.2009 um 11:32 schrieb Laurent PETIT:


Yes, what I have in mind is that, in some point in time, parts of
clojuredev (ouch, still not decided on a new name :) will be
implemented in clojure, and so I'll have to somewhat create the same
kind of dsl for swt based "forms".


Ah! I see the incentive! :)


So I was challenging your dsl to see how it could make a good basis
for a cross-way to declare forms (swing based or swt based).
The idea of getting rid of explicit Swing constructors seems good to
me. The only part that remains somewhat very tied to swing in the spec
may be the :constraints specification.


Well. The constraints spec is still there, because you have
to specify it to the PanelBuilder class of Forms. At least it
is a String. For miglayout for example, you still have specify
other constraints, like span and wrap and such things.
Maybe these can also be abstracted away.


Have you tried the MigLaout layout manager ? (
http://www.miglayout.com/ ). It enables one to specify layout
constraints without strong adherance to either swing or swt or a
particular swing/swt layout manager.


I know MigLayout and I know the contrib by Stephen.
However Forms also provides nice factories and such.
I haven't it used in depth, yet (Neither did I use MigLayout
in depth). But it seems a nice library from what I saw up
to now.


Was that, what you had in mind? Then a name like clj-swing-forms,
would maybe justifiable. Or maybe Jazz, Blues, ... ?


I'm pretty bad at finding names, so I won't give you any  
advice ... :-)


Same here. Name finding is horrible... :)

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Meikel Brandmeyer

Hi,

Am 30.06.2009 um 11:57 schrieb Nicolas Oury:


It seems a very nice idea. I would suggest the use of agents, for the
states, rather than atom. Especially, the possibility to
have watchers seems good.


I'm not sure agents are the right idea here. The forms
are used in dialogs. So when the dialog closes I need
the result immediately. So updating the IRef needs to
be synchronous. agents cannot assure that.

On the other hand one might choose :atom, :agent
or :ref and have the wrapper figure out how to update
the IRef.

Watche(r)s work on all IRef types.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: ANN: clj-forms - a wrapper DSL for JGoodies Forms

2009-06-30 Thread Nicolas Oury

On Tue, 2009-06-30 at 13:10 +0200, Meikel Brandmeyer wrote:

> I'm not sure agents are the right idea here. The forms
> are used in dialogs. So when the dialog closes I need
> the result immediately. So updating the IRef needs to
> be synchronous. agents cannot assure that.
> 
Then it could be great to cache the modifications in vars and commit
them atomically to Refs when you close the dialog. 

> Watche(r)s work on all IRef types.
> 
Thank you very much for the information. I didn't know that. 
Clojure is even better than I thought.

Cheers,

Nicolas.



--~--~-~--~~~---~--~~
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: Binary Tree

2009-06-30 Thread Emeka
(defn depth [tree]
  (if (nil? tree) 0
  (+ 1 (max (depth (left tree)) (depth (right tree)
 This looks close to what I need. Let me see if I can't get my head around
it.

Regards,
Emeka


On Tue, Jun 30, 2009 at 8:28 AM, Daniel Lyons wrote:

>
> On Jun 30, 2009, at 1:05 AM, Emeka wrote:
>
> Hello All,
>
> I have a BinaryTree Nodes that I want to resolve it's depth and the
> BinaryTree may be unbalanced. How do I do this? Can't just figure it out on
> my own?
> It is in the form of vector of vectors, and from one cell of any vector I
> can move to the next row  however the column index has to be either
> increased by one or decreased by one(and the new cell is empty).
>
>
> If you had a balanced binary tree, you could just take log_2(N) where N is
> the number of nodes. :) But since you don't you have to do something like
> get the max depth of the left branch and the right branch and add one to it
> (pseudocode):
>
> (defn depth [tree]
>   (if (nil? tree) 0
>   (+ 1 (max (depth (left tree)) (depth (right tree)
>
> If you're storing this binary tree in an array, I vaguely remember doing
> something like storing the left node at 2*i where i is the index of the
> current node, and the right node at 2*i+1. I'm not sure how you'd do that
> with an unbalanced tree unless you did something like have nils in your
> array. If you did that, you just need to take log_2(I) where I is the index
> of the last non-nil value in the array.
>
> I'm not sure exactly what data structure you're working with to make your
> binary tree though. Can you send an example of the tree you have as vectors?
>
> Are you also trying to compute whether or not it's unbalanced or is that
> just a given that it might be?
>
> —
> Daniel Lyons
>
>
> >
>

--~--~-~--~~~---~--~~
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: ants.clj and render thread starvation

2009-06-30 Thread Krukow

On Jun 29, 7:51 pm, B Smith-Mannschott  wrote:
[snip...]
> much on my netbook. The problem seems to be that with only a single
> (hyperthreaded) core the render agent is almost constantly interrupted
> by some pesky ant while attempting to snapshot the world, forcing the
> render agent to automatically retry. And so, the ants run merrily
> around the world, only I can't see it.

If my understanding of the STM is correct (and it may very well not
be) the render function should not retry. The render function reads
all the refs that define ant positions, but does not modify any ref.
So I suspect that the missing renders are caused by a thread
starvation rather than retries.

But I'd like to hear if Rich agrees ;-)

[snip..]

/Karl
--~--~-~--~~~---~--~~
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: ClassNotFoundException turn up randomly at compilation

2009-06-30 Thread Michael Wood

2009/6/29 C. Florian Ebeling :
>
>>> I randomly get ClassNotFoundExceptions when I try to compile a file.
>>> This is a paste from the repl:
>>>
>>> Clojure 1.0.0-
>>> user=> (compile 'app.hello)
>>> java.lang.RuntimeException: java.lang.ClassNotFoundException:
>>> app.hello$exec__4 (NO_SOURCE_FILE:0)
>>> user=> (compile 'app.hello)
>>> app.hello
>>>
>>> I'm really fresh to Clojure, but that strikes me as very odd. I just
>>> execute the same command twice. But no regularity, before that it
>>> would fail for 20 or so time in a row.
>>
>> I have no idea why it would be random, but perhaps "classes" is not in
>> your class path?
>
> nah, with the paste from the repl I intended to demonstrate that it
> worked and didn't work in two succesive invocations of the exact same
> compile form.

Yes, I understood that.  I have no explanation for it, though.  Sorry :)

> I didn't change anything in the environment. I think
> that it worked in one instance effectively excludes something being
> wrong with the classpath.

Yes, that seems logical, but the problem is your problem does not
appear to be logical ;)

-- 
Michael Wood 

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



Clojure only (in-memory) database / locking granularity

2009-06-30 Thread Rowdy Rednose

Would it be easy to implement an in-memory database in clojure that
allows concurrent access?

It sounds pretty easy, as most of the features are already provided by
Clojure. I'm not sure though about the "locking granularity".
Of course you don't pessimistically lock in Clojure, but if you have a
relation that is "protected" by a Ref, then concurrently adding two
rows to that relation will make one of the two transaction replay,
although the added rows could be completely independent (unless there
are unique constraints, for example, which, now that I think about it,
are present in every real-world table in the form of primary keys).

Furthermore, if you have constraints that involve other relations, say
foreign key constraints, then the locking granularity gets even
coarser, spanning all relations involved, and thus affecting every
mutating access to any one of those relations.

Is there a way to make this more fine-grained and still use the
existing clojure data structures? Or is this for some reason not a
problem in reality?

Has anyone actually implemented something like this in Clojure? You'd
think that many companies have a database that contains their clients
in relations like "Person", "Company", etc.
--~--~-~--~~~---~--~~
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: ants.clj and render thread starvation

2009-06-30 Thread Daniel B Lucraft

I didn't think it was possible for the render agent to be interrupted
like that. Isn't the point of the MVCC system that the render agent
will see a consistent view of the world as it was when the render
started? And that the ants can continue modifying the world during the
render's processing but the render agent will not see any of it until
it has completed it's transaction? It only reads the refs so it
shouldn't ever retry.

Sorry to jump in despite being inexperienced at this, but it makes me
think I don't understand something correctly.

Dan

On Jun 29, 6:51 pm, B Smith-Mannschott  wrote:
> After watching most of Rich's Clojure presentations over the weekend,
> I found myself playing with ants.clj again on my netbook. The ant
> simulation runs brilliantly on my quad-core machine at work. Not so
> much on my netbook. The problem seems to be that with only a single
> (hyperthreaded) core the render agent is almost constantly interrupted
> by some pesky ant while attempting to snapshot the world, forcing the
> render agent to automatically retry. And so, the ants run merrily
> around the world, only I can't see it.
>
> This raises a question. Clojure's refs and dosync sure are neat, but
> this experience would seem to indicate that there are potential
> scalability problems when combining long-running and short-running
> transactions. Under load (or on a slow machine) a long-running
> transaction may never get a chance to complete and may be stuck
> forever retrying, burning CPU but producing no useful output. This
> makes me uneasy.
>
> I was able to get ants.clj to work reliably on my netbook by playing
> around with the sleep times in such a way as to increase the
> probability of the renderer actually completing a snapshot, but this
> process felt hacky and ad-hoc. What works on my netbook might well be
> sub-optimal on another system.
>
> How could one change the design of ants.clj to work reliably (i.e.
> update the screen periodically) even on slower systems?
>
> // Ben

--~--~-~--~~~---~--~~
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: Displaying Clojure code on a Website

2009-06-30 Thread Sam Griffith

Thanks for doing this.

I think I fixed one bug so wanted to mention it.  In your html-post-
format function, you have a string that creates the first .  It
has a explicit style set to have a font-family: courier new and a font-
size of 14px.  I took those styles out so that the style sheet
controlled that correctly.

I also made it so that when the standalone? variable wasn't set to
true that the styles would be embedded into the html that is output.
This allows for cases where you don't have a style.css or where you
want the html to have it's own just for the one file.  I'm sure you
know all that though but it's been fun playing around with this code
and adding these little features.

- Sam

On Jun 26, 9:27 pm, Kai  wrote:
> I fixed a bug that messed up spacing (ampersands weren't converted in
> html-pre-format), so be sure to use the latest version.
>
> Of course, feel free to use it on your webpage!
>
> ~ Kai
>
> On Jun 26, 9:09 pm, CuppoJava  wrote:
>
> > Hi Kai,
> > That is really cool! Do you mind if I use it on my webpage?
>
> > As for coding style, I must say that yours is very clear. It was very
> > easy to read through the whole thing.
>
> >   -Patrick

--~--~-~--~~~---~--~~
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: ants.clj and render thread starvation

2009-06-30 Thread John Newman
I think I remember running the ants.clj demo on my netbook and it running
normally.  I'll check again this evening.

On Tue, Jun 30, 2009 at 12:40 PM, Daniel B Lucraft 
wrote:

>
> I didn't think it was possible for the render agent to be interrupted
> like that. Isn't the point of the MVCC system that the render agent
> will see a consistent view of the world as it was when the render
> started? And that the ants can continue modifying the world during the
> render's processing but the render agent will not see any of it until
> it has completed it's transaction? It only reads the refs so it
> shouldn't ever retry.
>
> Sorry to jump in despite being inexperienced at this, but it makes me
> think I don't understand something correctly.
>
> Dan
>
> On Jun 29, 6:51 pm, B Smith-Mannschott  wrote:
> > After watching most of Rich's Clojure presentations over the weekend,
> > I found myself playing with ants.clj again on my netbook. The ant
> > simulation runs brilliantly on my quad-core machine at work. Not so
> > much on my netbook. The problem seems to be that with only a single
> > (hyperthreaded) core the render agent is almost constantly interrupted
> > by some pesky ant while attempting to snapshot the world, forcing the
> > render agent to automatically retry. And so, the ants run merrily
> > around the world, only I can't see it.
> >
> > This raises a question. Clojure's refs and dosync sure are neat, but
> > this experience would seem to indicate that there are potential
> > scalability problems when combining long-running and short-running
> > transactions. Under load (or on a slow machine) a long-running
> > transaction may never get a chance to complete and may be stuck
> > forever retrying, burning CPU but producing no useful output. This
> > makes me uneasy.
> >
> > I was able to get ants.clj to work reliably on my netbook by playing
> > around with the sleep times in such a way as to increase the
> > probability of the renderer actually completing a snapshot, but this
> > process felt hacky and ad-hoc. What works on my netbook might well be
> > sub-optimal on another system.
> >
> > How could one change the design of ants.clj to work reliably (i.e.
> > update the screen periodically) even on slower systems?
> >
> > // Ben
>
> >
>


-- 
John

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



pprint

2009-06-30 Thread Laurent PETIT

Hi all,

I want to add source code formatting / auto-indenting to the clojure
plugin for eclipse.

I had asked other IDE plugin creators, and it seems that they
leveraged the specifics of their respective platforms to do so. So I
have nothing substantial to "steal from them" not requiring a fair
amount of rework :-)

I'm now facing the following two paths :

 * try to leverage Eclipse's way of doing clojure source code
formatting / auto-indenting and create yet another lib for doing that
very specifically

 * try to do it in clojure so that it can also be used as a standalone
command-line / whatever utility for mass source code reformatting ...

So what is my question ? :-)

Do you know if pprint lib now is (or will in a near future) be able to
handle this use case : that is not only formatting clojure code
returned by the reader, but also clojure code as string, and
potentially broken code (and so it would have to preserve comments,
literal metadata in the exact form they were written, etc.)

Do you know whether there is another existing effort to do this in
plain clojure, or at least sufficiently independtly from an existing
IDE framework so that I can painlessly reuse it ?


Thanks in advance,

-- 
Laurent

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



Re: Clojure only (in-memory) database / locking granularity

2009-06-30 Thread Chouser

On Tue, Jun 30, 2009 at 8:37 AM, Rowdy Rednose wrote:
>
> Would it be easy to implement an in-memory database in clojure that
> allows concurrent access?
>
> It sounds pretty easy, as most of the features are already provided by
> Clojure. I'm not sure though about the "locking granularity".
> Of course you don't pessimistically lock in Clojure, but if you have a
> relation that is "protected" by a Ref, then concurrently adding two
> rows to that relation will make one of the two transaction replay,
> although the added rows could be completely independent (unless there
> are unique constraints, for example, which, now that I think about it,
> are present in every real-world table in the form of primary keys).

You could wrap a Ref around every value, if you chose, to
allow independent changes to different "rows" at the same
time -- though this would not help when inserting rows.

You could partition your key space somehow (perhaps by hash)
to allow n groups of rows, and protect each of those with
a Ref.  This would allow insertions and deletions
independently as long as the operations were being applied
to different groups.

I imagine there are other possible solutions as well...

> Furthermore, if you have constraints that involve other relations, say
> foreign key constraints, then the locking granularity gets even
> coarser, spanning all relations involved, and thus affecting every
> mutating access to any one of those relations.

With either of the layouts I mentioned, this kind of
multi-relation transaction ought to allow Clojure STM to
really shine when compared to a more naive locking scheme.

--Chouser

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



Re: ants.clj and render thread starvation

2009-06-30 Thread B Smith-Mannschott

On Tue, Jun 30, 2009 at 10:10, Daniel B Lucraft wrote:
>
> I didn't think it was possible for the render agent to be interrupted
> like that. Isn't the point of the MVCC system that the render agent
> will see a consistent view of the world as it was when the render
> started? And that the ants can continue modifying the world during the
> render's processing but the render agent will not see any of it until
> it has completed it's transaction? It only reads the refs so it
> shouldn't ever retry.
>
> Sorry to jump in despite being inexperienced at this, but it makes me
> think I don't understand something correctly.
>


To demonstrate my point, I made the following changes to my copy of ants.clj:

--- [[ patch on ants.clj ]] 
Changes in HEAD
Modified ants.clj
diff --git a/ants.clj b/ants.clj
index 5e2e012..43e3ba0 100644
--- a/ants.clj
+++ b/ants.clj
@@ -262,11 +262,14 @@
 (render-ant (:ant p) g x y)))

 (defn render [g]
-  (let [v (dosync (apply vector (for [x (range dim) y (range dim)]
-   @(place [x y]
+  (println "entering render")
+  (let [v (dosync (println "snapshotting world")
+  (apply vector (for [x (range dim) y (range dim)]
+  @(place [x y]
 img (new BufferedImage (* scale dim) (* scale dim)
  (. BufferedImage TYPE_INT_ARGB))
 bg (. img (getGraphics))]
+(println "rendering world")
 (doto bg
   (.setColor (. Color white))
   (.fillRect 0 0 (. img (getWidth)) (. img (getHeight
@@ -278,7 +281,8 @@
   (.drawRect (* scale home-off) (* scale home-off)
  (* scale nants-sqrt) (* scale nants-sqrt)))
 (. g (drawImage img 0 0 nil))
-(. bg (dispose
+(. bg (dispose))
+(println "exiting render")))

 (def panel (doto (proxy [JPanel] []
 (paint [g] (render g)))
- [[ end patch on ants.clj ]] --

After evaluating:

  (def ants (setup))
  (send-off animator animation)

I saw output like this:

  entering render
  snapshotting world
  rendering world
  exiting render
  entering render
  snapshotting world
  rendering world
  exiting render
  ...

After evaluating this, which starts up all the ants and the evaporator
thread:

  (dorun (map #(send-off % behave) ants))
  (send-off evaporator evaporation)

I'm now seeing this:

  entering render
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  snapshotting world
  ...

Clearly "snapshotting world" is getting retried. This makes a certain
degree of sense from skimming LockingTransaction, which ultimately
implements dosync.

I'm *guessing* that it records a readPoint (a kind of transactional
'timestamp') when it starts working and makes sure that this readPoint
is never less than any consulted reference's (last modification)
point. Such a constellation indicates that the reference has been
changed since the start of the transaction.  To recover from this,
clojure does a retry. This it will do 10'000 times before giving up. I
don't believe I ever actually waited that long. ;-)

// ben

--~--~-~--~~~---~--~~
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: ants.clj and render thread starvation

2009-06-30 Thread Rich Hickey

On Tue, Jun 30, 2009 at 7:50 AM, Krukow wrote:
>
> On Jun 29, 7:51 pm, B Smith-Mannschott  wrote:
> [snip...]
>> much on my netbook. The problem seems to be that with only a single
>> (hyperthreaded) core the render agent is almost constantly interrupted
>> by some pesky ant while attempting to snapshot the world, forcing the
>> render agent to automatically retry. And so, the ants run merrily
>> around the world, only I can't see it.
>
> If my understanding of the STM is correct (and it may very well not
> be) the render function should not retry. The render function reads
> all the refs that define ant positions, but does not modify any ref.
> So I suspect that the missing renders are caused by a thread
> starvation rather than retries.
>
> But I'd like to hear if Rich agrees ;-)
>

MVCC history in Clojure's STM is dynamic, created by need. There is no
read tracking, and more important for this case, no transaction
tracking. So, if a read transaction is unable to satisfy its snapshot
view from history, it will flag the offending ref with a fault and
retry. When a writer sees a ref with a read fault it will grow history
for that ref. In this way only as much history is created as is needed
to satisfy the dynamic contention patterns, and
tracking/synchronization is minimized.

The problem for scanning readers like render is that the ref that
caused the fault this pass is unlikely to be the ref that causes the
fault next time, and it will take a while to accumulate even one step
of history for each scanned ref using the fault system.

This has caused me to implement (in git master) some long-planned
controls on ref history. You can now supply :min-history and
:max-history args to ref. The defaults are 0 and 10 respectively. By
setting min-history to some positive value, history will be
accumulated even in the absence of faults, providing a window, if you
will, for scanning readers like render.

You can see this history acquisition by periodically running:

(map ref-history-count (world 20))

while the ants demo is going.

So, now you can preemptively maintain history in the ants demo by
modifying the world init with some min-history (the value 2 below is
your 'knob' for accommodating the duration of the render sweep)

(def world ... (ref (struct cell 0 0) :min-history 2) ...)

Please let me know how that works for you, and, everyone else, please
let me know if max-history default of 10 causes you any trouble
("Transaction failed after reaching retry limit").

There will eventually be more knobs coming, to control
transaction-level retry counts and timeouts.

Rich

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

2009-06-30 Thread Tom Faulhaber

Hi Laurent,

I think that pprint might be a good foundation for what you are doing,
but there are a couple of issues that need to be dealt with first.

First, pprint works directly on Clojure objects and not strings, so
the code will need to be read first.

Second, the Clojure reader is lossy - it strips comments, metadata
tags (#^{}) and expands forms like backquote and reader time
evaluation before passing you the result.

The first thing I would do is look at making a modified reader that
could read chunks of s-expression and pass back raw data. In a perfect
world, this reader would be much more resistant to syntax problems
(for example by "assuming" extra opening or closing brackets of
various types).

Then I would look at how I was going to attach the pprint to the
editor. In practice, I think you want the reformatting to be very
incremental, working on small chunks of code at a time, but you know
better than I.

Using the code dispatch in pretty printing should be pretty easy once
you have this infrastructure. You'll probably want to customize it a
little, but that's fairly straightforward. You'll also probably want
to "clean up" any syntax corrections you made. I might think about
adding metadata to the read structure and then using that in the
dispatch to skip writing open parens that weren't really there, for
instance.

I've been thinking about doing all this, but it's not at the top of my
list right now (working on a new contrib autodoc tool and making
pprint cleaner and faster plus my real job!). But I'm happy to discuss/
help in the short term.

HTH,

Tom

On Jun 30, 7:08 am, Laurent PETIT  wrote:
> Hi all,
>
> I want to add source code formatting / auto-indenting to the clojure
> plugin for eclipse.
>
> I had asked other IDE plugin creators, and it seems that they
> leveraged the specifics of their respective platforms to do so. So I
> have nothing substantial to "steal from them" not requiring a fair
> amount of rework :-)
>
> I'm now facing the following two paths :
>
>  * try to leverage Eclipse's way of doing clojure source code
> formatting / auto-indenting and create yet another lib for doing that
> very specifically
>
>  * try to do it in clojure so that it can also be used as a standalone
> command-line / whatever utility for mass source code reformatting ...
>
> So what is my question ? :-)
>
> Do you know if pprint lib now is (or will in a near future) be able to
> handle this use case : that is not only formatting clojure code
> returned by the reader, but also clojure code as string, and
> potentially broken code (and so it would have to preserve comments,
> literal metadata in the exact form they were written, etc.)
>
> Do you know whether there is another existing effort to do this in
> plain clojure, or at least sufficiently independtly from an existing
> IDE framework so that I can painlessly reuse it ?
>
> Thanks in advance,
>
> --
> Laurent
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure for Scientific and other CPU-intensive Computing

2009-06-30 Thread Luc Prefontaine
On Tue, 2009-06-30 at 01:55 -0600, Daniel Lyons wrote:

> 
> On Jun 29, 2009, at 12:41 PM, fft1976 wrote:
> 
> >
> > Based on the recent survey "What are people using Clojure for?",
> > people are mostly using it for non-CPU-intensive work, like parsing,
> > report generation, GUIs, "glue" code.
> >
> > It's been argued by some that Clojure is as fast as Java, because at
> > worst, you can implement your bottlenecks in Java. I have a problem
> > with this argument, because the data structures that your Java has to
> > work with are still (wasteful) Clojure ones.
> 
> You can use (make-array) and work with native Java arrays of native  
> Java types if you like. And you can use Java's native interface if  
> Java's too slow too, though I hear there is non-negligible cost to  
> crossing the interface.


Optimize the Clojure or java code before anything else. There is a
significant cost in
using JNI. You pay it each time you cross the frontier... there's heavy
structure copying...


> 
> > For example, a matrix data structure in Clojure could be based on Seqs
> > (or Seqs of Seqs) of dynamically typed elements. There is overhead
> > associated with this dynamic typing and mutation of the elements.
> 
> (make-array) can make higher dimensional arrays as well.
> 
> > When you discover that some procedure working on such data structure
> > is slow, you can reimplement it in Java, but do you think it could
> > compete with Java working on native statically typed arrays of floats?
> 
> I don't see why that wouldn't be the case, if you were using Java's  
> native multidimensional arrays. I don't think it would be as much fun,  
> since it would become an exercise in managing mutable state, but if  
> performance is the first priority, sacrifices have to be made.
> 
> > I would be curious to know if anyone is using Clojure for CPU-
> > intensive work where performance really counts.
> 
> This is kind of a dodge, but for most of my apps the perception of  
> performance is more important than real performance, and  
> responsiveness is the essential ingredient to that perception. Clojure  
> does great once it's started up and performs better than most of the  
> languages I'm accustomed to (Ruby, PHP, JavaScript, etc.) even before  
> we throw in concurrency.
> 
> Clojure's real value for me probably lies in helping with the glue  
> code though. Most of my code seems to be glue code these days, and  
> Clojure really minimizes the unfun and makes the rest quite short and  
> pleasurable to write. As libraries have exploded I think more people  
> find themselves writing more glue code than (?)leaf code.


Right... no need to rewrite the low level Java stuff but more fun and
faster code writing
is to be expected with Clojure than Java. At least you will have a
prototype faster
instead of writing piles of code line for months before anything lifts
from the ground.


> 
> > I get the impression that Jon Harrop is gearing up to write Clojure
> > for Scientists. Also I remember someone saying they are working on the
> > Shootout entry for Clojure. Has this happened?
> 
> Of course I would be interested if Dr. Harrop did write Clojure for  
> Scientists. I think some of his ideas could use wider circulation. I'd  
> be a little surprised if he did write it though; isn't he busy with F#  
> still?
> 
> As an aside, I wouldn't worry too much about wooing scientists. The  
> ones I know aren't using Fortran because they like it so much as  
> because their ancient simulations are huge and complex and they run on  
> supercomputers with expensive compilers. The ones I know that aren't  
> using Fortran are using Mathematica, where speed isn't the winning  
> feature so much as the attractive environment. If single-core  
> performance is your first priority, you probably are going to use C  
> and sacrifice some portability. Being comparable in speed to Java in a  
> language hosted on the JVM and implemented in Java is no small feat.  
> For me, Clojure is a big improvement over Ruby or PHP. If one instead  
> arrived from a lower level language, it would mean a loss of  
> performance but a gain in productivity and abstraction. Sometimes  
> those just aren't the right priorities. To each his own.


Agree, you would be better thinking about new parallel algorithms,
easily expressed in Clojure
compared to other languages, to gain some speed. Sometime the nature of
the problem
does not allow this (unavoidable computation dependencies) however
Clojure allows you to test
new alternatives to use multiple CPUs to find better ways to express
your problem.

These alternatives have not been tried out yet because we just happen
now to have cheap SMP
on the desktop. Testing new parallel solutions on these high-cost
parallel architectures is way to 
high in terms of . they have to be tested on small scale first to
see the if they provide any benefits.

There's much to gain in changing our new designs to think "parallel" but
it's

Re: clueless hash-map question

2009-06-30 Thread Raoul Duke

> -Mr. Not Yet With The Programme.

thanks to all for the helpful replies. i might actually be 'getting
it' now. (well, at least minimally :-)

sincerely.

--~--~-~--~~~---~--~~
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 for Scientific and other CPU-intensive Computing

2009-06-30 Thread Mark Engelberg

On Tue, Jun 30, 2009 at 12:29 AM, Konrad
Hinsen wrote:
> What is particularly nice about Clojure is that in most situations
> you don't need to switch to Java for speed. You can optimize your
> code by adding type hints and switching to low-level data structures
> (unboxed ints and floats, arrays, ...) and get performance equal to
> Java.

I have heard this claim about Clojure's speed a number of times, and I
am curious what the evidence for this claim is.  As far as I know, no
one has written a suite of meaningful benchmarks to compare the
performance of Clojure versus Java.

On the other hand, every month or so, someone posts here saying they
tried to do a single benchmark, and it runs quite a bit slower than
Java.  People help out, and usually some ways to improve the code are
found, but I don't think I've ever seen the code actually get to the
point where it has "performance equal to Java".

> The main limitation is that unboxed numbers can't be used at
> the interface between two functions.

Right, and I think without a large body of code, it remains an open
question the degree to which this impacts performance in typical code.

I have been satisfied with Clojure's performance so far, but if I ever
do hit a performance bottleneck, I am not convinced that I will be
able to annotate my way out of the problem.  I have often found myself
wondering whether my code would run faster if I switched to something
like Scala (switching to Java would be too painful for what I'm doing,
so that's off the table).  Maybe not, but it bothers me that I don't
know whether it would make a difference.  I would love to see more
benchmarking of Clojure performance versus Java and other Java
languages.

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



subvec drops metadata

2009-06-30 Thread bayerf

The subject says all: Should subvec keep the parent vector's metadata
(it currently doesn't) or not?
Similar functions like conj, assoc, dissoc DO keep the metadata of the
collection.

--~--~-~--~~~---~--~~
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: Displaying Clojure code on a Website

2009-06-30 Thread Kai

Hey Sam,

I'm glad you were able to refactor the code, I had a fear that it was
too unreadable.

There were several other bugs in that version that you should know of:
- First version didn't use StringBuilder, which accounted for very
slow times.
- Semicolons aren't handled correctly in code and can be mistaken for
comments.
- Vector styles overflow into other elements.

I posted a new version that fixes all of these. I feel it's easier to
read and more flexible. It has the added feature of underlining any
functions you call that you have defined previously in the code.

I'm just beefing up this script until I see a glimmer that draws my
attention to a different project.

~ Kai

On Jun 30, 12:17 am, Sam Griffith  wrote:
> Thanks for doing this.
>
> I think I fixed one bug so wanted to mention it.  In your html-post-
> format function, you have a string that creates the first .  It
> has a explicit style set to have a font-family: courier new and a font-
> size of 14px.  I took those styles out so that the style sheet
> controlled that correctly.
>
> I also made it so that when the standalone? variable wasn't set to
> true that the styles would be embedded into the html that is output.
> This allows for cases where you don't have a style.css or where you
> want the html to have it's own just for the one file.  I'm sure you
> know all that though but it's been fun playing around with this code
> and adding these little features.
>
> - Sam
>
> On Jun 26, 9:27 pm, Kai  wrote:
>
> > I fixed a bug that messed up spacing (ampersands weren't converted in
> > html-pre-format), so be sure to use the latest version.
>
> > Of course, feel free to use it on your webpage!
>
> > ~ Kai
>
> > On Jun 26, 9:09 pm, CuppoJava  wrote:
>
> > > Hi Kai,
> > > That is really cool! Do you mind if I use it on my webpage?
>
> > > As for coding style, I must say that yours is very clear. It was very
> > > easy to read through the whole thing.
>
> > >   -Patrick
--~--~-~--~~~---~--~~
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: Interest in creating a NYC Clojure user group?

2009-06-30 Thread Kai

I would be interested in meeting in NYC.

On Jun 6, 11:38 am, "John D. Hume"  wrote:
> On Thu, Jun 4, 2009 at 12:09 PM, Eric Thorsen wrote:
> > what kind of interest there might be in creating a Clojure user group
> > in the NY metro area to meet up in Manhattan once a month to discuss
> > all things Clojure.
>
> I'd make an effort to attend monthly Clojure meetings in NYC.
>
> --http://elhumidor.blogspot.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Interest in creating a NYC Clojure user group?

2009-06-30 Thread Jonah Benton

Not sure if I could make it on a regular basis, but on a related note,
those in NYC may be interested in:

http://bits.blogs.nytimes.com/2009/06/29/new-york-city-starts-contest-for-big-apple-apps/?ref=technology

Could be an interesting use case for clj + cloud resources

On Thu, Jun 4, 2009 at 12:09 PM, Eric Thorsen wrote:
>
> I went to the Bay Area Clojure group meeting last night which was
> great.  People demoed some very interesting stuff and it was great
> having face time with more people using Clojure.   I wanted to see
> what kind of interest there might be in creating a Clojure user group
> in the NY metro area to meet up in Manhattan once a month to discuss
> all things Clojure. My company is in Westchester but I can _probably_
> get some space (depending on how many of us there are) to meet.
>
> Eric
>
> >
>

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



Re: Interest in creating a NYC Clojure user group?

2009-06-30 Thread Rich Hickey

On Tue, Jun 30, 2009 at 4:47 PM, Kai wrote:
>
> I would be interested in meeting in NYC.
>

Me too!

Rich

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



send versus send-off

2009-06-30 Thread Kai

I can't imagine that this hasn't been asked before, so please direct
this post to an appropriate link if you know of it.

(send a f & args)
Dispatch an action to an agent. Returns the agent immediately.
Subsequently, in a thread from a thread pool, the state of the agent
will be set to the value of:

(send-off a f & args)
Dispatch a potentially blocking action to an agent. Returns the agent
immediately. Subsequently, in a separate thread, the state of the
agent will be set to the value of:

Why is there a distinction between an action and a blocking action?
What kind of concerns arise when you send a potentially blocking
action to an agent and why is send-off better accommodated to deal
with it?

>From scheduling I know that there are CPU-bound and IO-bound
processes. Perhaps send-off tends to hold off on yielding for longer
durations since it expects frequent interrupts. If this is the case, I
think it would be useful to elaborate on that in the documentation of
send-off, even if that's something implemented mostly in Java.

~ Kai
--~--~-~--~~~---~--~~
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: Interest in creating a NYC Clojure user group?

2009-06-30 Thread Andrew Stein

Count me in

At Stuart's presentation to LispNYC, someone took down an email list
for a proposed ClojureNYC group - if only I could remember who .
--~--~-~--~~~---~--~~
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: send versus send-off

2009-06-30 Thread Meikel Brandmeyer

Hi,

Am 30.06.2009 um 23:30 schrieb Kai:


Why is there a distinction between an action and a blocking action?
What kind of concerns arise when you send a potentially blocking
action to an agent and why is send-off better accommodated to deal
with it?


send serves the agent from a fixed ThreadPool. When all
threads in this ThreadPool are used up, your agents basically
freeze waiting in a queue for free threads. The number of threads
in this ThreadPool is limited. send'ing a blocking action basically
blocks the thread. Enough blocking threads might use up all
threads and there you go.

send-off allocates a new thread in a different ThreadPool.
So the aforementioned scenario cannot happen.

A Guru might want to give the details of the second scenario.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


loneclojurian at ICFP programming contest

2009-06-30 Thread igorrumiha

Greetings everyone,

I didn't actually plan it but I ended up participating in the ICFP
programming contest (http://www.icfpcontest.org). This year the task
was to move satellites from one orbit to another, to meet with other
satellites etc. Quite interesting, and to start it all you need to
implement a virtual machine for the physics simulator.

I used Clojure and managed to solve the first of the four problems,
which means I didn't get really far. I was simply too slow to get to
the really interesting stuff. I have written a rather long article
describing my solution so I hope some of you may find it interesting:

http://igor.rumiha.net/tag/icfp/

I have also put the code on github: 
http://github.com/irumiha/icfp-loneclojurian/tree/master

I hope someone has the interest and the time to take a look at the
code. I consider myself a Clojure beginner and any suggestions are
welcome, especially considering possible speed improvements to the
virtual machine. According to some of the people on the #icfp-contest
channel my VM implementation is 500x to 1000x slower than a typical
implementation written in C. It is, on the other hand, in the same
performance range as some VMs written in Python. Some people claim
that the JVM can give you C-like performance, but I would be more than
happy if I got my VM to be 10x slower than the C ones :)


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



NoClassDef Issue, possibly my fault with the classloaders

2009-06-30 Thread BerlinBrown

Pre Notes: I put most of the code for my unit testing here:

http://groups.google.com/group/clojure/web/MostCodeIssue.java
http://groups.google.com/group/clojure/web/NoClassDefIssue.zip
http://clojure.googlegroups.com/web/MostCodeIssue.java?gsc=XGm71ws6-FUP8n2vUln2lQc9yyLJ



This is the strange no classdef not found error. Here is the scenario
which is a little different by 90% of my code works. Please ignore
that I am using Clojure, I have also done this with regular java code
and still get the same error.

Ideally, I was hoping for some help on custom classloader. My initial
thought was that I could create the classloader, add the filepath/url
of the jars to the classloader and I could launch my code. But
apparently there is some strangeness going on.

   1.   I have ONE jar file that dynamically loads 4-5 auxillary jar
files. It is built on a simple URLClassLoader. I want to do this
because I can have a user click on one jar file and launch the
application. So there is one item that the user has to worry about.
   2. By clicking on this jar file, the application loads jar files
from the filesystem. E.g. the application loads swt.jar (Eclipse's
widget toolkit) and some other jars.

3 (but don't worry about it), my application is built on Clojure (the
dynamic programming language), the first application to launch is this
Clojure script. Most of my application is within the clojure script.
4. Everything up to 1-3 works fine. The application loads and clojure
script runs, the SWT GUI application runs, etc.

   1. Here is the part that doesn't work.
   2. I have an existing java library, call it my-swt-gui.jar. That is
also a swt application. It is basically another gui application is
already built. I am trying to load the window from my current clojure/
swt application. For some reason, the JAVA oriented library won't
recognize SWT and I get noclassdef errors.

Here is the strangeness. And I will identify where I think there might
be oddities.

Entitis: A. The java oriented classloader. In the java classloader, I
launch the clojure application. SWT and other jar files are loaded
with this classloader. B. The Clojure oriented code that gets invoked
by section entity a. The clojure code is a swt based GUI application.
B works fine. C. Java code that contains another GUI window. For some
reason, this library wont load and I am getting the error, noclassdef.

NOTE: I KNOW FOR A FACT THAT the SWT class is actually in the
classpath or I would get a NoClassFound exception. I am not getting
that exception. Something else is going on.

Note: could it also be an issue with the fact that SWT includes win32
dlls? Maybe accessing the win32 dll jar the first time works but with
the java code it doesn't work? But that is strange. Why would SWT work
and then not work?
I can't show you all the code, I hope I can show you the relevant
pieces.

Here is the main classloader code:

 public static final String [] JAVA_LIBRARIES = {
"lib\\log4j-1.2.15.jar",
"lib\\octane_commons.jar",
"lib\\clojure.jar",
"lib\\swt\\win32\\swt.jar",
"lib\\jfreechart\\jcommon-1.0.15.jar",
"lib\\jfreechart\\jfreechart-1.0.12.jar",
"lib\\jfreechart\\jfreechart-1.0.12-swt.jar",
"lib\\pdf\\minium.jar",
"lib\\pdf\\tagsoup-1.2.jar",
"lib\\pdf\\core-renderer.jar",
"lib",
"conf",
"src"
};

My classloader code is based on jetty's classloader and it works OK
but I keep get ting classnotdef errors.  Strange ones.  I can see a
clear distinction between classnotfound errors.  If the file path to
the jar is invalid then I get classnotfound, easy to detect and fix.

Here is essentially the classloader code for future reference.

Classpath classpath = new Classpath();

boolean res = classpath.addComponent(libFilePath);

/// Classloader

private class Loader extends URLClassLoader {
String name;
Loader(URL[] urls, ClassLoader parent) {
super(urls, parent);
name = "StartLoader" + Arrays.asList(urls);
}

public String toString() {
return name;
}
}

 Then set the classloader
 where the URLs are the JAR libraries:
   URL [] urls = new URL[NUMBER_OF_JARS];
   for (x in urls) {
  urls[i] = new URL("THE JAR PATH");
   }

ClassLoader parent = Thread.currentThread().getContextClassLoader
();
if (parent == null) {
parent = Classpath.class.getClassLoader();
}
if (parent == null) {

parent = ClassLoader.getSystemClassLoader();
}
return new Loader(urls, parent);

/

And this is how I tried to load the java swt window. I tried to print
out as much about the classloader and change to different classloader.

public static final void createPDFWindowShell(IStartService service,
final Object shell, final Object globalClassLoader) throws Exception {

if ((service != null) && (shell != null)) {
   

Re: send versus send-off

2009-06-30 Thread Stephen C. Gilardi


On Jun 30, 2009, at 5:30 PM, Kai wrote:


From scheduling I know that there are CPU-bound and IO-bound
processes. Perhaps send-off tends to hold off on yielding for longer
durations since it expects frequent interrupts. If this is the case, I
think it would be useful to elaborate on that in the documentation of
send-off, even if that's something implemented mostly in Java.



-

send-off:
- is the more general case
- is somewhat slower on average
- has a quiescent thread count of 0
- has a transient thread count that can be arbitrarily high
- accommodates actions that block.

send-off uses a cached thread pool. The pool grows as necessary to  
accommodate new high water marks of simultaneously pending actions.  
When an action completes, the thread that ran it is kept around for a  
time for possible reuse. If a thread remains idle for a significant  
amount of time, it's terminated and released. The current Java  
implementation of Clojure uses a cached thread pool as described here:


http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool%28%29

-

send:
- is an optimization for non-blocking actions
- is somewhat faster on average
- has a fixed thread count whether it's being used or not
- fails to operate properly if used with actions that block.

send uses a fixed cache pool whose size is related to the number of  
processors (cores) that the JVM sees on your machine. The threads are  
created when Clojure starts up and are not released. They take actions  
off of a shared queue. send never incurs the overhead of creating a  
thread. The promise is (roughly) that your action either executes  
(close to) immediately or waits on a queue because all of the  
available cores are busy anyway. Blocking one of the fixed pool's  
threads would be bad and works against fulfilling send's promise. The  
current Java implementation of Clojure uses a fixed thread pool as  
described here:


http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool%28int%29

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: loneclojurian at ICFP programming contest

2009-06-30 Thread fft1976



On Jun 30, 3:02 pm, igorrumiha  wrote:
> Greetings everyone,
>
> I didn't actually plan it but I ended up participating in the ICFP
> programming contest (http://www.icfpcontest.org). This year the task
> was to move satellites from one orbit to another, to meet with other
> satellites etc. Quite interesting, and to start it all you need to
> implement a virtual machine for the physics simulator.
>
> I used Clojure and managed to solve the first of the four problems,
> which means I didn't get really far. I was simply too slow to get to
> the really interesting stuff. I have written a rather long article
> describing my solution so I hope some of you may find it interesting:
>
> http://igor.rumiha.net/tag/icfp/
>
> I have also put the code on 
> github:http://github.com/irumiha/icfp-loneclojurian/tree/master
>
> I hope someone has the interest and the time to take a look at the
> code. I consider myself a Clojure beginner and any suggestions are
> welcome, especially considering possible speed improvements to the
> virtual machine. According to some of the people on the #icfp-contest
> channel my VM implementation is 500x to 1000x slower than a typical
> implementation written in C. It is, on the other hand, in the same
> performance range as some VMs written in Python. Some people claim
> that the JVM can give you C-like performance, but I would be more than
> happy if I got my VM to be 10x slower than the C ones :)
>
> Igor.

I read somewhere that someone got down to 7 clock cycles per VM
instruction using JIT. You compile to JVM/.NET (via Clojure, e.g.),
and it JITs it for you.

I found this year's contest description super-boring by the way and
decided not to even read the whole problem statement.
--~--~-~--~~~---~--~~
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: subvec drops metadata

2009-06-30 Thread Glen Stampoultzis
I couldn't say whether it should or not but I've faced similar issues with
attaching metadata to various collections.  It becomes very easy to lose the
metadata when you're dealing with collections since many high level
functions tend to return new seqs.  I found myself having to reappy the
metadata frequently.

2009/7/1 bayerf 

>
> The subject says all: Should subvec keep the parent vector's metadata
> (it currently doesn't) or not?
> Similar functions like conj, assoc, dissoc DO keep the metadata of the
> collection.
>
> >
>

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



Problem with clojure code on .net.

2009-06-30 Thread mmwaikar

Hi,

I am learning clojure these days, but on .Net. I have the following
code -

(import '(System.IO Path Directory File DirectoryNotFoundException))

(defn starts-with-hmorx [name]
(if (or (= (.ToUpper (.ToString name)) "H")
  (= (.ToUpper (.ToString name)) "M")
  (= (.ToUpper (.ToString name)) "X")) true false))

(defn GetSubfolderName [filename]
((def name-wo-extn (Path/GetFileNameWithoutExtension filename))
 (def first-char (aget (.ToCharArray (.ToString name-wo-extn)) 0))
 (if (Char/IsDigit first-char) (Convert/ToInt32 first-char) (if
(starts-with-hmorx first-char) (.ToLower (.ToString first-char))
"other"

But when I call (GetSubfolderName "D:\\CsEx\\Manoj.cs"), I get this
exception -

System.InvalidCastException: Unable to cast object of type
'System.String' to type 'clojure.lang.IDeref'.
   at lambda_method(Closure , Object )
   at AFunction_impl.invoke(Object )
   at lambda_method(Closure , Object )
   at AFunction_impl.invoke(Object )
   at lambda_method(Closure )
   at AFunction_impl.invoke()
   at REPLCall(Closure )

Any help is greatly appreciated.

Thanks,
Manoj.
--~--~-~--~~~---~--~~
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: Problem with clojure code on .net.

2009-06-30 Thread Daniel Lyons

Manoj,

On Jun 30, 2009, at 8:55 PM, mmwaikar wrote:

> I am learning clojure these days, but on .Net. I have the following
> code -
>
> (import '(System.IO Path Directory File DirectoryNotFoundException))
>
> (defn starts-with-hmorx [name]
>   (if (or (= (.ToUpper (.ToString name)) "H")
> (= (.ToUpper (.ToString name)) "M")
> (= (.ToUpper (.ToString name)) "X")) true false))
>
> (defn GetSubfolderName [filename]
>   ((def name-wo-extn (Path/GetFileNameWithoutExtension filename))
>(def first-char (aget (.ToCharArray (.ToString name-wo-extn)) 0))
>(if (Char/IsDigit first-char) (Convert/ToInt32 first-char) (if
> (starts-with-hmorx first-char) (.ToLower (.ToString first-char))
> "other"

I think you want something like this instead:

(defn GetSubfolderName [filename]
   (let [name-wo-extn (Path/GetFileNameWithoutExtension filename)
first-char (aget (.ToCharArray (.ToString name-wo-extn)) 0)]
 (if (Char/IsDigit first-char) (Convert/ToInt32 first-char)
(if (starts-with-hmorx first-char) (.ToLower (.ToString first-char))  
"other"

The nested if is a little unusual though. I would probably rewrite it  
to use cond. If you can get a repl going, try to step through each  
expression and see where the problem is that way. I don't have  
Clojure .NET set up to give a more precise answer unfortunately.

—
Daniel Lyons


--~--~-~--~~~---~--~~
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: loneclojurian at ICFP programming contest

2009-06-30 Thread Jeff Foster

I looked at the ICFP Contest too.  I didn't even get as far as solving
the first problem, but I did implement a virtual machine that appeared
to work.  I really enjoyed the coding, though I didn't get very far
with the physics!  I tried a couple of approaches but settling on the
functional side.  Performance was not bad (from what I've seen it was
vaguely comparable to the Python implementations, but was completely
blown away by C/C++ implementations).  I really wish I'd had the time
to do a visualizer!

My code is on github too (http://github.com/fffej/ClojureProjects/tree/
1494815e83febebe9af28b0cb08b812a63df9e96/icfp/uk/co/fatvat) and
there's a write-up on my blog (http://www.fatvat.co.uk/2009/06/icfp-
contest-this-time-its-functional.html).

Again, I'd appreciate any guidance on anything that I could improve!

Cheers

jeff

On Jun 30, 11:02 pm, igorrumiha  wrote:
> Greetings everyone,
>
> I didn't actually plan it but I ended up participating in the ICFP
> programming contest (http://www.icfpcontest.org). This year the task
> was to move satellites from one orbit to another, to meet with other
> satellites etc. Quite interesting, and to start it all you need to
> implement a virtual machine for the physics simulator.
>
> I used Clojure and managed to solve the first of the four problems,
> which means I didn't get really far. I was simply too slow to get to
> the really interesting stuff. I have written a rather long article
> describing my solution so I hope some of you may find it interesting:
>
> http://igor.rumiha.net/tag/icfp/
>
> I have also put the code on 
> github:http://github.com/irumiha/icfp-loneclojurian/tree/master
>
> I hope someone has the interest and the time to take a look at the
> code. I consider myself a Clojure beginner and any suggestions are
> welcome, especially considering possible speed improvements to the
> virtual machine. According to some of the people on the #icfp-contest
> channel my VM implementation is 500x to 1000x slower than a typical
> implementation written in C. It is, on the other hand, in the same
> performance range as some VMs written in Python. Some people claim
> that the JVM can give you C-like performance, but I would be more than
> happy if I got my VM to be 10x slower than the C ones :)
>
> Igor.
--~--~-~--~~~---~--~~
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: ants.clj and render thread starvation

2009-06-30 Thread Krukow


On Jun 30, 6:01 pm, Rich Hickey  wrote:
> MVCC history in Clojure's STM is dynamic, created by need. There is no
> read tracking, and more important for this case, no transaction
> tracking. So, if a read transaction is unable to satisfy its snapshot
> view from history, it will flag the offending ref with a fault and
> retry. When a writer sees a ref with a read fault it will grow history
> for that ref. In this way only as much history is created as is needed
> to satisfy the dynamic contention patterns, and
> tracking/synchronization is minimized.

Ok - I understand better now. I guess I had an "idealized" system in
mind where each ref (in principle) had a complete history associated
with it so reads would never need to be retried (of course, unneeded
entries would somehow be discarded when the system decides it can
never be read.) Certainly that would imply tracking transactions. I
guess you don't do this because of the overhead.

I like the pragmatics of :min-history, and I believe it would be
sufficient for many scenarios. However, I suspect we are now moving
closer to the situation that Cliff Click was predicting [1] where as a
programmer you need more precise knowledge about the STM
implementation to understand the behavior and tune its performance.

Kind Regards,
- Karl

[1] 
http://groups.google.com/group/clojure/browse_frm/thread/5c7a962cc72c1fe7/a1a0cb35070e9558
--~--~-~--~~~---~--~~
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: Problem with clojure code on .net.

2009-06-30 Thread Daniel Lyons

Manoj,

In case this helps, I've had a bit longer to dwell on this problem and  
I have a couple of ideas. I do think this raises the general question  
of, are Clojure .NET and Clojure Java two different languages or two  
implementations of the same language? Normally in a situation like  
this (say, Jython and Python) I would say that they should be two  
implementations of the same language but the situation is complicated  
by the fact that Clojure code relies heavily on Java objects since the  
policy is not to wrap everything. I'm not sure how the subject of  
Clojure .NET / Java portability has been approached but my naïve guess  
is that it would revolve around separating Java dependencies and .NET  
dependencies from pure Clojure code. Is anyone else addressing these  
issues in their own code at this time?

Back to your code. First of all, to simplify things, it's probably a  
good idea to decouple your I/O from your parsing, since the parsing  
can be functional. First I rewrote starts-with-hmorx into this:

(defn starts-with-hm-or-x [name]
   (#{\H \M \X} (.charAt name 0)))

Which I think is simpler, building on the fact that sets can be used  
as functions, but then I thought it would probably be better to  
rewrite the functions into one that gets the information from the  
filesystem and another one that gets the information you want out:

(defn parse-subfolder-name
   [name]
   (or
(when-let [[_ digit] (re-find #"(\d).*" name)]
  (Integer/parseInt digit))
(when-let [[_ hmx] (re-find #"([hHmMxX]).*" name)]
  (.toLowerCase hmx))
"other"))

Unfortunately I'm still dependent on some Java API stuff in there, but  
I think you can probably translate to the .NET equivalents. This is  
easier to test at the REPL:

user> (parse-subfolder-name "0stuf")
0
user> (parse-subfolder-name "Hstuf")
"h"
user> (parse-subfolder-name "stuf")
"other"


Then I'd set about handling the loading of the filename and  
dispatching it:

(defn get-subfolder-name
   [filename]
   (parse-subfolder-name
(.ToString (Path/GetFileNameWithoutExtensions filename

Now it should be easier to determine where the problem is, either in  
the I/O code or in the functional code which is easier to test at the  
REPL.

As an aside, I'd recommend that you follow the naming convention of  
using lowercase function names with words separated by hypens (get- 
subfolder-name) rather than CamelCase (GetSubfolderName). Also, it  
doesn't look to me like GetSubfolderName is really returning a  
subfolder's name but I'm not quite sure what it is doing either. Are  
you working on an app with specific meaning tied to the first  
character of a path name or is this a .NET filesystem thing? Just  
curious.

Thanks and hope this helps,

—
Daniel Lyons


--~--~-~--~~~---~--~~
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: ants.clj and render thread starvation

2009-06-30 Thread Daniel Lyons


On Jun 30, 2009, at 11:50 PM, Krukow wrote:
> I like the pragmatics of :min-history, and I believe it would be
> sufficient for many scenarios. However, I suspect we are now moving
> closer to the situation that Cliff Click was predicting [1] where as a
> programmer you need more precise knowledge about the STM
> implementation to understand the behavior and tune its performance.


While that may be true for the time being I think that Rich's original  
response still holds water: that usually, correctness is more  
important than performance and correctness is the real win with STM.  
It's a nascent technology but that doesn't mean it's useless. Most  
people would probably rather utilize all four or eight of their cores  
at half the theoretical efficiency with no loss of correctness than  
have to create an old fashioned threading model with all the bugs and  
headaches that they entail, trying to get closer to that dream of 100%  
utilization. This is fast food parallelism. It isn't as optimal or as  
hard won but from a cost vs. benefit perspective the choice is  
obvious, especially when comparing to single threaded programming.

STM might be new, but I think an analogy to garbage collection is  
valid. We don't have all the best STM implementation algorithms down  
yet; certainly this is an active research area. But even back when GC  
was extremely new it was already a win for LOC and correctness. Over  
time the technologies got better and the performance question has  
mostly faded away, and it's going to be the same with STM. But only if  
the focus is on correctness first and performance second.

I say mostly faded away because there will always be applications  
where GC cannot be used simply because it makes the system less  
predictable or because it incurs its own cost, such as realtime  
systems and extremely small-scale embedded devices. But most systems  
are not realtime and GC is quite prevalent, even though realtime  
performance characteristics seem generally desirable. It just isn't  
worth the tradeoff in desktop software. Lots of software will benefit  
from STM, even if the performance gains are minimal, even if it turns  
out to be provably impossible to push performance past half that of  
classically threaded programs.

Often there is a sound theoretical reason for throwing out an idea  
which turns out to occur so infrequently in the wild working on it is  
a net win anyway. Ethernet is a good example of a technology that  
shouldn't work well in the wild but which does. A stronger example  
would be Microsoft's Terminator project, which, in attempting to  
create termination proofs for programs through static analysis, flies  
in the face of CS's most famous mathematical proof. It turns out the  
problem is important enough that even the partial, imperfect solutions  
we are damned to would be useful in practice (as long as you don't try  
and run it through itself, of course ;)

http://research.microsoft.com/en-us/um/cambridge/projects/terminator/

The rest of that original thread is a great read, by the way, and  
thanks for bringing it up!

—
Daniel Lyons


--~--~-~--~~~---~--~~
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: loneclojurian at ICFP programming contest

2009-06-30 Thread Nicolas Oury
Hello,
That is an interesting blog post. I am not a clojure specialist, but if I
was to try to change your program to get towards C-like speed (or better), I
would :

- Use java arrays for memory. You don't seem to use the vectors in a
persistent way, and there does not seem to be easy parallelization of the
vm. That's less elegant but probably quicker. I wouldn't say the same thing
if there were possible ways of using persistency later on in the problem.

- Most criticaly, try to use JVM's very good JIT. If it is possible. I
haven't looked to the OVM code precisely.
  If you replace :

(defn make-add
 [#^Integer r1 #^Integer r2 #^Integer pc]
 (fn [machine-state]
 (update-in machine-state [:data] ...)

by :

(defmacro make-add
 [r1 r2 pc-var]

 `(let [pc# (+ 1 pc-var)  (update-in machine-state ...)...)

And instead of reading the instruction and storing them in a vector
you create a term:

program-term =

   `(fn [input-array output-array memory]

  (do ~...@list-of-instructions)

Then you (eval program-term) (once only) at run time, or macro expand
it at compile time (if you have the right to use the binary at compile
time.)

This way, the code should be very fast, once the JIT starts. You can
hope better speed than C, because once compiled, you remove the
decoding phase of the opcode the C program has to do on each run.
Somehow you used clojure to translate OVM bytecode to - hopefully good
- JVM bytecode, that the JVM is very good at executing.

Can a clojure expert confirms wether it would work or not?

Best regards,

Nicolas.

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