Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread atreyu
impenetrable for builtin curried functions and . operator as comp?? i dont think so, haskell can be hard to read but not for those reasons F. e. filter when the sum of elements are even: Prelude filter (even.sum) [[2,3],[3,3]] [[3,3]] i think is pretty readable ;-) On Nov 16, 2:19 am, Cyrus

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Ken Wesson
On Tue, Nov 16, 2010 at 3:23 AM, atreyu atreyu@gmail.com wrote: impenetrable for builtin curried functions and . operator as comp?? i dont think so, haskell can be hard to read but not for those reasons F. e. filter when the sum of elements are even: Prelude filter (even.sum)

Re: Performance of seq on empty collections

2010-11-16 Thread Laurent PETIT
2010/11/16 Meikel Brandmeyer m...@kotka.de Hi, On 16 Nov., 02:31, Ken Wesson kwess...@gmail.com wrote: Eh. I'd heard first and rest had replaced next. No? No. This was a misinformation. To elaborate a bit more on the differences pointed out by Sean: next returns nil if there are no

Re: bimaps in clojure

2010-11-16 Thread Christophe Grand
You can implement your own, prettu easily with deftype. However it can be tedious to track every methods, so we need a repl helper function to scaffold the code for us. (defn scaffold [iface] (doseq [[iface methods] (- iface .getMethods (map #(vector (.getName

Re: Performance of seq on empty collections

2010-11-16 Thread Meikel Brandmeyer
Salut Laurent, On 16 Nov., 09:51, Laurent PETIT laurent.pe...@gmail.com wrote: Agreed with the explanation, but ... 12% of what, exactly ? 6,502692ms / 7,393586ms ~ 0,88 = 12% improvement, no? But maybe this whole microbenchmarking story is paper waste. As I said: quick'n'dirty. Will now

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread atreyu
clojure is nice too for the example but if you'd add functions and they have arity more than 1 haskell gets better (imo of course): user (def concat2 (partial apply concat)) #'user/concat2 user ((comp (partial map (partial + 5)) concat2) (filter (comp even? sum) [[2 3] [3 3] [6 6]])) (8 8 11 11)

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Meikel Brandmeyer
Hi, On 16 Nov., 11:06, atreyu atreyu@gmail.com wrote: clojure is nice too for the example but if you'd add functions and they have arity more than 1 haskell gets better (imo of course): And less than 3 if one is honest. Haskell is spicked with rather unmotivated `foo` xs which simply

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread atreyu
Yep, you have to use flip and it is not so elegant Prelude let f x y z=(x+z)*y Prelude map (flip (f 1) 2) [3,4,5] [9,12,15] OTOH in clojure we have, you guess..., macros!!! user (- [[2 3][3 3][6 6]] (filter (comp even? sum)) concat2 (map #(+ 5 %))) (8 8 11 11) i promise i'll not comment about

Generating random regular graphs

2010-11-16 Thread Tiemo
Hi, I need to implement an algorithm to generate large random d-regular graphs. A d-regular graph is a graph in which all vertices have degree d. Specifically I need to generate large (1000+ vertices) 4-regular graphs. The algorithm I need to use is as follows: let V be a set of n vertices with

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Eric Schulte
Hi Paul, Thanks for sharing this. It seems like the best compromise between the desire to keep my code brief (at least to my eyes) without wanting to introduce my own custom function names for global functions. If you don't mind I'd like to add this to my fork of the Emacs Starter Kit (will

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Eric Schulte
atreyu atreyu@gmail.com writes: Yep, you have to use flip and it is not so elegant Prelude let f x y z=(x+z)*y Prelude map (flip (f 1) 2) [3,4,5] [9,12,15] OTOH in clojure we have, you guess..., macros!!! user (- [[2 3][3 3][6 6]] (filter (comp even? sum)) concat2 (map #(+ 5 %)))

Re: Function Design: sequence or argument?

2010-11-16 Thread Chris Maier
That makes sense... thanks, Meikel. Maybe my example of + wasn't the best, given its mathematical nature. Here's my situation: I'm writing some software to analyze some protein datasets, part of which entails generating a Venn diagram of their intersections. Each dataset has a unique name, and

Re: Function Design: sequence or argument?

2010-11-16 Thread Christophe Grand
Hi, On Tue, Nov 16, 2010 at 5:21 PM, Chris Maier christopher.ma...@gmail.comwrote: That makes sense... thanks, Meikel. Maybe my example of + wasn't the best, given its mathematical nature. Here's my situation: I'm writing some software to analyze some protein datasets, part of which

Re: Newbie question

2010-11-16 Thread Lee Hinman
On Fri, Nov 12, 2010 at 1:54 PM, labwor...@gmail.com wrote: Which natural language processing tools have you used that worked well with clojure? I've had good luck with clojure-opennlp - http://github.com/dakrone/clojure-opennlp However, I may be a bit biased since I wrote it :) - Lee --

Re: Newbie question

2010-11-16 Thread Lee Hinman
On Tue, Nov 16, 2010 at 9:34 AM, Lee Hinman matthew.hin...@gmail.com wrote: On Fri, Nov 12, 2010 at 1:54 PM,  labwor...@gmail.com wrote: Which natural language processing tools have you used that worked well with clojure? I've had good luck with clojure-opennlp -

Re: Generating random regular graphs

2010-11-16 Thread Ken Wesson
I took a stab at it: (defn make-verts [n] (zipmap (range n) (repeat []))) (defn free-legs? [m i d] ( (count (m i)) d)) (defn free-leg-indices [m n d] (filter #(free-legs? m % d) (range n))) (defn first-free-leg [m n d] (first (free-leg-indices m n d))) (defn random-free-leg [m n d]

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Eric Schulte
Just to follow up, I'm now using the following to pretty up Clojure code in Emacs #+begin_src emacs-lisp ;; symbols for some overlong function names (eval-after-load 'clojure-mode '(font-lock-add-keywords 'clojure-mode (mapcar (lambda (pair) `(,(car pair)

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Alan
Ask on #clojure about this. Someone (hiredman, I think?) has a macro that rewrites code using some funky unicode characters. I can't find it at the moment, but it might be what you're looking for. On Nov 16, 9:51 am, Eric Schulte schulte.e...@gmail.com wrote: Just to follow up, I'm now using the

Re: Function Design: sequence or argument?

2010-11-16 Thread Vagif Verdi
On Nov 15, 8:52 am, Chris christopher.ma...@gmail.com wrote: If you have a function that needs to treat multiple arguments as a group, what forces drive you to represent this as a single sequence argument vs. an argument?  To give a concrete example, why does + work like (+ 1 2 3 4)

Re: Generating random regular graphs

2010-11-16 Thread Mark Engelberg
I think the simplest and most efficient way to simulate the random connection process in a functional manner is to start by generating a shuffled list of d copies of each vertices (this represents the d legs for each vertex), and then pair them up using partition. At this point you have a list of

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Paul Hobbs
Hi Eric, Looks good; nice job with complement too. Of course you can add it to the Emacs Starter Kit ;-) -- Paul Hobbs On Tue, Nov 16, 2010 at 9:51 AM, Eric Schulte schulte.e...@gmail.comwrote: Just to follow up, I'm now using the following to pretty up Clojure code in Emacs #+begin_src

Re: Generating random regular graphs

2010-11-16 Thread Tiemo
That is really nice thank you. I'd have to take a real hard look at it, to see whether or not it's the exact algorithm I need, but nonetheless, you pointed me in the right direction. The code I produced was a mess of mutable state and loops. Thank you very much! On Nov 16, 6:29 pm, Ken Wesson

Re: Generating random regular graphs

2010-11-16 Thread Tiemo
This is also a nice idea. I will take a look at both implementations. On Nov 16, 8:16 pm, Mark Engelberg mark.engelb...@gmail.com wrote: I think the simplest and most efficient way to simulate the random connection process in a functional manner is to start by generating a shuffled list of d

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Alan
Found it. See https://github.com/hiredman/odds-and-ends/blob/8a84e6ddbad9d71f714ba16c3e1239633228a7eb/functional.clj#L94 On Nov 16, 10:06 am, Alan a...@malloys.org wrote: Ask on #clojure about this. Someone (hiredman, I think?) has a macro that rewrites code using some funky unicode

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Paul Hobbs
Huh. Isn't a unicode composition symbol harder to type than comp? If it's for readability, I'd rather go with the emacs hacks. On Tue, Nov 16, 2010 at 11:54 AM, Alan a...@malloys.org wrote: Found it. See

Re: shorter alternatives for `comp' and `partial'

2010-11-16 Thread Alan
Well, it would be harder for *me* to type. I imagine Hiredman has these symbols bound to some short but little-used key sequences. If you're not using your C-c letter bindings for anything else, you can pick four of them and use them for this. On Nov 16, 12:13 pm, Paul Hobbs

Re: Being not Lisp is a feature?

2010-11-16 Thread Daniel Gagnon
I spoke to the guys on reddit. They said it is tongue-in-cheek. They have no knowledge of functional programming but strongly feel it isn't suited to their field. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Being not Lisp is a feature?

2010-11-16 Thread lprefontaine
Daniel Gagnon redalas...@gmail.com wrote .. I spoke to the guys on reddit. They said it is tongue-in-cheek. They have no knowledge of functional programming ??? but strongly feel it isn't suited to their field. ??? Isn't this a bit contradictory ? It's ok to follow your own gut

Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread Alyssa Kwan
I ran into this while working on making functions durable. Here's a contrived example: = (defn a ([x] x) ([x y] (+ (a x) (a y #'user/a = (a 1 2) 3 = (def b a) #'user/b = (b 1 2) 3 = (defn a [x] (- x)) #'user/a = (b 1 2) -3 Is this what people expect? I would think that

Re: Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread Lee Spector
On Nov 16, 2010, at 5:26 PM, Alyssa Kwan wrote: Is this what people expect? I would think that the original definition of a, which is self-referencing, should point to itself no matter what it's named, not get resolved at invoke-time to see what the var is currently resolving to. I'm

Re: Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread David Nolen
But that would destroy one of the most useful features Lisp has to offer, interactive coding. Live coding would be impossible w/o this behavior as you would need to find and update all callers. Yuk. David On Tue, Nov 16, 2010 at 5:26 PM, Alyssa Kwan alyssa.c.k...@gmail.comwrote: I ran into

Passing arguments from clojure to java

2010-11-16 Thread unst...@gmail.com
This seems like such an obvious question, but I can't seem to find the answer anywhere. I don't understand why this would not be included in the java_interop section of the clojure documentation. Is it possible to pass a clojure vector to a java function that requires a java vector as an

Re: Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread David Sletten
On Nov 16, 2010, at 5:26 PM, Alyssa Kwan wrote: I ran into this while working on making functions durable. Here's a contrived example: = (defn a ([x] x) ([x y] (+ (a x) (a y #'user/a = (a 1 2) 3 = (def b a) #'user/b = (b 1 2) 3 = (defn a [x] (- x))

Re: Passing arguments from clojure to java

2010-11-16 Thread Alan
This is because java vectors are disgusting and not part of the Collections framework. Clojure vectors do implement Collection, and indeed List, but that is different from Vector. However, Vector was hacked up a bit after Collections were released to make it a little more forward compatible:

Re: Passing arguments from clojure to java

2010-11-16 Thread David Sletten
On Nov 16, 2010, at 5:49 PM, unst...@gmail.com wrote: This seems like such an obvious question, but I can't seem to find the answer anywhere. I don't understand why this would not be included in the java_interop section of the clojure documentation. Is it possible to pass a clojure vector

fastest way to remove nils

2010-11-16 Thread Glen Rubin
What is the fastest way to remove nils from a sequence? I usually use the filter function, but I see there are other functions like remove that should also do the trick. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email

Re: fastest way to remove nils

2010-11-16 Thread lprefontaine
user= (time (filter identity [ nil 1 2 nil 4])) Elapsed time: 0.053219 msecs (1 2 4) user= (time (remove nil? [ nil 1 2 nil 4])) Elapsed time: 0.065092 msecs (1 2 4) Choose the flavor your prefer... Luc P. Glen Rubin rubing...@gmail.com wrote .. What is the fastest way to remove nils from a

Re: fastest way to remove nils

2010-11-16 Thread Miki
user= (time (remove nil? (repeat 100 nil))) Elapsed time: 0.079312 msecs () user= (time (filter identity (repeat 100 nil))) Elapsed time: 0.070249 msecs () Seems like filter is a bit faster, however YMMV On Nov 16, 4:48 pm, Glen Rubin rubing...@gmail.com wrote: What is the fastest way

Re: fastest way to remove nils

2010-11-16 Thread Stuart Campbell
On 17 November 2010 12:37, lprefonta...@softaddicts.ca wrote: user= (time (filter identity [ nil 1 2 nil 4])) Elapsed time: 0.053219 msecs (1 2 4) user= (time (remove nil? [ nil 1 2 nil 4])) Elapsed time: 0.065092 msecs (1 2 4) Choose the flavor your prefer... Luc P. Those aren't

Re: fastest way to remove nils

2010-11-16 Thread Mark Engelberg
(keep identity l) is preferable to (filter identity l) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first

Re: bimaps in clojure

2010-11-16 Thread Sunil S Nandihalli
Thanks Christopher Grand. I really like your scaffold .. would be extremely handy .. Like david suggested .. it would be a perfect candidate for inclusion in the clojure.repl Regarding your bimap implementation, in terms of complexity, I feel, it will be linear in the number of elements, when

Re: fastest way to remove nils

2010-11-16 Thread lprefontaine
Oups.. :) Stuart Campbell stu...@harto.org wrote .. On 17 November 2010 12:37, lprefonta...@softaddicts.ca wrote: user= (time (filter identity [ nil 1 2 nil 4])) Elapsed time: 0.053219 msecs (1 2 4) user= (time (remove nil? [ nil 1 2 nil 4])) Elapsed time: 0.065092 msecs (1 2 4)

Re: fastest way to remove nils

2010-11-16 Thread lprefontaine
Re-oups, Clojure 1.0 to 1.2 upgrade glitch :) Mark Engelberg mark.engelb...@gmail.com wrote .. (keep identity l) is preferable to (filter identity l) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: bimaps in clojure

2010-11-16 Thread Mark Engelberg
On Tue, Nov 16, 2010 at 7:18 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Thanks Christopher Grand. I really like your scaffold .. would be extremely handy .. Like david suggested .. it would be a perfect candidate for inclusion in the clojure.repl Regarding your bimap

Re: Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread Alyssa Kwan
Notice that when I redefined a, I only included one arity. If b were updated with the fn that a was redefined to, then (b 1 2) should have thrown an exception. Instead, it used the old definition of a but within that definition pointed to the new definition of a. This is internally

Re: bimaps in clojure

2010-11-16 Thread Ken Wesson
On Tue, Nov 16, 2010 at 10:18 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Thanks Christopher Grand. I really like your scaffold .. would be extremely handy .. Like david suggested .. it would be a perfect candidate for inclusion in the clojure.repl Regarding your bimap

Ghost Vars?

2010-11-16 Thread Alyssa Kwan
ns-unmap isn't typically used. But for durability, we can think of JVM shutdown/startup as unmapping everything and starting fresh. Therefore, expected behavior for ns-unmap should be the same as behavior for deserializing and loading an object after a new JVM startup. Here's another issue I ran

Re: Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread David Nolen
On Tue, Nov 16, 2010 at 10:52 PM, Alyssa Kwan alyssa.c.k...@gmail.comwrote: In any case, I am using Github master and I thought I was using 1.2. 1.2 has self-references lexically bound, as David Sletten points out, which I agree is the correct behavior. But something has happened on 1.3

Re: Dynamic Binding of Self-Referencing Functions Expected Behavior?

2010-11-16 Thread David Sletten
Ok, now I get it. The results you included weren't a hypothetical example, you were simply using a different version of Clojure. So in your 1.3 version, the second (b 1 2) does return -3? Are the macro expansions of 'defn' different? Have all good days, David Sletten On Nov 16, 2010, at

Add method implementations to proxy

2010-11-16 Thread Mark Rathwell
So I get an instance of AbstractComponent ( http://www.igniterealtime.org/builds/tinder/docs/latest/javadoc/org/xmpp/component/AbstractComponent.html) with the function below, overriding the necessary methods: (defn get-component returns a new component instance with the specified values

Re: Add method implementations to proxy

2010-11-16 Thread Liam
Would this help? http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/update-proxy -- 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: Add method implementations to proxy

2010-11-16 Thread Liam
More information from Rich himself about update-proxy when he first introduced it. Could not find examples for you except from the Joy of Clojure book on page 273, but it is very trivial... just like the doc string sounds.

Re: bimaps in clojure

2010-11-16 Thread Christophe Grand
On Wednesday, November 17, 2010, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Regarding your bimap implementation, in terms of complexity, I feel, it will be linear in the number of elements, when accessing the pair via the value .. Is that true? No I use two maps and rmap is O(1) so