fn? question

2010-04-04 Thread Manfred Lotz
Hi there, I can ask if something is an fn, like this: (fn? first) How do I do it when first is a string? Example: (def mylist '( map, first, nofun)) This doesn't work, of course: (map fn? mylist) How can I transpose, e.g. first to something so that I can feed fn? with it? --

Re: fn? question

2010-04-04 Thread Meikel Brandmeyer
Hi, On Sun, Apr 04, 2010 at 10:06:12AM +0200, Manfred Lotz wrote: I can ask if something is an fn, like this: (fn? first) How do I do it when first is a string? Example: (def mylist '( map, first, nofun)) This doesn't work, of course: (map fn? mylist) Of course it does. It

Re: fn? question

2010-04-04 Thread Per Vognsen
(map #(fn? (when-let [x (resolve (symbol %))] @x)) [map, first, nofun]) should do the trick. But before you go ahead and do this, make sure it's what you actually need. -Per On Sun, Apr 4, 2010 at 3:06 PM, Manfred Lotz manfred.l...@arcor.de wrote: Hi there, I can ask if something is an fn,

Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Bob Hutchison
Hi, I have a situation where: 1) I have a lot of 'values' that are both expensive to compute and quite large (they aren't all going to fit into memory) and most of which will not be needed (this time, but maybe later) 2) I may have a need to update several of them them (in a transaction)

Comparing NaNs to numbers: (= NaN x) should be false

2010-04-04 Thread Jouni K . Seppänen
This is with Clojure 1.1.0: user= ( Float/NaN 1.0) false user= (= Float/NaN 1.0) true Both comparisons should yield false. It seems that (= x y) is implemented by negating the result of ( y x), which is fine for totally-ordered sets, but unfortunately IEEE 754 floating-point numbers do not form

Re: Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Per Vognsen
Interesting question. Here's something I whipped up in response: http://gist.github.com/355456 I intentionally provide only lazy-alter and no lazy-ref-set. The reason is that lazy-alter can be coded so that all the unwrapping and rewrapping of delays can be abstracted away from the user-provided

Re: Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Bob Hutchison
On 2010-04-04, at 11:15 AM, Per Vognsen wrote: Interesting question. Here's something I whipped up in response: http://gist.github.com/355456 I intentionally provide only lazy-alter and no lazy-ref-set. The reason is that lazy-alter can be coded so that all the unwrapping and rewrapping

Re: fn? question

2010-04-04 Thread Manfred Lotz
Hi Per, On Sun, 4 Apr 2010 15:28:23 +0700 Per Vognsen per.vogn...@gmail.com wrote: (map #(fn? (when-let [x (resolve (symbol %))] @x)) [map, first, nofun]) should do the trick. But before you go ahead and do this, make sure it's what you actually need. -Per Thanks a lot. That was

Re: Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Bob Hutchison
On 2010-04-04, at 11:15 AM, Per Vognsen wrote: Interesting question. Here's something I whipped up in response: http://gist.github.com/355456 I intentionally provide only lazy-alter and no lazy-ref-set. The reason is that lazy-alter can be coded so that all the unwrapping and rewrapping

Re: Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Mark Engelberg
I don't understand why you need to get rid of the delay once it has been updated. Delays are cheap; why not just be consistent about having your data be a ref of a delay? It will keep your code simpler, and that's well worth it. -- You received this message because you are subscribed to the

Re: Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Per Vognsen
Rich has said that he intentionally didn't want to provide a uniform interface for setting and altering reference-like objects, and I agree with him. It wouldn't be difficult to have to have a function that calls send on agents, swap! on atoms, set! on vars and ref-set on refs. But it would give

Re: eclipse/counterclockwise/maven question

2010-04-04 Thread Stuart Halloway
Hmm. A this point am not using javac at all, just Clojure. So (in theory) I would expect to need a config setting on the clojure-maven- plugin instead. I'll give it a spin though! Stu Hi, On 01.04.2010, at 20:00, Stuart Halloway wrote: (2) When I import the project, the package explorer

Re: Would it be possible to make a dumped clojure, a la dumped emacs?

2010-04-04 Thread Remco van 't Veer
AFAIK, there's only one issue keeping the current master (and 1.1) from running on Dalvik: https://www.assembla.com/spaces/clojure/tickets/199-chunked-seqs-support--for--byte-code-can-t-be-converted-to-dex-for-dalvik So clone the 1.1.x branch from Rich and revert commit 306ef6 and it may just

Reorder a list randomly?

2010-04-04 Thread Linus Ericsson
Hello Clojure! Is there any straight-forward way to randomly reorder a list? ie: (randomize-list (list 1 2 3 4)) - (3 2 1 4) Regards, Linus Ericsson -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Reorder a list randomly?

2010-04-04 Thread Lee Spector
There's a shuffle function in seq-utils: user= (use 'clojure.contrib.seq-utils) nil user= (shuffle (list 1 2 3 4)) (3 4 1 2) -Lee On Apr 4, 2010, at 4:14 PM, Linus Ericsson wrote: Hello Clojure! Is there any straight-forward way to randomly reorder a list? ie: (randomize-list

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
The seq-utils library has a shuffle function that calls out to java.util.Collections. If you want to do it yourself, the easiest would be (defn naive-shuffle [xs] (let [v (vec xs)] (- (count v) range lex-permutations rand-elt (map v This uses the seq-utils and combinatorics libraries

Re: Reorder a list randomly?

2010-04-04 Thread Lee Spector
Since we're having a shuffle-a-thon, here's a version I wrote that I kind of like for its simplicity, even though it uses a recursive call that Clojure apparently can't optimize. (FWIW I wrote a version that used loop/recur instead, but it was actually slower for some reason): (defn shuffle

\ \ \= are valid in symbols?

2010-04-04 Thread Douglas Philips
(This is a follow up to my query last week, where upon I didn't fully connect these dots) According to: http://clojure.org/reader \ and \ are not in the valid list of sanctioned symbol characters. According to: http://richhickey.github.com/clojure/clojure.core-api.html

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
A quick test shows that it's about 3 times faster than my knuth-shuffle. Here's a version using transients that is 2x faster but still not quite as fast as yours: (defn rand-range [m n] (+ m (rand-int (- n m (defn swap-entries! [x i j] (assoc! x i (x j) j (x i))) (defn knuth-shuffle

Re: Leiningen integration?

2010-04-04 Thread Antony Blakey
For those interested in clojure maven, I've just published http://github.com/AntonyBlakey/polyglot-maven/tree/reflective-clojure-dsl , which is a clojure front-end for polyglot maven. It could do with more testing, and documentation, but apart from dealing with namespaces and attributes in the

Re: Reorder a list randomly?

2010-04-04 Thread Mark Engelberg
On my system, knuth-shuffle performs several times faster than Spector's recursive functional shuffle on smallish lists, and the difference grows even more dramatic as the list grows, which is what I'd expect (since knuth-shuffle is O(n) and shuffle is O(n^2)). -- You received this message

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
Wow, you're right. The partial laziness of his code was foiling my benchmark. -Per On Mon, Apr 5, 2010 at 11:05 AM, Mark Engelberg mark.engelb...@gmail.com wrote: On my system, knuth-shuffle performs several times faster than Spector's recursive functional shuffle on smallish lists, and the

Re: Reorder a list randomly?

2010-04-04 Thread Lee Spector
Ah -- maybe that foiled my timings too. I didn't expect it to be fast -- just clear (at least to this Lisp programmer). -Lee On Apr 5, 2010, at 12:11 AM, Per Vognsen wrote: Wow, you're right. The partial laziness of his code was foiling my benchmark. -Per On Mon, Apr 5, 2010 at 11:05

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
On Mon, Apr 5, 2010 at 11:33 AM, Lee Spector lspec...@hampshire.edu wrote: Ah -- maybe that foiled my timings too. I didn't expect it to be fast -- just clear (at least to this Lisp programmer). Embrace recursion combinators! They are warm and fuzzy! Here's a gist of the final cleaned up