swing-utils: another set of helpers (was: Re: swing-utils: patch - returning the listeners)

2009-06-02 Thread Meikel Brandmeyer
Hi Stephen, uh? I didn't notice you put up a swing-utils in contrib. I have a set of little macros + helper, which might also be interesting: (import 'javax.swing.SwingUtilities) (defn do-swing* "Run the given thunk in the Swing event thread according to the given schedule. - :later =>

Re: subtractng sequence?

2009-06-02 Thread Christophe Grand
Wilson MacGyver a écrit : > More newbie questions. :) > > If I have two sequences as follow: > > (2 3 4 5 6 7 8 9 10) > (4 6 8 10) > > what's the best way to subtract the 2nd sequence from the first one? > Is the order of the second sequence important? If not: (defn subtract [a b] (remove (i

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Glen Stampoultzis
Actually considering I'm currently writing a game in clojure that contains a lot of state this _is_ a good real world example for me. Thanks very much Laurent. 2009/6/3 Laurent PETIT > > Hi, > > Here is an example of the implementation of the "Visitor" design > pattern in clojure. > Multimethod

subtractng sequence?

2009-06-02 Thread Wilson MacGyver
More newbie questions. :) If I have two sequences as follow: (2 3 4 5 6 7 8 9 10) (4 6 8 10) what's the best way to subtract the 2nd sequence from the first one? The best I can come up with was to do (first) on 2nd sequence and turn around and do a (remove) on the first sequence, etc until I

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Laurent PETIT
Hi, Here is an example of the implementation of the "Visitor" design pattern in clojure. Multimethods are sufficiently powerfull and there is nothing explictly named "xxVisitor" in the code example, since with clojure the Visitor pattern is a non-issue and solved by the more general multimethod c

Re: unit testing private methods?

2009-06-02 Thread Stuart Halloway
Hi Allen, You could write a function that uses the clojure.contrib.with-ns/with- ns macro to dip into the namespace being tested and return the private function, assigning it to a local name in the test namespace. I need this too, and have been meaning to ping the other Stuart about either

unit testing private methods?

2009-06-02 Thread Allen Rohner
I have a namespace with some public functions, and some private functions. I would like to write unit tests for the functions, and put them in a separate file from the main name space. I would also like to have an (ns) declaration in my tests file, because the tests require several libraries. Of c

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Glen Stampoultzis
Some good examples from everyone. Thank you. 2009/6/3 Richard Newman > > Some work in which I'm currently engaged uses ad hoc hierarchies for > dispatching on a handler and either a message method or a method and > response code. In the realm of HTTP clients -- imagine that the > response arriv

Re: filter on sequence

2009-06-02 Thread Vagif Verdi
On Jun 2, 7:55 am, Andrew Wagner wrote: > > You can use destructuring in your predicate's arg list: > >  Not to hijack the thread but...is there some reason clojure doesn't just > just call this pattern-matching? Is it different somehow? Pattern matching matches not only structure but also value

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Richard Newman
> I now write all my Java code without any types... and then realize I > have to go back and add them in later. Heh, very often I allow the IDE to fill them in, because I'm too lazy to type that much! --~--~-~--~~~---~--~~ You received this message because you are

Re: filter on sequence

2009-06-02 Thread Richard Newman
> Not to hijack the thread but...is there some reason clojure doesn't just > just call this pattern-matching? Is it different somehow? I guess the simplest answer is "because it's destructuring, not pattern-matching" :) As Rich explained in the thread to which Stephen linked, pattern matching (a

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Richard Newman
Some work in which I'm currently engaged uses ad hoc hierarchies for dispatching on a handler and either a message method or a method and response code. In the realm of HTTP clients -- imagine that the response arrives as a method invocation -- the equivalent would be writing something like (defm

Re: swing-utils: patch - returning the listeners

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 7:31 PM, Roland Sadowski wrote: May I suggest a small change in the add-*-listener functions in contrib.swing-utils? It's handy to have them return the listeners (and be able to disable/remove them later etc). Patch attached. Nice change, Roland. I see that you're on the li

swing-utils: patch - returning the listeners

2009-06-02 Thread Roland Sadowski
May I suggest a small change in the add-*-listener functions in contrib.swing-utils? It's handy to have them return the listeners (and be able to disable/remove them later etc). Patch attached. -Roland -- [ http://www.haltingproblem.net/ - my homepage ] --~--~-~--~~~

Re: how would I do this functionally? (internally mutable state)

2009-06-02 Thread ronen
As mentioned before, most file systems have the ability of providing callback to changes in files/directories, at SE 6 using this ability requires resorting to native code (JNA or JNI, see http://jnotify.sourceforge.net/) , in SE 7 this will be implemented in NIO 2 (http://java.sun.com/ developer

Re: filter on sequence

2009-06-02 Thread Tassilo Horn
Wilson MacGyver writes: Hi Wilson, > I saw that clojure has loop. But in other functional languages, using > loops are always discouraged. So I didn't know if loop was the > "clojure" idiomatic way of doing this. Clojure's `loop' (with `recur') is no "real" loop in an imperative sense. It's

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread CuppoJava
I now write all my Java code without any types... and then realize I have to go back and add them in later. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojur

Re: feature request: docstring for defstruct

2009-06-02 Thread thearthur
it would conform to "the clojure way". On Jun 2, 8:45 am, Sean Devlin wrote: > This would encourage documenting structs, so I think this is a good > idea. > > Sean > > On Jun 2, 11:31 am, Stuart Halloway wrote: > > > I would like to see defstruct take an optional docstring. Would such a   > > p

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Max Suica
people in math discussions raise their eyebrow at my new comma-less tuple and set notation: (a_1 a_2 ... a_n a_(n+1) .. ) in R^|N| {1 2 3 4 5} = {a in N+ | a < 6} Haskel hated it that time I wrote: fold:: (b a b) b [a] or sum x y & zs = fold (+) 0 x:y:zs, where: sum 1 2 3 4 5 6 7 => haskell

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
I see. very clever. I'm not used to loop constructs with no side effect. On Tue, Jun 2, 2009 at 12:21 PM, Konrad Hinsen wrote: >> I saw that clojure has loop. But in other functional languages, >> using loops are always discouraged. So I didn't know if loop >> was the "clojure" idiomatic way of

Re: filter on sequence

2009-06-02 Thread Andrew Wagner
The same is true of irrefutable patterns in haskell. > > The difference is that a pattern match can fail, and in that case > other patterns are tried. Clojure's destructuring assumes that the > value has the right structure. If it doesn't, then you will get an > exception thrown. > > --~--~-

Re: filter on sequence

2009-06-02 Thread Konrad Hinsen
On 02.06.2009, at 18:00, Wilson MacGyver wrote: > actually I had the exact same reaction. So I'd echo Andrew's comment. > Is this different than pattern-matching in say haskell/scala? The difference is that a pattern match can fail, and in that case other patterns are tried. Clojure's destruct

Re: filter on sequence

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 11:55 AM, Andrew Wagner wrote: Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? This thread has some info on that: http://groups.google.com/group/clojure/browse_frm/thread/0aa57ab265f7474a

Re: filter on sequence

2009-06-02 Thread Andrew Wagner
> > Why doesn't Ruby just call it destructuring like Lisp has been doing > for decades? ;) > > So that non-academics have a prayer at not getting scared away by an unnecessarily-technical name? --~--~-~--~~~---~--~~ You received this message because you are subscri

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 6:02 PM, Michael Wood wrote: > On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner wrote: >>> You can use destructuring in your predicate's arg list: >> >>  Not to hijack the thread but...is there some reason clojure doesn't just >> just call this pattern-matching? Is it differe

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner wrote: >> You can use destructuring in your predicate's arg list: > >  Not to hijack the thread but...is there some reason clojure doesn't just > just call this pattern-matching? Is it different somehow? Why doesn't Ruby just call it destructuring li

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
I saw that clojure has loop. But in other functional languages, using loops are always discouraged. So I didn't know if loop was the "clojure" idiomatic way of doing this. On Tue, Jun 2, 2009 at 11:52 AM, Konrad Hinsen wrote: >> My first reaction was to do it using a sequence. Is this the clojur

Re: filter on sequence

2009-06-02 Thread Stuart Halloway
Ditto what everyone else said, plus let's get rid of the duplicated call to Math/log by splitting the iterate into an iterate + a map: (take-while (fn [[_ second]] (< second 10)) (map (fn [x] [x (/ x (Math/log x))]) (iterate #(* % 2) 2))) Stu > > On 02.06.2009, at 17:35, Wilson

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
actually I had the exact same reaction. So I'd echo Andrew's comment. Is this different than pattern-matching in say haskell/scala? On Tue, Jun 2, 2009 at 11:55 AM, Andrew Wagner wrote: >> You can use destructuring in your predicate's arg list: >> > >  Not to hijack the thread but...is there som

Re: filter on sequence

2009-06-02 Thread Wilson MacGyver
ah, got it. thanks! On Tue, Jun 2, 2009 at 11:48 AM, Stephen C. Gilardi wrote: > > On Jun 2, 2009, at 11:35 AM, Wilson MacGyver wrote: > >> what I like to know is, how do I filter for with value b is < X > > > You can use destructuring in your predicate's arg list: > >        (filter (fn [[_ x]]

Re: filter on sequence

2009-06-02 Thread Michael Wood
On Tue, Jun 2, 2009 at 5:35 PM, Wilson MacGyver wrote: > > Apologies in advance on a very newbie question. > > I've constructed a sequence > > (take 10 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))]) [2 (/ 2 > (Math/log 2))]) > > doing a take 10 on it, produce the pairs I expect. > > what I li

Re: filter on sequence

2009-06-02 Thread Andrew Wagner
> > You can use destructuring in your predicate's arg list: > > Not to hijack the thread but...is there some reason clojure doesn't just just call this pattern-matching? Is it different somehow? --~--~-~--~~~---~--~~ You received this message because you are subscr

Re: filter on sequence

2009-06-02 Thread Konrad Hinsen
On 02.06.2009, at 17:35, Wilson MacGyver wrote: > for example, the first 10 produces. > > ([2 2.8853900817779268] [4 2.8853900817779268] [8 2.8853900817779268] > [16 3.8471867757039027] [32 5.7707801635558535] [64 9.233248261689365] > [128 15.38874710281561] [256 26.380709319112476] [512 > 46.166

Re: filter on sequence

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 11:35 AM, Wilson MacGyver wrote: what I like to know is, how do I filter for with value b is < X You can use destructuring in your predicate's arg list: (filter (fn [[_ x]] (< x 10)) *1) In English, the function takes an argument which can be accessed sequentia

Re: feature request: docstring for defstruct

2009-06-02 Thread Sean Devlin
This would encourage documenting structs, so I think this is a good idea. Sean On Jun 2, 11:31 am, Stuart Halloway wrote: > I would like to see defstruct take an optional docstring. Would such a   > patch be welcome? > > Stu --~--~-~--~~~---~--~~ You received thi

filter on sequence

2009-06-02 Thread Wilson MacGyver
Apologies in advance on a very newbie question. I've constructed a sequence (take 10 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))]) [2 (/ 2 (Math/log 2))]) doing a take 10 on it, produce the pairs I expect. what I like to know is, how do I filter for with value b is < X for example, the f

feature request: docstring for defstruct

2009-06-02 Thread Stuart Halloway
I would like to see defstruct take an optional docstring. Would such a patch be welcome? Stu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroup

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Stuart Halloway
People keep looking at me funny when I point out variables as code smells during code review... Stu > > Same here with the commas. Since I've been neck deep in Clojure, I've > been pathologically forgetting to add them with other languages. > > On Jun 2, 10:06 am, Shawn Hoover wrote: >> On Tu

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Stuart Halloway
Hi Glen, (1) Real-world example: I use polymorphism on the types of two different arguments to define implicit conversions: (defmulti coerce (fn [dest-class src-inst] [dest-class (class src-inst)])) (defmethod coerce [java.io.File String] [_ str] (java.io.File. str)) (defmethod coerce

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 8:59 AM, Chouser wrote: I'm never sure what the etiquette is for adding to other people's files in contrib, but please don't hesitate to add this to repl-utils on my account. Thanks again. I've checked in run*/run to clojure.contrib.repl-utils. Cheers, --Steve smime

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread tmountain
Same here with the commas. Since I've been neck deep in Clojure, I've been pathologically forgetting to add them with other languages. On Jun 2, 10:06 am, Shawn Hoover wrote: > On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid wrote: > > > On Fri, May 29, 2009 at 2:51 PM, Paul Stadig wrote: > > > Y

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Paul Stadig
On Tue, Jun 2, 2009 at 10:06 AM, Shawn Hoover wrote: > On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid wrote: > >> On Fri, May 29, 2009 at 2:51 PM, Paul Stadig wrote: >> > You meant to type disclosure, but instead you typed disclojure. >> > >> > Paul >> > >> How about when you try to write code in

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Shawn Hoover
On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid wrote: > > On Fri, May 29, 2009 at 2:51 PM, Paul Stadig wrote: > > You meant to type disclosure, but instead you typed disclojure. > > > > Paul > > > How about when you try to write code in other languages, and > reflexively place parentheses before f

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Laurent PETIT
2009/6/2 Michael Reid : > > On Fri, May 29, 2009 at 2:51 PM, Paul Stadig wrote: >> You meant to type disclosure, but instead you typed disclojure. >> >> Paul >> > How about when you try to write code in other languages, and > reflexively place parentheses before function/method names? > > (len 'F

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Laurent PETIT
2009/6/2 Stephen C. Gilardi : > > On Jun 2, 2009, at 8:59 AM, Chouser wrote: >> >> On Tue, Jun 2, 2009 at 7:49 AM, Stephen C. Gilardi >> wrote: >>> >>> On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote: That looks like a perfect candidate for clojure.contrib.repl-utils! >>> >>> Thanks! Af

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Michael Reid
On Fri, May 29, 2009 at 2:51 PM, Paul Stadig wrote: > You meant to type disclosure, but instead you typed disclojure. > > Paul > How about when you try to write code in other languages, and reflexively place parentheses before function/method names? (len 'Foo') <-- not valid Python. :( /mike.

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 8:59 AM, Chouser wrote: On Tue, Jun 2, 2009 at 7:49 AM, Stephen C. Gilardi wrote: On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote: That looks like a perfect candidate for clojure.contrib.repl-utils! Thanks! After a little more discussion, I'd like to put it in there.

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Meikel Brandmeyer
Hi, Am 02.06.2009 um 13:49 schrieb Stephen C. Gilardi: I see the tradeoffs as: possible negative: - an extra name in the namespace I don't see this as a big negative. I usually stick with the convention that the function is named after the macro with a star added. As in your example

Re: Spider with clojure

2009-06-02 Thread Sasa Ebach
Hi BG, > This seems to be an ideal use-case for Clojure Agents > http://clojure.org/agents This code is still a little too general for me. I guess if I stare at it long enough, I will eventually get it ;) > Try it out and share the code :) Will do, but I hope that someone has something more c

Re: STM & Resource transactions

2009-06-02 Thread Michael Reid
On Tue, Jun 2, 2009 at 8:12 AM, Robert Campbell wrote: > > I've been looking at using the clojure.set functions to create a > simple in-memory database cache. Basically when the app boost up, load > entire db into memory, work with it through the basic relational > algebra functions provided. Any

Re: ClojureCLR updated

2009-06-02 Thread Jeff Heon
On Jun 1, 1:57 pm, David Miller wrote: > It's important in that it means that the generated MSIL is not > completely junk, in that I'm not missing any important optimizations, > that I'm taking full advantage of type hints, avoiding reflection, > etc..  The JVM bytecodes are an important check fo

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Chouser
On Tue, Jun 2, 2009 at 7:49 AM, Stephen C. Gilardi wrote: > > On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote: >> >> That looks like a perfect candidate for clojure.contrib.repl-utils! > > Thanks! After a little more discussion, I'd like to put it in there. I'm never sure what the etiquette is f

STM & Resource transactions

2009-06-02 Thread Robert Campbell
I've been looking at using the clojure.set functions to create a simple in-memory database cache. Basically when the app boost up, load entire db into memory, work with it through the basic relational algebra functions provided. Any mutations (create/update/delete) would be wrapped in a simple fun

Re: Spider with clojure

2009-06-02 Thread Baishampayan Ghose
> just reading through the book (http://pragprog.com/titles/shcloj/ > programming-clojure) and having a lot of of fun learning. I was > wondering if there are any examples out there like Dave Thomas' > > A First Erlang Program > http://pragdave.pragprog.com/pragdave/2007/04/a_first_erlang_.html >

Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-06-02 Thread Stefan Hübner
Christian Vest Hansen writes: > On Mon, May 18, 2009 at 8:59 AM, Stefan Hübner > wrote: >> >> I've submitted the Maven bundle for Clojure 1.0.0 to >> http://jira.codehaus.org/browse/MAVENUPLOAD-2464. Processing the request >> might take a couple of days. > > The upload guide says four weeks. R

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Stephen C. Gilardi
On Jun 2, 2009, at 3:35 AM, Adrian Cuthbertson wrote: Thanks Steve! That's very neat. Pretty much a "canonical" macro example. You're welcome! I'm glad you like it. On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote: That looks like a perfect candidate for clojure.contrib.repl-utils! Thanks!

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Konrad Hinsen
On 02.06.2009, at 12:01, Glen Stampoultzis wrote: > I'm used to polymorphism in OO systems where everything in driven > from inheritance hierarchy. Clojures defmulti style polymorphism > seems powerful but has left me wondering how to most effectively > use it. I'm looking for some good r

Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-06-02 Thread Paul Stadig
I signed up and voted. Only took about 30 seconds. Thanks for the work everyone. I would love to see Clojure get into the Maven repo. Paul On Tue, Jun 2, 2009 at 6:04 AM, Stefan Hübner wrote: > > The upload bundle, which is found at > http://jira.codehaus.org/browse/MAVENUPLOAD-2464, promotes

Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-06-02 Thread Stefan Hübner
The upload bundle, which is found at http://jira.codehaus.org/browse/MAVENUPLOAD-2464, promotes Clojure as "org.clojure:clojure:1.0.0". It hasn't received any atention from the Upload team yet, but I do hope it gets uploaded within the next weeks. Maybe voting could speed it up... dysinger write

Good examples of defmulti polymorphism

2009-06-02 Thread Glen Stampoultzis
I'm used to polymorphism in OO systems where everything in driven from inheritance hierarchy. Clojures defmulti style polymorphism seems powerful but has left me wondering how to most effectively use it. I'm looking for some good real world examples of how people have used polymorphism in clojure

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Konrad Hinsen
On 02.06.2009, at 05:50, Stephen C. Gilardi wrote: > Here's a macro I've found useful for loading and running Clojure > programs from the REPL: > > (defmacro run > "Loads the specified namespace and invokes its \"main\" > function with optional args. ns-name is not evaluated." > [

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Adrian Cuthbertson
Thanks Steve! That's very neat. Pretty much a "canonical" macro example. Adrian. On Tue, Jun 2, 2009 at 5:50 AM, Stephen C. Gilardi wrote: > Here's a macro I've found useful for loading and running Clojure programs > from the REPL: > >  (defmacro run >    "Loads the specified namespace and invo