Re: Growing trees

2009-01-28 Thread Christophe Grand

Christophe Grand a écrit :
> Timothy Pratley a écrit :
>   
>> I want to grow a tree programmatically so have been trying zippers:
>>
>> (defn insert-parent [loc n]
>>   (clojure.zip/replace loc (clojure.zip/make-node
>>  loc n loc)))
>> (println (clojure.zip/root (insert-parent (clojure.zip/seq-zip (list
>> 1)) 2)))
>> (println (clojure.zip/root (clojure.zip/append-child
>>  (clojure.zip/seq-zip (list 1)) 2)))
>>
>> [(1) nil]
>> (1 2)
>>
>> My 'insert-parent' function does not work, I was trying to get (2 1) -
>> any tips?
>>   
>> 
>
> It's clojure.zip/insert-child you are looking for:
>
> clojure.contrib.struct-ed=> (clojure.zip/root (clojure.zip/insert-child 
> (clojure.zip/seq-zip (list 1)) 2))
> (2 1)
>
> Christophe
>   

My take on your followup question (asked on #clojure):

If you want to add a parent you have to know how to make a new node with 
a single child. Since you are using seq-zip, it's easy: you simply use 
'list ((list x) yields indeed a node with one child: x)!
user=> (-> '(1) clojure.zip/seq-zip (clojure.zip/edit list) 
clojure.zip/root)
((1))

Then you can easily add 2:
user=> (-> '(1) clojure.zip/seq-zip (clojure.zip/edit list) 
(clojure.zip/insert-child 2) clojure.zip/root)
(2 (1))

or in a single step:
user=> (-> '(1) clojure.zip/seq-zip (clojure.zip/edit #(list 2 %)) 
clojure.zip/root)
(2 (1))


Christophe

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread bOR_

There is many ways in which you can improve the algorithm. I have seen
flocks of 10,000 birds being rendered real-time on a laptop by Hanno
Hildenbrandt, theoretical biology Utrecht.

http://www.rug.nl/biologie/onderzoek/onderzoekgroepen/theoreticalbiology/peoplePages/hannoPage

Also, Craig Reynolds himself has been working on speeding up crowd
behaviour (was in contact with him a while ago about Hanno's model).
http://www.research.scea.com/pscrowd/

I think the basic theory of speeding up the whole simulation is to
just let the birds react to nearby birds. The biological reasoning
behind it is that the bird has to pay attention to gather the
information, and will only do so for a fixed number of birds, favoring
those birds that are nearby.

I think there is a whole field in game engine design devoted to that,
but the basic idea is to split up your sky into boxes, in such a way
that you can quickly gather which birds are nearby one particular
bird, and thus which birds influence this single birth. I think
there's also some fun you can have thinking about how to deal with two
birds that are nearby: it would be foolish to drop all the 'birds
nearby bird A' information, if you know that bird A and bird B are
close by, and you still need to calculate bird B.

The one drawback is that these kind of algorithm optimizations might
make your program look less neat :). Have fun!


On Jan 28, 5:00 am, Eric Lavigne  wrote:
> > The technique was first described by Craig Reynolds in the 1980s and has
> > since then made it's way into many contemporary games.  The algorithm is
> > interesting in that it's fairly computationally intensive.  Each boid's
> > motion is determined by calculating it's distance from every other boid.  If
> > the other boids are within a threshold, 3 different vector values (cohesion,
> > alignment, separation) are calculated based on the location and velocites
> > from all other boids that are within the said neighborhood.  There's a lot
> > of interation, 67500 (150x150x3) iterations for 150 boids per update/render
> > loop.
>
> For the purpose of game development, I think it is a mistake to perform
> these calculations for every pair of birds. If you had an error of 1% in
> each of the three characteristics (cohesion, alignment, separation) would
> that still be good enough? Would this be an acceptable loss if you got a
> factor of 100 performance improvement?
>
> In "Objective CAML for Scientists" [1] pages 92-101 Jon Harrop demonstrates
> a rapid numerical solution for a multibody gravitation problem, which looks
> similar to the problem you are solving. He refers to the method as Fast
> Multipole Method [2,3]. It trades a little accuracy for a big performance
> gain. Oh, and his implementation in OCaml uses only immutable data
> structures. No guarantees, but I have a feeling that this would completely
> eliminate your performance issues.
>
> [1]http://www.ffconsultancy.com/products/ocaml_for_scientists/
> [2] W. Rankin and J. Board, "A portable distributed implementation of the
> parallel multipole tree algorithm," in IEEE Symposium on High Performance
> Distributed Computing, (Los Alamitos), pp. 17-22, IEEE Computer Society
> Press, 1995.
> [3]http://en.wikipedia.org/wiki/Fast_Multipole_Method
>
> Sorry for the long post, definitely interested in how I could close the gap.
>
> >  Of course I'm totally ready to accept the fact that this particular
> > algorithm is best suited for having parts written in Java, but I really
> > don't like Java and I love Clojure ;)
>
> I think Clojure can handle this. Good luck :-D
>
> --
> Education is what survives when what has been learned has been forgotten.
>
>                    - B. F. Skinner
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Turning a sequence of chars into a string.

2009-01-28 Thread ivant

On Jan 26, 1:31 am, "Stephen C. Gilardi"  wrote:
> The usual way to do this is with "(apply str ...)"
>

I just wonder if there is a limit to how long the sequence can be,
because apply should use the Java calling stack, right?

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



Re: Tail calls in OpenJDK

2009-01-28 Thread ivant

On Jan 24, 5:31 am, hughw  wrote:
> A fellow named Arnold Schwaighofer is hacking in TCO as a thesis
> project:
>
> http://mail.openjdk.java.net/pipermail/mlvm-dev/2009-January/000331.html

At first I read his name as "Arnold Schwarzenegger".  Now that would
be cool! :D
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: repeat and replicate

2009-01-28 Thread Albert Cardona

Shawn Hoover wrote:
> Why do we have both repeat and replicate? I can sort of keep them straight,
> but as they only differ by arity I wonder if they can be combined... or if
> I'm missing a subtle reason for separate names. A user in IRC threw out the
> possibility of infinite vs. finite functions, but interleave and map seem to
> blur that line.
>   

 From clojure/core.clj :

(defn replicate
  "Returns a lazy seq of n xs."
  [n x] (take n (repeat x)))


-- 
Albert Cardona
http://albert.rierol.net


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Growing trees

2009-01-28 Thread Timothy Pratley

Thanks :)

That works great. I wrote a simple math precedence parser based upon
it:
http://github.com/timothypratley/strive/blob/195c350485a7f01c7ddef01a85d1fd4fc1652fd9/src/clj/math-tree.clj
Test expression [1 + 2 * 3 ^ 4 + 5 * 6]
(+ 1 (* 2 (^ 3 4)) (* 5 6))

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



Re: Turning a sequence of chars into a string.

2009-01-28 Thread Timothy Pratley

> I just wonder if there is a limit to how long the sequence can be,
> because apply should use the Java calling stack, right?

str is only called once, with many arguments:
user=> (apply str (range 1))

Only limit is total memory (like anything).


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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread David Nolen
>
> For the purpose of game development, I think it is a mistake to perform
> these calculations for every pair of birds. If you had an error of 1% in
> each of the three characteristics (cohesion, alignment, separation) would
> that still be good enough? Would this be an acceptable loss if you got a
> factor of 100 performance improvement?
>

Good point.


> In "Objective CAML for Scientists" [1] pages 92-101 Jon Harrop demonstrates
> a rapid numerical solution for a multibody gravitation problem, which looks
> similar to the problem you are solving. He refers to the method as Fast
> Multipole Method [2,3]. It trades a little accuracy for a big performance
> gain. Oh, and his implementation in OCaml uses only immutable data
> structures. No guarantees, but I have a feeling that this would completely
> eliminate your performance issues.
>

Very interesting, these book(s) look amazing!  Thanks much.

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread David Nolen
On Wed, Jan 28, 2009 at 6:59 AM, bOR_  wrote:

>
> There is many ways in which you can improve the algorithm. I have seen
> flocks of 10,000 birds being rendered real-time on a laptop by Hanno
> Hildenbrandt, theoretical biology Utrecht.
>
>
> http://www.rug.nl/biologie/onderzoek/onderzoekgroepen/theoreticalbiology/peoplePages/hannoPage
>
> Also, Craig Reynolds himself has been working on speeding up crowd
> behaviour (was in contact with him a while ago about Hanno's model).
> http://www.research.scea.com/pscrowd/


More great references and readings, thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~--~~~~--~~--~--~---



Creating executable Jars?

2009-01-28 Thread smarf

(ns progs.comex.compileexample
(:gen-class))

(defn -main
  []
  (println (str "Hello " "Sverker" "!")))

(binding [*compile-path* "C:\\clojure\\classes"]
  (compile 'progs.comex.compileexample))


I compiled C:/clojure/progs/comex/compileexample.clj.
I can run the program with:

C:\clojure\classes>java -cp C:/clojure/clojure.jar;
progs.comex.compileexample
Hello Sverker!

Manifest.txt says:
Main-Class: compileexample.class

and is finished with a newline.

so how do I make it a jar?


C:\clojure\classes\progs\comex>dir
 Volume in drive C is Vista
 Volume Serial Number is DC46-FE33

 Directory of C:\clojure\classes\progs\comex

2009-01-28  03:33  .
2009-01-28  03:33  ..
2009-01-27  23:47 1 101 compileexample$fn__554.class
2009-01-27  23:47 1 131 compileexample$_main__551.class
2009-01-27  23:47 1 812 compileexample.class
2009-01-27  23:47 2 431 compileexample__init.class
2009-01-28  03:3134 manifest.txt
   5 File(s)  6 509 bytes
   2 Dir(s)   5 783 875 584 bytes free

C:\clojure\classes\progs\comex>jar cf Hmm.jar C:/clojure/clojure.jar
manifest.tx
t compileexample.class

C:\clojure\classes\progs\comex>Hmm.jar

C:\clojure\classes\progs\comex>


i get a popup :
Java Virtual Machine Launcher
Failed to load Main-class manifest attribute from
C:\clojure

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Agent watchers on Refs

2009-01-28 Thread Rich Hickey



On Jan 27, 8:49 am, MikeM  wrote:
> > Were watchers synchronous, they would have to run post-transaction
> > (else a watcher action failure could cause a transaction rollback,
> > leaving already notified watchers confused). Being post-transaction
> > would mean that the refs could have been changed by another
> > transaction in the interim.
>
> I've been looking at the source to make sure I understand the trade-
> off you're describing. In LockingTransaction, ref.notifyWatches is
> called immediately after ref.validate for each ref. So it seems that a
> watcher could be triggered with a value that then gets rolled back if
> a subsequent validator throws. So even with the current watcher
> implementation, a watcher could be called with a value that is not
> consistent with the actual value of the ref when the transaction is
> done. This doesn't seem much different from the scenario you're
> describing. Is this correct?
>
>

No, because the watchers currently use agent sends, which are held
until post-transaction.

>
> > So, to answer your question, no, watchers don't have to be agents, and
> > while there would be some tighter guarantees were they not, there's no
> > getting around the essential asynchrony of a multi-threaded system.
>
> After looking at how validators and watchers are invoked, I'm thinking
> the current implementation already provides both synchronous and
> asynchronous notification - synch notification via a validator, and
> asynch notification via a watcher agent. Of course, the validator
> isn't intended to be used as a watcher, but I wonder if you could
> generalize the notion of validator so that this is acceptable usage.

I don't think so. Use of validators for anything other than purely-
functional validation is not going to be supported.

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
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: repeat and replicate

2009-01-28 Thread Vincent Foley

repeat returns an infinite seq; replicate returns a finite one.

On Jan 27, 8:53 pm, Shawn Hoover  wrote:
> Why do we have both repeat and replicate? I can sort of keep them straight,
> but as they only differ by arity I wonder if they can be combined... or if
> I'm missing a subtle reason for separate names. A user in IRC threw out the
> possibility of infinite vs. finite functions, but interleave and map seem to
> blur that line.
>
> Shawn
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: repeat and replicate

2009-01-28 Thread Mark Volkmann

On Wed, Jan 28, 2009 at 6:36 AM, Albert Cardona  wrot>
> Shawn Hoover wrote:
>> Why do we have both repeat and replicate? I can sort of keep them straight,
>> but as they only differ by arity I wonder if they can be combined... or if
>> I'm missing a subtle reason for separate names. A user in IRC threw out the
>> possibility of infinite vs. finite functions, but interleave and map seem to
>> blur that line.
>>
>
>  From clojure/core.clj :
>
> (defn replicate
>  "Returns a lazy seq of n xs."
>  [n x] (take n (repeat x)))

Right. Why not add a version of replicate that just takes x and have
it create an infinite, lazy sequence? Then repeat could go away.

-- 
R. Mark Volkmann
Object Computing, Inc.

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



Re: pretty-printing?

2009-01-28 Thread Matt Moriarity

I say go for it. maybe swank could use it for macroexpansions and
stuff. the lack of pretty-print drives me crazy!

On Jan 27, 10:56 am, Mike DeLaurentis  wrote:
> Hi,
>
> Is anyone aware of a pretty-print function for Clojure? I saw there
> was some discussion about it on this thread a while ago, but I don't
> seem to see anything related to pretty-print in either the core or
> clojure-contrib. If no one's working on implementing it, I might take
> a stab at it.
>
> Thanks,
>
> Mike
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: pretty-printing?

2009-01-28 Thread David Nolen
Agreed ;)

On Wed, Jan 28, 2009 at 9:54 AM, Matt Moriarity wrote:

>
> I say go for it. maybe swank could use it for macroexpansions and
> stuff. the lack of pretty-print drives me crazy!
>
> On Jan 27, 10:56 am, Mike DeLaurentis  wrote:
> > Hi,
> >
> > Is anyone aware of a pretty-print function for Clojure? I saw there
> > was some discussion about it on this thread a while ago, but I don't
> > seem to see anything related to pretty-print in either the core or
> > clojure-contrib. If no one's working on implementing it, I might take
> > a stab at it.
> >
> > Thanks,
> >
> > Mike
> >
>

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



Re: Creating executable Jars?

2009-01-28 Thread .Bill Smith

Your manifest assumes your main class lives in the default Java
package, but doesn't it really live in the progs.comex package?  Also,
don't you need to use the "m" switch when you specify a manifest to
the jar command?

Bill

On Jan 27, 10:01 pm, smarf  wrote:
> (ns progs.comex.compileexamples
>     (:gen-class))
>
> (defn -main
>   []
>   (println (str "Hello " "Sverker" "!")))
>
> (binding [*compile-path* "C:\\clojure\\classes"]
>   (compile 'progs.comex.compileexample))
>
> I compiled C:/clojure/progs/comex/compileexample.clj.
> I can run the program with:
>
> C:\clojure\classes>java -cp C:/clojure/clojure.jar;
> progs.comex.compileexample
> Hello Sverker!
>
> Manifest.txt says:
> Main-Class: compileexample.class
>
> and is finished with a newline.
>
> so how do I make it a jar?
>
> C:\clojure\classes\progs\comex>dir
>  Volume in drive C is Vista
>  Volume Serial Number is DC46-FE33
>
>  Directory of C:\clojure\classes\progs\comex
>
> 2009-01-28  03:33              .
> 2009-01-28  03:33              ..
> 2009-01-27  23:47             1 101 compileexample$fn__554.class
> 2009-01-27  23:47             1 131 compileexample$_main__551.class
> 2009-01-27  23:47             1 812 compileexample.class
> 2009-01-27  23:47             2 431 compileexample__init.class
> 2009-01-28  03:31                34 manifest.txt
>                5 File(s)          6 509 bytes
>                2 Dir(s)   5 783 875 584 bytes free
>
> C:\clojure\classes\progs\comex>jar cf Hmm.jar C:/clojure/clojure.jar
> manifest.tx
> t compileexample.class
>
> C:\clojure\classes\progs\comex>Hmm.jar
>
> C:\clojure\classes\progs\comex>
>
> i get a popup :
> Java Virtual Machine Launcher
> Failed to load Main-class manifest attribute from
> C:\clojure
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: def vs. intern

2009-01-28 Thread Matt Moriarity

yes, that is why.

On Jan 27, 9:55 am, Mark Volkmann  wrote:
> On Mon, Jan 26, 2009 at 8:19 PM, James Reeves
>
>
>
>  wrote:
>
> > On Jan 27, 2:08 am, Mark Volkmann  wrote:
> >> Let's see if I've got this straight.
>
> >> (def foo 1) creates a Var in the default namespace with a value of 1.
>
> >> (create-ns 'com.ociweb.demo) ; creates a new namespace
> >> (intern 'com.ociweb.demo foo 2) ; creates another Var named foo, but
> >> it's not in the default namespace
>
> >> But the last line gives a java.lang.ClassCastException. What's wrong
> >> with that line?
>
> > Because it should be: (intern 'com.ociweb.demo 'foo 2)
>
> > Gotta quote that symbol :)
>
> Thanks!
>
> What's the rationale for treating "foo" differently than in a def? I'm
> referring to the need to quote foo in an intern, but not in a def. Is
> it just because def is a special form whereas intern is a function?
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread Konrad Hinsen

On Jan 28, 2009, at 5:00, Eric Lavigne wrote:

> In "Objective CAML for Scientists" [1] pages 92-101 Jon Harrop  
> demonstrates a rapid numerical solution for a multibody gravitation  
> problem, which looks similar to the problem you are solving. He  
> refers to the method as Fast Multipole Method [2,3]. It trades a  
> little accuracy for a big performance gain. Oh, and his  
> implementation in OCaml

The Fast Multipole Method is an algorithm for rapidly calculating all  
pairwise interactions between a set of objects, provided that the  
interactions have a particular form. The method was developed for  
gravitational interactions (e.g. between planets or stars) and for  
electrostatic interactions (e.g. between atoms), which are two types  
of interactions that have the same mathematical form: the energy is  
inversely proportional to the distance between two objects.

It is possibe to generalize the Fast Multipole Method somewhat, but  
it remains a technique for a limited (though important) class of  
interactions. It is rather unlikely that it will be of any use for  
simulating a flock of birds.

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
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: Creating executable Jars?

2009-01-28 Thread Greg Harman

A couple things:

1. I don't know about embedding jars... Instead, use the Class-Path
manifest attribute to link in clojure.jar.

2. I noticed that your jar command was specifically packaging only
compileexample.class. You need all 4 of those generated classes in the
jar.

-Greg

On Jan 27, 11:01 pm, smarf  wrote:
> (ns progs.comex.compileexample
>     (:gen-class))
>
> (defn -main
>   []
>   (println (str "Hello " "Sverker" "!")))
>
> (binding [*compile-path* "C:\\clojure\\classes"]
>   (compile 'progs.comex.compileexample))
>
> I compiled C:/clojure/progs/comex/compileexample.clj.
> I can run the program with:
>
> C:\clojure\classes>java -cp C:/clojure/clojure.jar;
> progs.comex.compileexample
> Hello Sverker!
>
> Manifest.txt says:
> Main-Class: compileexample.class
>
> and is finished with a newline.
>
> so how do I make it a jar?
>
> C:\clojure\classes\progs\comex>dir
>  Volume in drive C is Vista
>  Volume Serial Number is DC46-FE33
>
>  Directory of C:\clojure\classes\progs\comex
>
> 2009-01-28  03:33              .
> 2009-01-28  03:33              ..
> 2009-01-27  23:47             1 101 compileexample$fn__554.class
> 2009-01-27  23:47             1 131 compileexample$_main__551.class
> 2009-01-27  23:47             1 812 compileexample.class
> 2009-01-27  23:47             2 431 compileexample__init.class
> 2009-01-28  03:31                34 manifest.txt
>                5 File(s)          6 509 bytes
>                2 Dir(s)   5 783 875 584 bytes free
>
> C:\clojure\classes\progs\comex>jar cf Hmm.jar C:/clojure/clojure.jar
> manifest.tx
> t compileexample.class
>
> C:\clojure\classes\progs\comex>Hmm.jar
>
> C:\clojure\classes\progs\comex>
>
> i get a popup :
> Java Virtual Machine Launcher
> Failed to load Main-class manifest attribute from
> C:\clojure
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~--~~~~--~~--~--~---



two way benefits

2009-01-28 Thread Mark Volkmann

What are some benefits of allowing two ways of doing the following?

There are two ways to access constants in a Java class.
(. java.util.Calendar APRIL)
java.util.Calendar/APRIL

There are two ways invoke a static method in a Java class.
(. Math pow 2 4)
(Math/pow 2 4)

There are two ways to invoke a constructor to create a Java object.
(def calendar (new GregorianCalendar 2008 3 16))
(def calendar (GregorianCalendar. 2008 3 16))

There are two ways invoke an instance method on a Java object.
(. calendar add Calendar/MONTH 2)
(.add calendar Calendar/MONTH 2)

It seems that in each case the second way is preferred. Why not get
rid of the first way?

-- 
R. Mark Volkmann
Object Computing, Inc.

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



Re: repeat and replicate

2009-01-28 Thread Christian Vest Hansen

On Wed, Jan 28, 2009 at 3:23 PM, Mark Volkmann
 wrote:
>
> On Wed, Jan 28, 2009 at 6:36 AM, Albert Cardona  wrot>
>> Shawn Hoover wrote:
>>> Why do we have both repeat and replicate? I can sort of keep them straight,
>>> but as they only differ by arity I wonder if they can be combined... or if
>>> I'm missing a subtle reason for separate names. A user in IRC threw out the
>>> possibility of infinite vs. finite functions, but interleave and map seem to
>>> blur that line.
>>>
>>
>>  From clojure/core.clj :
>>
>> (defn replicate
>>  "Returns a lazy seq of n xs."
>>  [n x] (take n (repeat x)))
>
> Right. Why not add a version of replicate that just takes x and have
> it create an infinite, lazy sequence? Then repeat could go away.

Or replicate could go away.

More likely, I think one of them could take multiple arities and make
the other obsolete.

>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

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



Re: two way benefits

2009-01-28 Thread Christophe Grand

Mark Volkmann a écrit :
> What are some benefits of allowing two ways of doing the following?
>
> There are two ways to access constants in a Java class.
> (. java.util.Calendar APRIL)
> java.util.Calendar/APRIL
>
> There are two ways invoke a static method in a Java class.
> (. Math pow 2 4)
> (Math/pow 2 4)
>
> There are two ways to invoke a constructor to create a Java object.
> (def calendar (new GregorianCalendar 2008 3 16))
> (def calendar (GregorianCalendar. 2008 3 16))
>
> There are two ways invoke an instance method on a Java object.
> (. calendar add Calendar/MONTH 2)
> (.add calendar Calendar/MONTH 2)
>
> It seems that in each case the second way is preferred. Why not get
> rid of the first way?
>   
The first way makes macros easier to write.

eg:
  `(new ~a-class) instead of (list (symbol (str (name a-class) \.)))

The second way is just "syntax" sugar:
user=> (macroexpand-1 '(Foo.))
(new Foo)

Christophe


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



Classloading again

2009-01-28 Thread Ferdinando Villa

Clojure is saving our life and enabling thing we would never have
dreamed of without in our ARIES project (http://ecoinformatics.uvm.edu/
aries). Still, we need to hack RT in order to be able to use it. I've
seen some discussion on classloader flexibility in the context of
Eclipse integration. In our case, we use a similar environment (JPF
plugin framework, may move to similar OGSI later) where Clojure
bindings are loaded by each plugin in sequence, each having to use a
specific classloader in order to see the Java classes in the plugin.
Because there is one RT, we're not going to make it work unless we
manually switch the classloader Clojure uses to the plugin-specific
one every time we load bindings. This requires making a field public
and it's, generally speaking, a ugly hack. Also, because we run in a
multi-user server environment, we'd love to have one RT per session so
we could only load what's needed there and not pollute the runtime in
other sessions. Or even RT objects arranged in a tree so each can use
the parent's environment and cleanly be disposed of when not needed
anymore.

All this is clearly hard to do with the current static Clojure
runtime. How much of this is a choice, and how much is likely to
change in the future? We'd love to use Clojure as is.

Otherwise, thanks, thanks, thanks

ferdinando
http://ecoinformatics.uvm.edu
http://www.integratedmodelling.org

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



offtopic: code_swarm

2009-01-28 Thread Frantisek Sodomka

I found an interesting project code_swarm (an experiment in organic
software visualization), which I would like to share:
http://vis.cs.ucdavis.edu/~ogawa/codeswarm/

See video(s):
code_swarm - Python
http://www.vimeo.com/1093745

Source:
http://code.google.com/p/codeswarm/

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread mago

I don't know anything about how a bird navigates as part of a flock,
but I guess it uses its eyes to see the other birds. And I also
imagine that it pays more attention to birds nearby than to far away
birds. Maybe it even uses the area covered on its retina by the other
bird to assign to assign it some "weight" in its "navigation
algorithm". In that case, then the influence of other birds would
decrease in inverse proportion to the square of the distance :)

On Jan 28, 9:09 am, Konrad Hinsen  wrote:
> On Jan 28, 2009, at 5:00, Eric Lavigne wrote:
>
> > In "Objective CAML for Scientists" [1] pages 92-101 Jon Harrop
> > demonstrates a rapid numerical solution for a multibody gravitation
> > problem, which looks similar to the problem you are solving. He
> > refers to the method as Fast Multipole Method [2,3]. It trades a
> > little accuracy for a big performance gain. Oh, and his
> > implementation in OCaml
>
> The Fast Multipole Method is an algorithm for rapidly calculating all
> pairwise interactions between a set of objects, provided that the
> interactions have a particular form. The method was developed for
> gravitational interactions (e.g. between planets or stars) and for
> electrostatic interactions (e.g. between atoms), which are two types
> of interactions that have the same mathematical form: the energy is
> inversely proportional to the distance between two objects.
>
> It is possibe to generalize the Fast Multipole Method somewhat, but
> it remains a technique for a limited (though important) class of
> interactions. It is rather unlikely that it will be of any use for
> simulating a flock of birds.
>
> 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
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: changes to test_clojure and test_contrib

2009-01-28 Thread Frantisek Sodomka
Hello Steve,
I attached file predicates.patch for type and number predicates. Let me
know, if this is an acceptable patch (I haven't worked with them before). We
can then create an issue for Clojure-contrib if necessary.

Shawn, I keep wondering where is the best place to put tests for bug fixes.
One way would be to create a separate file (bugs.clj) and put all these
tests there. Another way is to include these tests into their respective
categories - although I wonder for example test for (= () []) => true  ...
where should it go? Should it go equality.clj or to sequences.clj???
Any suggestions/opinions about where is the best place for bug fixes???

Thank you, Frantisek


On Tue, Jan 27, 2009 at 2:05 AM, Stephen C. Gilardi wrote:

>
> On Jan 26, 2009, at 7:43 PM, Shawn Hoover wrote:
>
> I have a few tests in the works and am lacking commit access as well.
> Should test contributions follow the procedure of group discussion, then
> file an issue, then post a patch? If so, what would you like to know about
> the patch(es)?
>
>
> I consider the call for good unit tests covering areas of clojure or
> contrib that currently lack them to be permanently open.
>
> One of the purposes of discussing things on the mailing list first is to
> attract good ideas and thoughts from its denizens and avoid duplicating
> large-ish bits of effort. You may even occasionally find a collaborator that
> you can work with. That remains a good idea even in the case of unit tests.
> Of course that's all best done when you are beginning to think about some
> contribution rather than when it's nearly complete.
>
> Please do make a post here describing what you have. Then generate one or
> more issues (in groupings that make good common sense) against
> clojure-contrib describing which areas of clojure or contrib your
> contribution will test and attach the patches to them.
>
> Thanks,
>
> --Steve
>
>

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



predicates.patch
Description: Binary data


Clojure code formatter

2009-01-28 Thread Laurent PETIT
Hello,

Do you know if there is a clojure code formatter, written either in clojure
or java ?

It could take a string or InputStream/Reader or File as its input, and
return a well formatted String/outputStream/Writer ?

Indeed, I don't want to reinvent the wheel for clojure-dev, but if it is
written in Python/Ruby/emacs lisp ... I'll need to do so, though ;-)

Thanks in advance,

Regards,

-- 
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
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 Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread Jon Harrop

On Wednesday 28 January 2009 15:09:26 Konrad Hinsen wrote:
> It is possibe to generalize the Fast Multipole Method somewhat, but
> it remains a technique for a limited (though important) class of
> interactions.

I disagree. The most obvious generalization of FMM (and the one presented in 
my books OCaml for Scientists and F# for Scientists) is the hierarchical 
spatial decomposition of general contributions rather than just poles. That 
category of methods is huge, encompasses many of the most important 
algorithms ever invented and is applicable to most physical simulations, most 
notably heterogeneously distributed ones.

Moreover, the inherent ability of these methods to attain a required accuracy 
efficiently also makes them ideally suited for games programming where 
physical accuracy is traded for soft real-time performance.

> It is rather unlikely that it will be of any use for simulating a flock of
> birds. 

People are using FMM for flocking:

http://www.itk.ilstu.edu/faculty/portegys/research/ptree-PDPTA03.pdf
http://litis.univ-lehavre.fr/~tranouez/publications/Cossom2007-LITIS-DutotTranouez.pdf

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

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



New functions and possible bugs

2009-01-28 Thread Frantisek Sodomka

Hello all!
During writing tests for type predicates, I noticed that these -
possibly useful - predicates are not in clojure.core:
boolean?
character?
regex?
array?

Since this is correct:
user=> (= () [])
true

Shouldn't these be also 'true'?
user=> (= {} [])
false
user=> (= {} #{})
false
user=> (= {} ())
false
user=> (= #{} [])
false
user=> (= #{} ())
false

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread Mark H.

On Jan 28, 7:09 am, Konrad Hinsen  wrote:
> It is possible to generalize the Fast Multipole Method somewhat, but  
> it remains a technique for a limited (though important) class of  
> interactions. It is rather unlikely that it will be of any use for  
> simulating a flock of birds.

The FMM itself might not be directly applicable to simulating bird
flocking, but the general idea of the FMM and similar algorithms
(coalesce groups of far-away point forces into a single force) could
be helpful.

For the n^2 algorithm, it's mainly important to pay attention to data
locality.  Suppose for example that you keep the n 2-D coordinates of
the birds in an n x 2 array.  (OP is right, Java multi-D arrays are
awful for performance; map this n x 2 array onto a single-D Java
array.)  So you have

L =
x_1, y_1
x_2, y_2
...
x_n, y_n

Computing the distances is a kind of outer product.  For best locality
in L, you'll want to store it row-wise rather than column-wise.  That
way when you iterate over points you'll be traveling with unit stride
over L rather than skipping over it by n steps each time.

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



Re: Simple Examples of Concurrency?

2009-01-28 Thread wubbie


@mire.rooms/*rooms* is new to me.
could anybody explain to me?

-sun


(defn- mire-handle-client [in out]
  (binding [*in* (reader in)
*out* (writer out)]
;; bindings doesn't work sequentially, so we need to nest them
;; otherwise the call to read-name uses the old value of *in*/
*out*
(binding [*name* (read-name)
  *inventory* (ref [])
  *current-room* (ref (@mire.rooms/*rooms* :start))]

On Jan 27, 8:45 pm, "Stephen C. Gilardi"  wrote:
> On Jan 27, 2009, at 3:57 PM, wubbie wrote:
>
> > Why defn ends with -(dash)?
>
> > (defn- mire-handle-client [in out]
>
> A good approach to finding out what a function does is to consult "doc":
>
>         (doc defn-)
>
> --Steve
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: changes to test_clojure and test_contrib

2009-01-28 Thread Shawn Hoover
On Wed, Jan 28, 2009 at 11:18 AM, Frantisek Sodomka wrote:

>
> Shawn, I keep wondering where is the best place to put tests for bug fixes.
> One way would be to create a separate file (bugs.clj) and put all these
> tests there. Another way is to include these tests into their respective
> categories - although I wonder for example test for (= () []) => true  ...
> where should it go? Should it go equality.clj or to sequences.clj???
> Any suggestions/opinions about where is the best place for bug fixes???
>
> Thank you, Frantisek


Frantisek,

I considered the same questions and decided to organize my tests alongside
existing ones by topic. My reasoning was that the goal is a unified
maintainable test suite, and I was just plugging a couple holes. A test in a
bugs.clj script is likely to be duplicated as another developer fills out
the tests for a related topic unawares. The fact that a given test
originated in response to a bug report is a minor historical artifact, which
I felt merited no more structure than a small comment next to the test (and
a comment in the Google bug tracker).

As for locating specific topics, currently the suite is organized by top
level clojure.org topics. Sometimes you just have to pick (I wasn't clear on
evaluation vs. reader in some cases). The equality example you mentioned
could go in data_structures or a specific vectors file.

Shawn

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread Konrad Hinsen

On Jan 28, 2009, at 18:07, Jon Harrop wrote:

> I disagree. The most obvious generalization of FMM (and the one  
> presented in
> my books OCaml for Scientists and F# for Scientists) is the  
> hierarchical
> spatial decomposition of general contributions rather than just  
> poles. That

I agree that hierarchical spatial decomposition is a much more  
general concept that has lots of applications. I don't agree that it  
is a generalization of FMM. Hierarchical spatial decomposition is  
only one aspect of FMM, another being the existence and use of bounds  
on the error of the numerical approximation. The evaluation of these  
bounds depends on the mathematical form of the interactions. I don't  
expect them to carry over to arbitrary forms of interactions, though  
I'd like to be proven wrong. It may be possible to derive error  
bounds for other forms of interactions as well, but unless they are  
also based on a multipole expansion, the use of the name FMM would be  
confusing.

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



Re: New functions and possible bugs

2009-01-28 Thread Mark Volkmann

On Wed, Jan 28, 2009 at 11:13 AM, Frantisek Sodomka  wrote:
>
> Hello all!
> During writing tests for type predicates, I noticed that these -
> possibly useful - predicates are not in clojure.core:
> boolean?
> character?
> regex?
> array?

I'd also like function? and macro? as an alternative to checking the
metadata for :macro set to true.

> Since this is correct:
> user=> (= () [])
> true
>
> Shouldn't these be also 'true'?
> user=> (= {} [])
> false
> user=> (= {} #{})
> false
> user=> (= {} ())
> false
> user=> (= #{} [])
> false
> user=> (= #{} ())
> false

-- 
R. Mark Volkmann
Object Computing, Inc.

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



Clojure articles and blogs

2009-01-28 Thread Mark Volkmann

Are there web pages that provide links to articles and blogs about Clojure?
It would be nice if an "Articles" link and a "Blogs" link to such
pages appeared in the upper-right corner of http://clojure.org.

-- 
R. Mark Volkmann
Object Computing, Inc.

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



Re: Clojure articles and blogs

2009-01-28 Thread Nick Vogel
Personally I search for clojure on google blogsearch and then subscribe to
that feed to see whenever someone posts something about clojure.

On Wed, Jan 28, 2009 at 12:38 PM, Mark Volkmann
wrote:

>
> Are there web pages that provide links to articles and blogs about Clojure?
> It would be nice if an "Articles" link and a "Blogs" link to such
> pages appeared in the upper-right corner of http://clojure.org.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>

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



Re: Simple Examples of Concurrency?

2009-01-28 Thread Phil Hagelberg

wubbie  writes:

> @mire.rooms/*rooms* is new to me.
> could anybody explain to me?

Sure thing. *rooms* is a ref in the mire.rooms namespace. So since we
haven't used "refer" or "use" to draw all everything from mire.rooms
into the current namespace, we prefix the var with its namespace to
refer to it. And then the "@" before it simply means deref.

In summary: get the value of the ref named *rooms* in the mire.rooms
namespace.

> (binding [*name* (read-name)
>   *inventory* (ref [])
>   *current-room* (ref (@mire.rooms/*rooms* :start))]

In this case *rooms* is a ref that refers to a map, so we're looking up
:start in that map and setting the *current-room* ref to that value.

-Phil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Newbie: Trying to write revised multithreaded Swing Celsius converter app

2009-01-28 Thread samppi

Thanks for the replies, everyone. I read in an article that one of the
most common Swing mistakes is putting non-GUI work into the event
dispatch thread, but it seems like oftentimes the cost of creating a
new thread outweighs the benefit of separation, if the work is simple.
With the code above, I was trying to figure out how to do a Swing app
while performing potentially long procedure, such as contacting a
different connected computer.

But for Keith's comments—when would it good to block the Swing thread?
Even if I wanted to disable the control that started the action,
shouldn't I just use (.setEnabled button false)? I'd think that the
GUI should always be able to respond to the user, or else it would
seem frozen.

I guess it'd be bad with multiple modal dialogs. I think maybe I
should just try to avoid those. :)

On Jan 27, 4:38 pm, Keith Bennett  wrote:
> samppi -
>
> Typical Swing programs create a window with all its components and
> event handlers in the main thread, and then launch the event handling
> thread implicitly by calling setVisible(true) on the window (usually a
> JFrame).  I've always done it this way, and have never had a problem.
> However, there may be special cases where even the construction of a
> window needs to be done on the event handling thread, I don't know.
>
> By default, *all code* that you define to respond to user events is
> called on the event dispatch thread.  In my several years experience
> working with Swing, use of the SwingWorker technique was very rarely
> needed.  Of course, if your actions are more time consuming than mine
> were, then your experience will be different; but I recommend being
> sparing in its use.
>
> There are complexities associated with *not* blocking the Swing
> thread; for example, you'd probably want to disable the control (e.g.
> button) that initiated the action to prevent it from being triggered a
> second time.  In addition, if multiple actions can be occurring
> simultaneously, then one has to be sure that their interactions do not
> collide.  What if two such actions result in the display of a modal
> dialog?   And you probably wouldn't want the user to be able to close
> the window while the button's action is in process.   ...and on and
> on...
>
> - Keith
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread bOR_

Errata: Hanno works in Groningen. As I work in Utrecht, I sort of
automatically appended 'Utrecht' after 'Theoretical Biology'.

Ontopic: There is a thing called Hilbert curves that you could use.
http://en.wikipedia.org/wiki/Hilbert_curve

You could define a 1d array, and translate the bird 2d position into a
position in that array, using the hilbert curve. Now, if you want to
have a subset of nearby birds, you can just take a subarray of that
array around the bird of interest, and base your bird behaviour on the
birds in that subarray.

Not sure what the best data structure is to implement this in, or what
way to do it in clojure, but it gives you an idea.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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 articles and blogs

2009-01-28 Thread rb



On 28 jan, 18:38, Mark Volkmann  wrote:
> Are there web pages that provide links to articles and blogs about Clojure?
> It would be nice if an "Articles" link and a "Blogs" link to such
> pages appeared in the upper-right corner ofhttp://clojure.org.


Bill Clementson created a Yahoo Pipe aggregating clojure articles, you
can find it here:
http://pipes.yahoo.com/pipes/pipe.info?_id=4cc8ebb9ae0b852d6ab7d94956ce2638


raph
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Simple Examples of Concurrency?

2009-01-28 Thread wubbie

The notation mire.rooms/ is new, especially dod(.) and slash(/).
mire.rooms is rooms in ns mire, etc?

-sun


On Jan 28, 12:50 pm, Phil Hagelberg  wrote:
> wubbie  writes:
> > @mire.rooms/*rooms* is new to me.
> > could anybody explain to me?
>
> Sure thing. *rooms* is a ref in the mire.rooms namespace. So since we
> haven't used "refer" or "use" to draw all everything from mire.rooms
> into the current namespace, we prefix the var with its namespace to
> refer to it. And then the "@" before it simply means deref.
>
> In summary: get the value of the ref named *rooms* in the mire.rooms
> namespace.
>
> >     (binding [*name* (read-name)
> >               *inventory* (ref [])
> >               *current-room* (ref (@mire.rooms/*rooms* :start))]
>
> In this case *rooms* is a ref that refers to a map, so we're looking up
> :start in that map and setting the *current-room* ref to that value.
>
> -Phil
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Simple Examples of Concurrency?

2009-01-28 Thread wubbie

Oh,

I see (ns mire.rooms ... in rooms.clj
Also see (def *rooms* ...)
So we can refer in other name spaces
the vars and functions in this ns?
Like mire.rooms/*rooms*,  mire.rooms/*items*,
 mire.rooms/make-room etc?

Thanks
-sun

On Jan 28, 1:18 pm, wubbie  wrote:
> The notation mire.rooms/ is new, especially dod(.) and slash(/).
> mire.rooms is rooms in ns mire, etc?
>
> -sun
>
> On Jan 28, 12:50 pm, Phil Hagelberg  wrote:
>
> > wubbie  writes:
> > > @mire.rooms/*rooms* is new to me.
> > > could anybody explain to me?
>
> > Sure thing. *rooms* is a ref in the mire.rooms namespace. So since we
> > haven't used "refer" or "use" to draw all everything from mire.rooms
> > into the current namespace, we prefix the var with its namespace to
> > refer to it. And then the "@" before it simply means deref.
>
> > In summary: get the value of the ref named *rooms* in the mire.rooms
> > namespace.
>
> > >     (binding [*name* (read-name)
> > >               *inventory* (ref [])
> > >               *current-room* (ref (@mire.rooms/*rooms* :start))]
>
> > In this case *rooms* is a ref that refers to a map, so we're looking up
> > :start in that map and setting the *current-room* ref to that value.
>
> > -Phil
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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.contrib.command-line patch: multiple option format

2009-01-28 Thread Perry Trolard

Hi Chouser,

Is there anything I can do to help get the proposed change above, or
something like it, included in c.c.command-line? I'd be happy to
modify the patch: removing the somewhat orthogonal alignment code,
etc.

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread Jon Harrop

On Wednesday 28 January 2009 18:09:30 bOR_ wrote:
> Errata: Hanno works in Groningen. As I work in Utrecht, I sort of
> automatically appended 'Utrecht' after 'Theoretical Biology'.
>
> Ontopic: There is a thing called Hilbert curves that you could use.
> http://en.wikipedia.org/wiki/Hilbert_curve
>
> You could define a 1d array, and translate the bird 2d position into a
> position in that array, using the hilbert curve. Now, if you want to
> have a subset of nearby birds, you can just take a subarray of that
> array around the bird of interest, and base your bird behaviour on the
> birds in that subarray.
>
> Not sure what the best data structure is to implement this in, or what
> way to do it in clojure, but it gives you an idea.

That is an academically fascinating idea that I once persued when I was an 
academic (in the context of dynamical matrix preconditioning). :-)

Unfortunately, it does not work out well in practice despite the existence of 
some great Hilbert curve libraries:

  http://www.tiac.net/~sw/2008/10/Hilbert/moore/index.html

The reason is that cache locality much prefers striping over suitably-sized 
tiles rather than fancy curves.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

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



Learning Clojure

2009-01-28 Thread janus

While reading Programming Clojure the other night I found this code
interesting (+), however, when I tried out (-) I got my fingers burnt.
Why this? Or did I do something wrong which has nothing to do with
the  code in question?

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



Length of Sequence

2009-01-28 Thread Peter Wolf

Here's a dumb question, but I can't find it in the docs:

How do I get the length of a sequence?  Is there some generic way to 
find the number of elements in something that might be list, map, vector 
or lazy?

There must be some sort of built in function, or an idiom

Thanks
P

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



Re: Length of Sequence

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 2:15 PM, Peter Wolf  wrote:
>
> How do I get the length of a sequence?  Is there some generic way to
> find the number of elements in something that might be list, map, vector
> or lazy?

user=> (doc count)
-
clojure.core/count
([coll])
  Returns the number of items in the collection. (count nil) returns
  0.  Also works on strings, arrays, and Java Collections and Maps

Note how the name and docs both cleverly avoid use of the words "size"
or "length", to help the function remain undiscovered by searches
through the source code and by uses of find-doc.

--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
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: Length of Sequence

2009-01-28 Thread Kevin Downey

(doc count)
-
clojure.core/count
([coll])
  Returns the number of items in the collection. (count nil) returns
  0.  Also works on strings, arrays, and Java Collections and Maps
nil


On Wed, Jan 28, 2009 at 11:15 AM, Peter Wolf  wrote:
>
> Here's a dumb question, but I can't find it in the docs:
>
> How do I get the length of a sequence?  Is there some generic way to
> find the number of elements in something that might be list, map, vector
> or lazy?
>
> There must be some sort of built in function, or an idiom
>
> Thanks
> P
>
> >
>



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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



"incremental" (sort of) clojure compilation

2009-01-28 Thread Laurent PETIT
Hello,

Say I have namespace a.b.c that is defined in file a/b/c.clj, but which also
has some part in file a/b/c1.clj. And that a/b/c.clj loads a/b/c1.clj
somewhere in the code.


If I a.b.c via (compile 'a.b.c), the classes and files are in sync.

If I now make a change in file a/b/c1.clj, how to make clojure recompile
a.b.c ?

- I think, if I just do (compile 'a.b.c), the compilation will not proceed,
because file a/b/c.clj "seems" to be in sync (that's "a/b/c1.clj that is not
in sync).

One solution could be to "touch" file a/b/c.clj before calling 'compile on
it ?

Are there other (maybe cleaner) solutions ?

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
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: Length of Sequence

2009-01-28 Thread Peter Wolf

Thanks guys!  I knew I could 'count' on you ;-)

Chouser wrote:
> On Wed, Jan 28, 2009 at 2:15 PM, Peter Wolf  wrote:
>   
>> How do I get the length of a sequence?  Is there some generic way to
>> find the number of elements in something that might be list, map, vector
>> or lazy?
>> 
>
> user=> (doc count)
> -
> clojure.core/count
> ([coll])
>   Returns the number of items in the collection. (count nil) returns
>   0.  Also works on strings, arrays, and Java Collections and Maps
>
> Note how the name and docs both cleverly avoid use of the words "size"
> or "length", to help the function remain undiscovered by searches
> through the source code and by uses of find-doc.
>
> --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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: New functions and possible bugs

2009-01-28 Thread Perry Trolard

> I'd also like function? and macro? as an alternative to checking the
> metadata for :macro set to true.

Forgive my parital answer to the intial query of the thread, but
regarding a function? predicate, it's already included:

user=> (doc fn?)
-
clojure.core/fn?
([x])
  Returns true if x implements Fn, i.e. is an object created via fn.
nil
user=> (doc ifn?)
-
clojure.core/ifn?
([x])
  Returns true if x implements IFn. Note that many data structures
  (e.g. sets and maps) implement IFn
nil


Regarding macro?, it's use seems limited by the fact that macros are
not self-evaluating like functions, so the macro? predicate would have
to be a macro, which means it can't be passed to other functions, etc.
But its implementation would of course be:

  (defmacro macro? [x] `(:macro (meta (var ~x


Perry


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



Re: "incremental" (sort of) clojure compilation

2009-01-28 Thread Christophe Grand

Laurent PETIT a écrit :
> Hello,
>
> Say I have namespace a.b.c that is defined in file a/b/c.clj, but 
> which also has some part in file a/b/c1.clj. And that a/b/c.clj loads 
> a/b/c1.clj somewhere in the code.
>
>
> If I a.b.c via (compile 'a.b.c), the classes and files are in sync.
>
> If I now make a change in file a/b/c1.clj, how to make clojure 
> recompile a.b.c ?
>
> - I think, if I just do (compile 'a.b.c), the compilation will not 
> proceed, because file a/b/c.clj "seems" to be in sync (that's 
> "a/b/c1.clj that is not in sync).
>
> One solution could be to "touch" file a/b/c.clj before calling 
> 'compile on it ?
>
> Are there other (maybe cleaner) solutions ?
>

Hi Laurent,

Can't you rebind clojure.core/load to record all resources laoded during 
a namespace compilation?

Christophe

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



Re: "incremental" (sort of) clojure compilation

2009-01-28 Thread Laurent PETIT
Hello Christophe,

2009/1/28 Christophe Grand 

>
> Laurent PETIT a écrit :
> > Hello,
> >
> > Say I have namespace a.b.c that is defined in file a/b/c.clj, but
> > which also has some part in file a/b/c1.clj. And that a/b/c.clj loads
> > a/b/c1.clj somewhere in the code.
> >
> >
> > If I a.b.c via (compile 'a.b.c), the classes and files are in sync.
> >
> > If I now make a change in file a/b/c1.clj, how to make clojure
> > recompile a.b.c ?
> >
> > - I think, if I just do (compile 'a.b.c), the compilation will not
> > proceed, because file a/b/c.clj "seems" to be in sync (that's
> > "a/b/c1.clj that is not in sync).
> >
> > One solution could be to "touch" file a/b/c.clj before calling
> > 'compile on it ?
> >
> > Are there other (maybe cleaner) solutions ?
> >
>
> Hi Laurent,
>
> Can't you rebind clojure.core/load to record all resources laoded during
> a namespace compilation?


Well yes, that seems indeed a good solution to another problem I'll have to
solve (dependency graph of files) -> thanks for anticipation my next
question :-)
But does it solve the problem I exposed ?

Let's rephrase it : to force the recompilation of a lib, is there another
way than "touching" the lib's declaring file (so that if I just make changes
in a file loaded by the lib's declaring file, I'm sure the lib is really
recompiled) ?

Thanks in advance,

-- 
Laurent


>
>
> Christophe
>
> >
>

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



Re: New functions and possible bugs

2009-01-28 Thread Cosmin Stejerean
On Wed, Jan 28, 2009 at 11:13 AM, Frantisek Sodomka wrote:

[...]

Since this is correct:
> user=> (= () [])
> true
>
> Shouldn't these be also 'true'?
> user=> (= {} [])
> false
> user=> (= {} #{})
> false
> user=> (= {} ())
> false
> user=> (= #{} [])
> false
> user=> (= #{} ())
> false
>

Well, I'm not yet sure if I like it but lists and vectors that have
identical elements in them appear to be equal, not just empty ones.

user=> (= [1, 2] '(1, 2))
true

Since any list can be represented as an equivalent vector (and any vector as
an equivalent list) I can imagine this making sense.

user=> (apply list [1 2 1])
(1 2 1)
user=> (apply vector '(1 2 1))
[1 2 1]

But I don't see how this would ever apply to sets or maps so I don't see why
empty sets and maps should be an exception.

-- 
Cosmin Stejerean
http://offbytwo.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
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: "incremental" (sort of) clojure compilation

2009-01-28 Thread Christophe Grand

Laurent PETIT a écrit :
>
> Hi Laurent,
>
> Can't you rebind clojure.core/load to record all resources laoded
> during
> a namespace compilation?
>
>
> Well yes, that seems indeed a good solution to another problem I'll 
> have to solve (dependency graph of files) -> thanks for anticipation 
> my next question :-)
> But does it solve the problem I exposed ?
>
> Let's rephrase it : to force the recompilation of a lib, is there 
> another way than "touching" the lib's declaring file (so that if I 
> just make changes in a file loaded by the lib's declaring file, I'm 
> sure the lib is really recompiled) ?
>
Well, I answered your next question because, here, clojure.core/compile 
doesn't try to be smart and recompile the whole lib each time it is 
called. :-( (or :-) I don't know)

Christophe

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



Re: Clojure for Games/Simluation/Art (Optimization in Clojure)

2009-01-28 Thread bOR_

Aww. Indeed, if I remember Hanno's talks, he was using meticiously
sized cubes that worked well with the cache.

by the way, the way to get bird rather than boid/fish swarms is to add
gravity, and let the birds bank and roll and pitch and yaw.

On Jan 28, 7:46 pm, Jon Harrop  wrote:
> On Wednesday 28 January 2009 18:09:30 bOR_ wrote:
>
> > Errata: Hanno works in Groningen. As I work in Utrecht, I sort of
> > automatically appended 'Utrecht' after 'Theoretical Biology'.
>
> > Ontopic: There is a thing called Hilbert curves that you could use.
> >http://en.wikipedia.org/wiki/Hilbert_curve
>
> > You could define a 1d array, and translate the bird 2d position into a
> > position in that array, using the hilbert curve. Now, if you want to
> > have a subset of nearby birds, you can just take a subarray of that
> > array around the bird of interest, and base your bird behaviour on the
> > birds in that subarray.
>
> > Not sure what the best data structure is to implement this in, or what
> > way to do it in clojure, but it gives you an idea.
>
> That is an academically fascinating idea that I once persued when I was an
> academic (in the context of dynamical matrix preconditioning). :-)
>
> Unfortunately, it does not work out well in practice despite the existence of
> some great Hilbert curve libraries:
>
>  http://www.tiac.net/~sw/2008/10/Hilbert/moore/index.html
>
> The reason is that cache locality much prefers striping over suitably-sized
> tiles rather than fancy curves.
>
> --
> Dr Jon Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?e
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: New functions and possible bugs

2009-01-28 Thread Frantisek Sodomka

Talking about equality of:
user=> (= [1, 2] '(1, 2))
true

I also wondered if there could be something as "strict equal", which
returns true only if both the operands are equal and of the same type.
See JavaScript:
http://www.devguru.com/Technologies/ecmascript/quickref/comparison_operators.html
http://www.devguru.com/Technologies/ecmascript/quickref/javascript_index.html

Frantisek


On Jan 28, 9:17 pm, Cosmin Stejerean  wrote:
> On Wed, Jan 28, 2009 at 11:13 AM, Frantisek Sodomka wrote:
>
> [...]
>
> Since this is correct:
>
> > user=> (= () [])
> > true
>
> > Shouldn't these be also 'true'?
> > user=> (= {} [])
> > false
> > user=> (= {} #{})
> > false
> > user=> (= {} ())
> > false
> > user=> (= #{} [])
> > false
> > user=> (= #{} ())
> > false
>
> Well, I'm not yet sure if I like it but lists and vectors that have
> identical elements in them appear to be equal, not just empty ones.
>
> user=> (= [1, 2] '(1, 2))
> true
>
> Since any list can be represented as an equivalent vector (and any vector as
> an equivalent list) I can imagine this making sense.
>
> user=> (apply list [1 2 1])
> (1 2 1)
> user=> (apply vector '(1 2 1))
> [1 2 1]
>
> But I don't see how this would ever apply to sets or maps so I don't see why
> empty sets and maps should be an exception.
>
> --
> Cosmin Stejereanhttp://offbytwo.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
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
-~--~~~~--~~--~--~---



nested maps

2009-01-28 Thread Mark Volkmann

I have a map that describes a person.
It has a key that describes their address.
It also has a key for their employer.
The employer has its own address.

(def person {
  :name "Mark Volkmann"
  :address {
:street "644 Glen Summit"
:city "St. Charles"
:state "Missouri"
:zip 63304}
  :employer {
:name "Object Computing, Inc."
:address {
  :street "12140 Woodcrest Executive Drive, Suite 250"
  :city "Creve Coeur"
  :state "Missouri"
  :zip 63141}}})

Is this the best way to retrieve the employer city?
(reduce get person [:employer :address :city])

Is this the best way to get a new map where the city is changed?
(update-in person [:employer :address :city] (fn [old & args] "Clayton"))
I can't get this to work with #("Clayton") in place of the anonymous
function above.

-- 
R. Mark Volkmann
Object Computing, Inc.

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



more readable IRefs

2009-01-28 Thread Chouser

Currently if you happen upon a Ref in the REPL, you don't get much
helpful information:

user=> (ref #{:a 1})
#

Improving on this is not difficult:

(defmethod print-method clojure.lang.IRef [o w]
  (.write w (format "#<%...@%x: %s>"
(.getSimpleName (class o))
(System/identityHashCode o)
(pr-str @o

Now Ref and all her cousins print their values:

user=> (agent 99)
#

The identity code is included so you can tell if it's the same object
or a different one, since the identity of reference objects matter.

user=> (let [a (atom 4)] (swap! a inc) (prn a) (swap! a + 10) (prn a))
#
#

This is also why the #<> format is still used, disallowing 'read' from
working on the string.

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



test-is: generating and processing testing data

2009-01-28 Thread Frantisek Sodomka

Hello, I have suggestion about clojure.contrib.test-is.

It is useful and sometimes necessary to generate testing data.
Currently, data can be generated by a piece of code and passed to an
'is' function. For example, I want to test for equality of many
things, to see if each is equal to each:

(use 'clojure.contrib.combinatorics)
(use 'clojure.contrib.test-is)

(deftest each-is-equal-to-each
  (let [data [0 0.0 0M]
test-data (combinations data 2)]
(doseq [td test-data]
  (is (apply = td)

Now, I can easily extend 'data' to do more tests (e.g. byte 0, float
0, ...). This will work, but it is not as readable as I would like it
to be.

Another approach would be to allow 'are' macro to accept generated
testing data:

user=> (combinations [0 0.0 0M] 2)
((0 0.0) (0 0M) (0.0 0M))
user=> (apply concat (combinations [0 0.0 0M] 2))
(0 0.0 0 0M 0.0 0M)

(are (= _1 _2)
  (apply concat (combinations [0 0.0 0M] 2)))


Older style of tests could be then rewritten as:

(are (= _1 _2)
  3 (+ 1 2)
  0 (+ -1 1))

becomes

(are (= _1 _2)
  (list
3 (+ 1 2)
0 (+ -1 1)))

or nicer:

(are (= _1 _2)
  [3 (+ 1 2)
   0 (+ -1 1)])

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



Re: nested maps

2009-01-28 Thread Vincent Foley

(-> person :employer :address :city) would be my pick

Vincent

On Jan 28, 4:02 pm, Mark Volkmann  wrote:
> I have a map that describes a person.
> It has a key that describes their address.
> It also has a key for their employer.
> The employer has its own address.
>
> (def person {
>   :name "Mark Volkmann"
>   :address {
>     :street "644 Glen Summit"
>     :city "St. Charles"
>     :state "Missouri"
>     :zip 63304}
>   :employer {
>     :name "Object Computing, Inc."
>     :address {
>       :street "12140 Woodcrest Executive Drive, Suite 250"
>       :city "Creve Coeur"
>       :state "Missouri"
>       :zip 63141}}})
>
> Is this the best way to retrieve the employer city?
> (reduce get person [:employer :address :city])
>
> Is this the best way to get a new map where the city is changed?
> (update-in person [:employer :address :city] (fn [old & args] "Clayton"))
> I can't get this to work with #("Clayton") in place of the anonymous
> function above.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: repeat and replicate

2009-01-28 Thread Stephen C. Gilardi


On Jan 28, 2009, at 10:17 AM, Christian Vest Hansen wrote:


Or replicate could go away.

More likely, I think one of them could take multiple arities and make
the other obsolete.


I like "repeat" with multiple arities and remove "replicate".

--Steve



smime.p7s
Description: S/MIME cryptographic signature


proposal for shell-out: option to return articulated out, err, & exit code

2009-01-28 Thread Perry Trolard

Hi Users of Shell-out,

I'd sometimes like to have the exit status from system commands, so I
patched clojure.contrib.shell-out to accept a :verbose option which,
when turned on, returns a map with :exit, :out, & :err (where :exit's
value is the exit code int, & :out & :err name either byte arrays or
strings).

Anyone else have an interest in such a feature? In particular, would
the option be handy for lancet?

The modified sh function is below for reference, but I'll submit an
issue & patch to contrib if invited to.

Thanks,
Perry

(defn sh
  ; doc string elided
  [& args]
  (let [opts (parse-args args)
proc (.exec (Runtime/getRuntime)
(into-array (:cmd opts))
(as-env-string (:env opts))
(as-file (:dir opts)))
in-stream (.getInputStream proc)]
(when (:in opts)
  (with-open [osw (OutputStreamWriter. (.getOutputStream proc))]
(.write osw (:in opts
(let [stdout (.getInputStream proc)
  stderr (.getErrorStream proc)
  [[out err] combine-fn]
(if (= (:out opts) :bytes)
  [(for [strm [stdout stderr]]
(into-array Byte/TYPE (map byte (stream-seq strm
   #(into-array Byte/TYPE (concat %1 %2))]
  [(for [strm [stdout stderr]]
(apply str (map char (stream-seq
   (InputStreamReader. strm (:out
opts))
 str])
   exit-code  (.waitFor proc)]
  (if (:verbose opts)
{:exit exit-code :out out :err err}
(combine-fn out err)

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



Re: proposal for shell-out: option to return articulated out, err, & exit code

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 4:37 PM, Perry Trolard  wrote:
>
> I'd sometimes like to have the exit status from system commands, so I
> patched clojure.contrib.shell-out to accept a :verbose option which,
> when turned on, returns a map with :exit, :out, & :err (where :exit's
> value is the exit code int, & :out & :err name either byte arrays or
> strings).

Sounds good.  Is ':verbose' the base name for this option?  What about
':return-map'?  I'm okay with ':verbose' if we can't reach consensus
on something else.

> Anyone else have an interest in such a feature? In particular, would
> the option be handy for lancet?
>
> The modified sh function is below for reference, but I'll submit an
> issue & patch to contrib if invited to.

Please do.

--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
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: proposal for shell-out: option to return articulated out, err, & exit code

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 4:43 PM, Chouser  wrote:
>
> Sounds good.  Is ':verbose' the base name for this option?

Sorry for the typo.  "best name"

--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
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: nested maps

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 4:02 PM, Mark Volkmann
 wrote:
>
> Is this the best way to retrieve the employer city?
> (reduce get person [:employer :address :city])

That's the definition of 'get-in', but the -> suggestion sounds good too.

> Is this the best way to get a new map where the city is changed?
> (update-in person [:employer :address :city] (fn [old & args] "Clayton"))
> I can't get this to work with #("Clayton") in place of the anonymous
> function above.

You might like 'assoc-in' for this use case.

--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
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: Creating executable Jars?

2009-01-28 Thread luciofulci

That's how I managed to create jar:

I have folders c:\user\apps and c:\user\apps\classes (which can be
empty, but must exist) (beside clojure.jar and other jars) in
classpath.
I have a file:
c:\user\apps\my\hello.clj with this contents:

(ns my.hello
  (:gen-class))

(defn -main [] (println "Hello World!"))

I launch repl from the dir c:\user\apps and enter this command:
(compile 'my.hello)
and I have my compiled classes in c:\user\apps\classes\my
I unpack clojure.jar to c:\user\classes and delete a META-INF folder.
Then in this folder (c:\user\classes) I create manifest.txt:
Main-Class: my.hello

which ends with a newline.

after that I execute this command in the same folder (c:\user
\classes):
jar cmf manifest.txt hello.jar clojure my

And there I have an executable jar.

so when I run java -jar  hello.jar It prints out "Hello, world!".
That's it.

Well, I hope that helps...

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



Re: repeat and replicate

2009-01-28 Thread Shawn Hoover
On Wed, Jan 28, 2009 at 4:36 PM, Stephen C. Gilardi wrote:

>
> On Jan 28, 2009, at 10:17 AM, Christian Vest Hansen wrote:
>
> Or replicate could go away.
>
> More likely, I think one of them could take multiple arities and make
> the other obsolete.
>
>
> I like "repeat" with multiple arities and remove "replicate".
>
> --Steve
>
>
Me too. I'm just waiting for some hammer to drop about args ordering or
partial application or something...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: proposal for shell-out: option to return articulated out, err, & exit code

2009-01-28 Thread Perry Trolard

> Sounds good.  Is ':verbose' the best name for this option?  What about
> ':return-map'?  I'm okay with ':verbose' if we can't reach consensus
> on something else.

I agree that :verbose isn't right -- :return-map's not bad at all.

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



Loading two namespaces that :use each other.

2009-01-28 Thread CuppoJava

Hi,
I'm unused to managing file dependencies myself, and I'm lost as to
how to load two namespaces that reference each other.

I'm treating the (use) command as analagous to java's import command.
But I've run into problems trying to load this namespace:

Do I have to resort to manually separating the dependencies? And if
so, how would I go about doing that?

Thanks for your help
  -Patrick

--a.clj---
(ns a
  (:use b))

(defn afunc []
  (bfunc))

--b.clj--
(ns b
  (:use a))

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



Re: test-is: generating and processing testing data

2009-01-28 Thread Frantisek Sodomka

Oops, error. Sequence passed to 'are' cannot be evaluated => use
quoted list '( or quoted vector '[  ...

(are (= _1 _2)
  '(3 (+ 1 2)
0 (+ -1 1)))

Hm... Since 'are' is basically creating bunch of 'is' tests, I wonder
how to also add a description message for each test. Thinking along
the lines:

(are (= _1 _2)
  '(3 (+ 1 2) "should be 3"
0 (+ -1 1) "-x + x = 0"))

(are (is (= _1 _2) _3)
  '(3 (+ 1 2) "should be 3"
0 (+ -1 1) "-x + x = 0"))

(do-parse (is (= _1 _2) _3)
  '(3 (+ 1 2) "should be 3"
0 (+ -1 1) "-x + x = 0"))

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



Re: repeat and replicate

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 4:56 PM, Shawn Hoover  wrote:
>
> On Wed, Jan 28, 2009 at 4:36 PM, Stephen C. Gilardi 
> wrote:
>>
>>
>> I like "repeat" with multiple arities and remove "replicate".
>> --Steve
>
> Me too. I'm just waiting for some hammer to drop about args ordering or
> partial application or something...

+1 from me, for what it's worth.

(repeat obj) and (repeat n obj) look good.

--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
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: repeat and replicate

2009-01-28 Thread Jason Wolfe

> +1 from me, for what it's worth.

Ditto.  Every time I want replicate, I type "repeat", remember that it
only takes 1 arg, and then have to search for "replicate" because the
name just won't stick in my head.

-Jason
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: more readable IRefs

2009-01-28 Thread Rich Hickey



On Jan 28, 4:11 pm, Chouser  wrote:
> Currently if you happen upon a Ref in the REPL, you don't get much
> helpful information:
>
> user=> (ref #{:a 1})
> #
>
> Improving on this is not difficult:
>
> (defmethod print-method clojure.lang.IRef [o w]
>   (.write w (format "#<%...@%x: %s>"
> (.getSimpleName (class o))
> (System/identityHashCode o)
> (pr-str @o
>
> Now Ref and all her cousins print their values:
>
> user=> (agent 99)
> #
>
> The identity code is included so you can tell if it's the same object
> or a different one, since the identity of reference objects matter.
>
> user=> (let [a (atom 4)] (swap! a inc) (prn a) (swap! a + 10) (prn a))
> #
> #
>
> This is also why the #<> format is still used, disallowing 'read' from
> working on the string.
>

Patch welcome for this.

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
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: repeat and replicate

2009-01-28 Thread Rich Hickey



On Jan 28, 5:38 pm, Chouser  wrote:
> On Wed, Jan 28, 2009 at 4:56 PM, Shawn Hoover  wrote:
>
> > On Wed, Jan 28, 2009 at 4:36 PM, Stephen C. Gilardi 
> > wrote:
>
> >> I like "repeat" with multiple arities and remove "replicate".
> >> --Steve
>
> > Me too. I'm just waiting for some hammer to drop about args ordering or
> > partial application or something...
>
> +1 from me, for what it's worth.
>
> (repeat obj) and (repeat n obj) look good.
>

Patch welcome for this.

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
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: more readable IRefs

2009-01-28 Thread Timothy Pratley

Great! That's really handy.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Length of Sequence

2009-01-28 Thread Rich Hickey



On Jan 28, 2:19 pm, Chouser  wrote:
> On Wed, Jan 28, 2009 at 2:15 PM, Peter Wolf  wrote:
>
> > How do I get the length of a sequence?  Is there some generic way to
> > find the number of elements in something that might be list, map, vector
> > or lazy?
>
> user=> (doc count)
> -
> clojure.core/count
> ([coll])
>   Returns the number of items in the collection. (count nil) returns
>   0.  Also works on strings, arrays, and Java Collections and Maps
>
> Note how the name and docs both cleverly avoid use of the words "size"
> or "length", to help the function remain undiscovered by searches
> through the source code and by uses of find-doc.
>

Patch welcome for this - could mention it returns the length of
strings and arrays and the size of Java collections.

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
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: pretty-printing?

2009-01-28 Thread Tom Faulhaber

Yeah, I'll probably layer a pretty printer on top of my common lisp
format stuff sometime in the next month. I'm just just doing some
cleanup to cl-format to make it a tad more user friendly right now and
then I'll dig in on the pretty printing stuff.

I don't know if I'll go for the all out XP approach used in CL or not
yet. I don't think that all of it is fully applicable to Clojure. But
I am planning to make code printing be nice and have some support for
customization.

Tom

On Jan 27, 7:56 am, Mike DeLaurentis  wrote:
> Hi,
>
> Is anyone aware of a pretty-print function for Clojure? I saw there
> was some discussion about it on this thread a while ago, but I don't
> seem to see anything related to pretty-print in either the core or
> clojure-contrib. If no one's working on implementing it, I might take
> a stab at it.
>
> Thanks,
>
> Mike
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Length of Sequence

2009-01-28 Thread Peter Wolf

How about this?  Needlessly wordy to make it more search-able...

clojure.core/count
([coll])
  Returns the length of a list or vector, the number of keys in a map, 
the size of a string, or the number of items in a sequence or 
collection.  (count nil) returns 0.  Also works on Java Collections and 
Maps.


Rich Hickey wrote:
>
> On Jan 28, 2:19 pm, Chouser  wrote:
>   
>> On Wed, Jan 28, 2009 at 2:15 PM, Peter Wolf  wrote:
>>
>> 
>>> How do I get the length of a sequence?  Is there some generic way to
>>> find the number of elements in something that might be list, map, vector
>>> or lazy?
>>>   
>> user=> (doc count)
>> -
>> clojure.core/count
>> ([coll])
>>   Returns the number of items in the collection. (count nil) returns
>>   0.  Also works on strings, arrays, and Java Collections and Maps
>>
>> Note how the name and docs both cleverly avoid use of the words "size"
>> or "length", to help the function remain undiscovered by searches
>> through the source code and by uses of find-doc.
>>
>> 
>
> Patch welcome for this - could mention it returns the length of
> strings and arrays and the size of Java collections.
>
> 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
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: more readable IRefs

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 5:57 PM, Rich Hickey  wrote:
>
> On Jan 28, 4:11 pm, Chouser  wrote:
>>
>> Now Ref and all her cousins print their values:
>>
>> user=> (agent 99)
>> #
>
> Patch welcome for this.

Created issue with patch:

http://code.google.com/p/clojure/issues/detail?id=56

--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
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: "incremental" (sort of) clojure compilation

2009-01-28 Thread Laurent PETIT
I tried this, but it didn't seem to work :
; a/b/c.clj
(ns a.b.c)
(defn f [] :f)
(load "c1")

;a/b/c1.clj
(in-ns 'a.b.c)
(defn g [] :g)

;in REPL
user=>(let [real-load clojure.core/load]
  (binding [clojure.core/load (fn [f] (println "file loaded: " f) (real-load
f))] (compile 'a.b.c)))
file loaded:  a.b.c
a.b.c
user=>

??

2009/1/28 Christophe Grand 

>
> Laurent PETIT a écrit :
> >
> > Hi Laurent,
> >
> > Can't you rebind clojure.core/load to record all resources laoded
> > during
> > a namespace compilation?
> >
> >
> > Well yes, that seems indeed a good solution to another problem I'll
> > have to solve (dependency graph of files) -> thanks for anticipation
> > my next question :-)
> > But does it solve the problem I exposed ?
> >
> > Let's rephrase it : to force the recompilation of a lib, is there
> > another way than "touching" the lib's declaring file (so that if I
> > just make changes in a file loaded by the lib's declaring file, I'm
> > sure the lib is really recompiled) ?
> >
> Well, I answered your next question because, here, clojure.core/compile
> doesn't try to be smart and recompile the whole lib each time it is
> called. :-( (or :-) I don't know)
>
> Christophe
>
> >
>

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



Re: repeat and replicate

2009-01-28 Thread Timothy Pratley

> Patch welcome for this.

http://code.google.com/p/clojure/issues/detail?id=55&colspec=ID%20Type%20Status%20Priority%20Reporter%20Owner%20Summary

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



improved gview

2009-01-28 Thread kyle smith

I have improved on chouser's gview code (http://blog.n01se.net/?
p=30).  It can now expand java.awt.Container objects.  I haven't
implemented this, but it would be nice to pass in a function to filter
leaves/nodes.

(defn container? [obj]
  (instance? (. (java.awt.Container.) getClass) obj))

(ns gview
  (:import (javax.swing JFrame JScrollPane JTree)))

(defn- make-node
  ([parent obj]
 (if (container? obj)
   (make-node parent obj #'identity #(. %1 getComponents))
   (make-node parent obj #'coll? #'seq)))
  ([parent obj ischildfn getchildfn]
   (proxy [javax.swing.tree.TreeNode] []
 (toString []  (pr-str obj))
 (getAllowsChildren [] (ischildfn obj))
 (getChildAt [i]   (make-node this (nth (getchildfn obj)
i)))
 (getChildCount [] (count (getchildfn obj)))
 (getIndex [n] -1)
 (getParent [] parent)
 (isLeaf [](not (ischildfn obj))

(defn gview [obj]
  (doto (JFrame.)
(.add (JScrollPane. (JTree. (make-node nil obj
(.setTitle (str "gview: " (.getName (class obj
(.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
(.pack)
(setVisible true)))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Learning Clojure

2009-01-28 Thread Timothy Pratley

On Jan 29, 6:03 am, janus  wrote:
> While reading Programming Clojure the other night I found this code
> interesting (+), however, when I tried out (-) I got my fingers burnt.
> Why this? Or did I do something wrong which has nothing to do with
> the  code in question?

You didn't do anything wrong, there is a definition of + with no
arguments which just returns 0, but no definition of - with no
arguments. Similarly (*) is defined as 1, but (/) is undefined. I
guess there is no such thing as negative 0, then again there is no
such thing as positive zero! Why would you call these functions like
this with no arguments?


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



Re: Learning Clojure

2009-01-28 Thread Stephen C. Gilardi


On Jan 28, 2009, at 6:48 PM, Timothy Pratley wrote:


You didn't do anything wrong, there is a definition of + with no
arguments which just returns 0, but no definition of - with no
arguments. Similarly (*) is defined as 1, but (/) is undefined. I
guess there is no such thing as negative 0, then again there is no
such thing as positive zero! Why would you call these functions like
this with no arguments?


One reason that the zero argument cases for + and * exist is to  
support smooth operation with a collection of numbers even when the  
collection is empty.


For example:

Clojure
user=> (defn sum-of-elements
  [coll]
  (apply + coll))
#'user/sum-of-elements
user=> (sum-of-elements [1 2 3])
6
user=> (sum-of-elements [])
0
user=>

Using the additive and multiplicative identity elements (of the set of  
numbers) for zero-argument cases for + and * seems natural and  
uncontroversial.


Not allowing the zero argument case for - and / is harder to  
understand. Here are some likely motivations:


	- 0 is both a "left identity element" and a "right identity element"  
for +, but is only a "right identity element" for -. The corresponding  
argument holds for 1 and /.

- + and * are commutative and - and / are not
- Clojure's behavior in this is consistent with Common Lisp

(see http://en.wikipedia.org/wiki/Identity_element)

Here's another argument in favor of this choice: consider how each  
function works with initial sequences of increasing lengths from an  
overall sequence of numbers. For "+" the value of the n argument  
addition is the value of an n-1 argument addition plus the nth element.


Let the sequence be [1 2 3 4 5 6 7 8 9]

(+) =>  0
(+ 1)   =>  1 = 0 + 1
(+ 1 2) =>  3 = 1 + 2
(+ 1 2 3)   =>  6 = 3 + 3
(+ 1 2 3 4) => 10 = 6 + 4
...

The same progression doesn't work for -:

(-) =>  0 (hypothetically)
(- 1)   => -1 = 0 - 1 (works for this case)
(- 1 2) => -1 does not equal -1 - 2

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Learning Clojure

2009-01-28 Thread Timothy Pratley

Thanks for the detailed explanation Steve!

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



Re: Simple Examples of Concurrency?

2009-01-28 Thread wubbie

Hi,

I see
(add-classpath (str "file://" (.getParent (java.io.File. *file*))
"/"))
in mire.clj.
What value of *file* is it? I failed to see *file* is assigned at all.

-thanks
sun



On Jan 27, 1:16 pm, Phil Hagelberg  wrote:
> Keith Bennett  writes:
> > I'm trying to wrap my head around Clojure's concurrency.  I'm new to
> > Lisp-like languages, and the examples that I've found are a bit
> > complex.
>
> > Can anyone point me to simple examples of how concurrency works in
> > Clojure?  (Not just one-liners, but examples that actually modify
> > values from multiple threads, and hopefully print out some helpful
> > information?
>
> Sure; I created a program called Mire to play with this.
>
> It's a multiplayer text adventure that uses refs to handle concurrent
> access to things like who is in which rooms and who can pick up which
> items. Since it's just dealing with text, it's still a very simple
> codebase (around 200 lines). I think it should be pretty understandable.
>
> https://github.com/technomancy/mire/tree
>
> It's not thoroughly documented, but if you find anything particularly
> confusing after reading and trying it out, feel free to ask about it.
> The bulk of the functionality is in commands.clj, with some boring
> server bits in mire.clj.
>
> It may not be the most idiomatic code as I haven't read that much
> Clojure code from other projects, so I'd be happy to get any suggestions
> on how to improve that.
>
> -Phil
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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.contrib.command-line patch: multiple option format

2009-01-28 Thread Chouser

On Wed, Jan 28, 2009 at 1:40 PM, Perry Trolard  wrote:
>
> Is there anything I can do to help get the proposed change above, or
> something like it, included in c.c.command-line? I'd be happy to
> modify the patch: removing the somewhat orthogonal alignment code,
> etc.

I've been conflicted over how to proceed with this lib -- thanks for
your patience.  With a few small changes I'd be happy to include this.

Please make the 'justify' fn (whatever you want to call it) private
for now so that it doesn't become another API to be maintained.  If it
proves to be more generally useful, it can be moved to a more
approriate lib later.

Printing the options as --(a|b) is rather unusual and likely to be
confusing.  More common appears to be like this line from "ls --help":

  -r, --reverse  reverse order while sorting

Please use something like this instead.  Showing double-dashes for
each option is probably fine for now.  If we want to allow combining
of multiple single-letter options without spaces between them later on
(which itself has questionable value) -- well, that's a question for
another time.

Finally, please don't include any commented-out lines in your final
patch.

Thanks so much for your help,
--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
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: test-is: generating and processing testing data

2009-01-28 Thread Stuart Sierra

Hi Frantisek,

I think I understand what you're looking for here, but I don't see how
to make it work. If "are" could be applied to a generated list, then
it would have to evaluate its arguments, which is a pretty fishy thing
for a macro to do. (But possible -- check out clojure.contrib.apply-
macro). Here's how I would write this sequence of assertions:

(deftest zeros-are-equal
  (doall (map (fn [[a b]] (is (= a b)))
  (combinations [0 0.0 0M] 2

To answer your other question, if you want a message on each
assertion, just use "is". That's why I've never been crazy about
"are", I feel like it encourages too much succinctness. You also lose
accurate line numbers in error reports.

But if you want, you can use "do-template" in
clojure.contrib.template, which is how "are" is implemented.

(deftest my-test
  (do-template (is (= _1 _2) _3)
4 (+ 2 2) "simple arithmetic"
5 (+ 2 2) "bad arithmetic"))

-Stuart Sierra



On Jan 28, 5:29 pm, Frantisek Sodomka  wrote:
> Oops, error. Sequence passed to 'are' cannot be evaluated => use
> quoted list '( or quoted vector '[  ...
>
> (are (= _1 _2)
>   '(3 (+ 1 2)
>     0 (+ -1 1)))
>
> Hm... Since 'are' is basically creating bunch of 'is' tests, I wonder
> how to also add a description message for each test. Thinking along
> the lines:
>
> (are (= _1 _2)
>   '(3 (+ 1 2) "should be 3"
>     0 (+ -1 1) "-x + x = 0"))
>
> (are (is (= _1 _2) _3)
>   '(3 (+ 1 2) "should be 3"
>     0 (+ -1 1) "-x + x = 0"))
>
> (do-parse (is (= _1 _2) _3)
>   '(3 (+ 1 2) "should be 3"
>     0 (+ -1 1) "-x + x = 0"))
>
> Frantisek
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



How come *file* is assigned to current (running) dir?

2009-01-28 Thread wubbie

Hi,

I saw (.getParent (java.io.File. *file*)) is resolved to parent
directory of current running directory.

java.io.File. is a constructor that takes *file* as an argument, but
I don't see *file* is assgned any value at all.
Is it related to the starup script?

The start-up script has clojure.main in it. What's the purpose of it?
Here it is:
java -cp $CLJ/clojure.jar:$CLJ/clojure-contrib.jar clojure.main src/
mire-tst.clj


thanks
sun

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



Re: two way benefits

2009-01-28 Thread Michael Wood

On Wed, Jan 28, 2009 at 5:24 PM, Christophe Grand  wrote:
>
> Mark Volkmann a écrit :
>> What are some benefits of allowing two ways of doing the following?
>>
[...]
>> There are two ways to invoke a constructor to create a Java object.
>> (def calendar (new GregorianCalendar 2008 3 16))
>> (def calendar (GregorianCalendar. 2008 3 16))
[...]
> The first way makes macros easier to write.
>
> eg:
>  `(new ~a-class) instead of (list (symbol (str (name a-class) \.)))
>
> The second way is just "syntax" sugar:
> user=> (macroexpand-1 '(Foo.))
> (new Foo)

Well, I prefer (new Foo) to (Foo.) anyway, because it's much harder to
miss "new" than it is to miss "." :)

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

2009-01-28 Thread Michael Wood

On Wed, Jan 28, 2009 at 6:52 PM, Laurent PETIT  wrote:
> Hello,
>
> Do you know if there is a clojure code formatter, written either in clojure
> or java ?

Have a look here:
http://groups.google.com/group/clojure/search?group=clojure&q=pretty+print&qt_g=Search+this+group

> It could take a string or InputStream/Reader or File as its input, and
> return a well formatted String/outputStream/Writer ?
>
> Indeed, I don't want to reinvent the wheel for clojure-dev, but if it is
> written in Python/Ruby/emacs lisp ... I'll need to do so, though ;-)

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

2009-01-28 Thread Laurent PETIT
Well, I asked this, because I was not sure whether a pretty-print function
is the same as a formatting function.
I thought of the former to have datastructures as its input -> thus working
only on well structured code, as the second would accept more "raw" text,
maybe not totally correct (missing parentheses, ...), thus being more
permissive, while still doing its best to format what it is presented with ?

2009/1/29 Michael Wood 

>
> On Wed, Jan 28, 2009 at 6:52 PM, Laurent PETIT 
> wrote:
> > Hello,
> >
> > Do you know if there is a clojure code formatter, written either in
> clojure
> > or java ?
>
> Have a look here:
>
> http://groups.google.com/group/clojure/search?group=clojure&q=pretty+print&qt_g=Search+this+group
>
> > It could take a string or InputStream/Reader or File as its input, and
> > return a well formatted String/outputStream/Writer ?
> >
> > Indeed, I don't want to reinvent the wheel for clojure-dev, but if it is
> > written in Python/Ruby/emacs lisp ... I'll need to do so, though ;-)
>
> --
> 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
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: Learning Clojure

2009-01-28 Thread Emeka
Thanks Steve and Tim.

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