Re: Easily add a Java Listener

2009-08-31 Thread Luc Prefontaine
It could be handy to have this shortcut implemented as you suggest. Solving ambiguities may be done through an explicit proxy or with some meta data to point to the proper method match. Luc On Mon, 2009-08-31 at 19:34 -0700, Timothy Pratley wrote: > If I understand correctly it could be impleme

Re: Easily add a Java Listener

2009-08-31 Thread Timothy Pratley
If I understand correctly it could be implemented with the following change to Reflector.java: static Object boxArg(Class paramType, Object arg){ if(paramType.isInterface() && arg instanceof IFn) return makeAProxy( findMethodMatch( paramType, arg ), arg ); Which would then

Re: Easily add a Java Listener

2009-08-31 Thread Luc Prefontaine
Hi guys, Am I missing something here? We define SWING listeners with proxies and find that it's already short in terms of code lines: (.addMouseListener (proxy [MouseAdapter] [] (mouseClicked [event] (if (= 2 (.getClickCount event)) (display-details (.locationToInde

Re: Java security code in Clojure

2009-08-31 Thread Timothy Pratley
The reason your byte-seq fails is because you coerce the int result to a byte before comparing to -1. You should compare the int result to -1 and coerce to a byte after: (defn byte-seq [rdr] (let [result (. rdr read)] (if (= result -1) (do (. rdr close) nil) (lazy-seq (cons (byte

Re: A complete documentation (downloadable)

2009-08-31 Thread John Harrop
On Mon, Aug 31, 2009 at 3:45 PM, freddi301 wrote: > > are there a complete clojure documentation ? There's the documentation at clojure.org; you could spider it with wget, though with some sites you need to spoof the user-agent and/or hack wget to disable retrieving robots.txt to do that. (Ethi

Re: vs. Python

2009-08-31 Thread John Harrop
On Mon, Aug 31, 2009 at 5:04 PM, Brian Hurt wrote: > On Sun, Aug 30, 2009 at 9:31 AM, Jason Baker wrote: > >> On Aug 30, 2:24 am, Dan Fichter wrote: >> > The Clojure version is more concise and radically safer but a little >> more >> > conceptually packed. Is it worth your trouble? >> >> Being

Re: vs. Python

2009-08-31 Thread John Harrop
On Mon, Aug 31, 2009 at 5:15 PM, Brian Hurt wrote: > If I recall correctly (and correct me if I'm wrong), Python uses a > reference counting garbage collector. Which means as soon as the reference > to the object goes away, the object gets collected and the handle closed. > Most JVMs use some fo

Re: Java security code in Clojure

2009-08-31 Thread Timothy Pratley
security=> (count byte-arr) 115 tprat...@neuromancer:~$ wc public.der 5 11 294 public.der your byte-seq does not do what the java version does :) On Aug 31, 9:19 pm, Sam Hughes wrote: > Hey, > > I'm trying to write a Clojure security library. My first step is > porting some working Java co

Re: Easily add a Java Listener

2009-08-31 Thread Christophe Grand
Rhino provides a similar facility https://developer.mozilla.org/en/Scripting_Java#JavaScript_Functions_as_Java_Interfaces but AFAIK it uses reflection. On Tue, Sep 1, 2009 at 12:03 AM, Kevin Downey wrote: > > I think this would necessitate an added layer of indirection and > reflection, which wou

Re: Easily add a Java Listener

2009-08-31 Thread Kevin Downey
I think this would necessitate an added layer of indirection and reflection, which would mean taking a performance hit. On Mon, Aug 31, 2009 at 2:54 PM, Stuart Sierra wrote: > > That's a clever trick.  How does the block know which interface method > was invoked? > -SS > > On Aug 31, 2:41 pm, rb

Re: Easily add a Java Listener

2009-08-31 Thread Stuart Sierra
That's a clever trick. How does the block know which interface method was invoked? -SS On Aug 31, 2:41 pm, rb wrote: > Hi, > > After using Jwt from Clojure, I did it with Jruby and discovered that > Jruby has what they call Closure Conversion (http://kenai.com/projects/ > jruby/pages/CallingJav

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Stuart Sierra
On Aug 31, 10:44 am, wangzx wrote: > I just want to learn clojure by using it to parse log file and > generate reports. and one question is: for a large text file, can we > use it as a sequence effectively? for example, for a 100M log file, we > need to check each line for some pattern match. Yo

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Laurent PETIT
Hello, Can you give the exact REPL session, with the exception you have, and also the clojure version you're using ? 8/31 wangzx > > I just want to learn clojure by using it to parse log file and > generate reports. and one question is: for a large text file, can we > use it as a sequence effec

Re: vs. Python

2009-08-31 Thread Brian Hurt
On Mon, Aug 31, 2009 at 9:03 AM, Konrad Hinsen wrote: > > > In this particular case, there is no reason to worry: open() returns a > file object that is fed to the method read(), but after that method > returns, there is no more reference to the object, so it is garbage > collected. Upon destructi

Re: STM article

2009-08-31 Thread sirpi
I remember a discussion about the Ant example in Lisp and Clojure, the response for Rich shows some important point that establishes the difference with a naive implementation of the Ant example. I think you can add a link to the Ant example and the incorrect Lisp implementation of it. http:/

Re: vs. Python

2009-08-31 Thread Brian Hurt
On Sun, Aug 30, 2009 at 9:31 AM, Jason Baker wrote: > > On Aug 30, 2:24 am, Dan Fichter wrote: > > The Clojure version is more concise and radically safer but a little more > > conceptually packed. Is it worth your trouble? > > Being primarily a Python programmer, I can say that the first thing

A complete documentation (downloadable)

2009-08-31 Thread freddi301
are there a complete clojure documentation ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderate

Re: Clojure for game programming?

2009-08-31 Thread hoeck
Hi, I'm using Clojure together with Processing and JBox2D to write small, 2D physics-powered games. The constraint given by JBox2D is, that the physics simulation has to be run in and only accessed from the same thread. So the whole game simulation is confined to the physics simulation thread and

Re: Java security code in Clojure

2009-08-31 Thread Sam Hughes
Hey Emeka, No problem. Yeah, the reason I used the above configuration is because it ultimately returned the same primitive byte array, to be passed into the X509EncodedKeySpec constructor. Sam On Aug 31, 1:27 pm, Emeka wrote: > Sorry, I was too quick. I misunderstood your code. > > Regards, >

Re: STM article

2009-08-31 Thread Mark Volkmann
On Mon, Aug 31, 2009 at 11:23 AM, Howard Lewis Ship wrote: > > Wow! That's a lot of great research.  I'm impressed. Thanks! > My only concern is that some of the internals *could* change over time > (I see Rich's commit stream) and some indication in the doc > identifying what's design level (wo

Re: STM article

2009-08-31 Thread Mark Volkmann
On Mon, Aug 31, 2009 at 1:10 PM, Lau wrote: > > Hey Mark, > > Congratulations on a very good article - I helped me get a lot of > facts straight. Thanks! > The final part of the article where you comment on the various > functions like > add-watcher etc, is not very insightful and the UML charts

Easily add a Java Listener

2009-08-31 Thread rb
Hi, After using Jwt from Clojure, I did it with Jruby and discovered that Jruby has what they call Closure Conversion (http://kenai.com/projects/ jruby/pages/CallingJavaFromJRuby#Closure_conversion ) where a Ruby block or closure is converted to an appropriate Java interface. From the wiki: "When

Re: Java security code in Clojure

2009-08-31 Thread Emeka
Sorry, I was too quick. I misunderstood your code. Regards, Emeka On Mon, Aug 31, 2009 at 6:10 PM, Emeka wrote: > > Hello Sam, > > From the Java version you used created array ,byte[] encodedKey = new > byte[(int) keyFile.length()];, but in clojure version you did (into-array > Byte/TYPE (byte-

Re: STM article

2009-08-31 Thread Lau
Hey Mark, Congratulations on a very good article - I helped me get a lot of facts straight. The final part of the article where you comment on the various functions like add-watcher etc, is not very insightful and the UML charts didnt help me all that much. But with such a small amount of critis

Re: Java security code in Clojure

2009-08-31 Thread Emeka
Hello Sam, >From the Java version you used created array ,byte[] encodedKey = new byte[(int) keyFile.length()];, but in clojure version you did (into-array Byte/TYPE (byte-seq stream)) , why not use make-array here. (byte-seq stream) returns list, is that the right argument for constructor call?

for those who just can't get enough of monads

2009-08-31 Thread Raoul Duke
http://patryshev.com/monad/crashcourse.pdf (via SVP) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Jonathan Smith
Ooh, or maybe not. I just reread and line-seq and read-lines should implement pretty much the same thing. (In the demo code it isn't clear to me where you are using line-seq.) Are you holding on to the head of the sequence somewhere? On Aug 31, 12:52 pm, Jonathan Smith wrote: > Look at clojure

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Jonathan Smith
Look at clojure-contrib/duck_streams.clj (specifically the read-lines function) I think it should be sufficiently lazy to do the job that you are looking for. (although I don't have any 100mb txt files to test with handy right now...) On Aug 31, 10:44 am, wangzx wrote: > I just want to learn c

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Adrian Cuthbertson
I mostly revert to good ole loop/recur for these large file processing exercises. Here's a template you could use (includes a try/catch so you can see errors as you go); (import '(java.io BufferedReader FileReader PrintWriter File)) (defn process-log-file "Read a log file tracting lines matchi

Re: STM article

2009-08-31 Thread Howard Lewis Ship
Wow! That's a lot of great research. I'm impressed. My only concern is that some of the internals *could* change over time (I see Rich's commit stream) and some indication in the doc identifying what's design level (won't change) vs. implementation level (might change) would be useful. On Sun,

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Krukow
On Aug 31, 4:44 pm, wangzx wrote: > Is there other APIs like the Sequence but provide stream-like API? You can try this, which I've used on short files recently: (defn #^Class class-identity [#^Class c] c) (defn #^java.io.BufferedReader reader-from-classpath [#^String s] (-> (. (class-ident

Two possible additions: non-reflective classobject calls & support for map-conj on arrays

2009-08-31 Thread Krukow
I have two minor minor suggestions for Clojure changes. 1) Consider this function: user> (set! *warn-on-reflection* true) true user> (defn reader-from-classpath [s] (-> (.getResourceAsStream java.lang.String s) (java.io.InputStreamReader.) (java.io.BufferedReader.))) Reflection warn

Re: Self-referencing map literals

2009-08-31 Thread Timo Mihaljov
On Mon, Aug 31, 2009 at 09:14:38AM -0400, Chas Emerick wrote: > > You could define your own let-like construct for this: > > > > > > (defmacro letmap [[m kvs & mkvs] & body] > > (if m > > `(let [~m {} > >~@(mapcat (fn [[k v]] `(~m (assoc ~m ~k ~v))) kvs)] > > (letmap ~mkvs

Qi in Clojure (Shen) project underway

2009-08-31 Thread Fogus
It looks like there is a thrust to rewrite Qi (http:// lambdassociates.org) in Clojure. With the impending departure of Dr. Mark Tarver the effort could use some help from the Clojure community. There has been discussion in the past few weeks at http://groups.google.co.uk/group/Qilang. Likewise

How to represents a Big text file using sequence?

2009-08-31 Thread wangzx
I just want to learn clojure by using it to parse log file and generate reports. and one question is: for a large text file, can we use it as a sequence effectively? for example, for a 100M log file, we need to check each line for some pattern match. I just using the (line-seq rdr) but it will ca

Re: vs. Python

2009-08-31 Thread Laurent PETIT
Usually the java libraries explicitly mention not to place OS resource handles on the finalize() method called by the GC, that why I had the reflex of thinking it was generally applicable to all languages with a GC. -- Laurent 2009/8/31 Konrad Hinsen > > On 31 Aug 2009, at 14:08, Laurent PETIT

Re: Self-referencing map literals

2009-08-31 Thread Chas Emerick
On Aug 31, 2009, at 6:56 AM, Achim Passen wrote: >> I would like to simplify it to something like: >> >> {:radius 20 >>:diameter (* 2 (% :radius)) >>:circumference (* pi (% :diameter))} >> >> where % is the map itself. > > You could define your own let-like construct for this: > > > (d

Re: vs. Python

2009-08-31 Thread Konrad Hinsen
On 31 Aug 2009, at 14:08, Laurent PETIT wrote: > [Python] > > open(filename, 'r').read() # who cares about closing files opened in > read-mode? > > "who cares about closing files opened in read-mode" ? > > I would say anybody concerned about blowing up the underlying OS if > not releasing fil

Re: vs. Python

2009-08-31 Thread B Smith-Mannschott
On Mon, Aug 31, 2009 at 14:08, Laurent PETIT wrote: > Hi, > > Just one point: > > 2009/8/30 Dan Fichter >> >> Read the contents of a file. >> >> [Clojure] >> >> (slurp filename) >> >> [Python] >> >> open(filename, 'r').read() # who cares about closing files opened in >> read-mode? > > "who cares

Re: vs. Python

2009-08-31 Thread Laurent PETIT
Hi, Just one point: 2009/8/30 Dan Fichter > Read the contents of a file. > > [Clojure] > > (slurp filename) > > [Python] > > open(filename, 'r').read() # who cares about closing files opened in > read-mode? > "who cares about closing files opened in read-mode" ? I would say anybody concerned

Java security code in Clojure

2009-08-31 Thread Sam Hughes
Hey, I'm trying to write a Clojure security library. My first step is porting some working Java code into Clojure. The Java and Clojure snippets below are more or less the same, but with the Clojure code, I'm getting: "java.security.InvalidKeyException: IOException: null [Thrown class java.securi

Re: Self-referencing map literals

2009-08-31 Thread Achim Passen
Hi! Am 31.08.2009 um 11:27 schrieb Timo Mihaljov: > I have some code that looks like this: > >(let [radius 20 > diameter (* 2 radius) > circumference (* pi diameter)] > {:radius radius > :diameter diameter > :circumference circumference}) > > I would like t

Re: Self-referencing map literals

2009-08-31 Thread Meikel Brandmeyer
Hi, On Aug 31, 11:27 am, Timo Mihaljov wrote: > When defining a map literal, is it possible to reference the map that is > being defined? I don't think this is possible. > I have some code that looks like this: > >     (let [radius 20 >           diameter (* 2 radius) >           circumference

Self-referencing map literals

2009-08-31 Thread Timo Mihaljov
When defining a map literal, is it possible to reference the map that is being defined? I have some code that looks like this: (let [radius 20 diameter (* 2 radius) circumference (* pi diameter)] {:radius radius :diameter diameter :circumference circu

Re: How do I add a new collection in Clojure?

2009-08-31 Thread Meikel Brandmeyer
Hi, On Aug 31, 1:35 am, "jonathan.arrender.sm...@gmail.com" wrote: > I was not sure from the documentation if conj, seq, etc are generic > functions (multimetiod functions). Is there any easy way to define > these for a new type? Shameless commercial: http://bitbucket.org/kotarak/lazymap/ This

Re: Unable to build a simple project with clojure-ant-tasks

2009-08-31 Thread Ivan Chernetsky
2009/8/31 J. McConnell : > The Ant tasks have only been tested against Clojure 1.0, since I assumed > that's what most people would be using in a production context. For my personal projects the HEAD version is stable enough. :) > I am > thinking about going the Contrib route and tagging a 1.0-