On Jan 3, 2:50 pm, Chouser wrote:
> (def v1 [1 2])
> (def l1 '(1 2))
...
> But as noted originally, hashes are a bit more strict than Clojure =:
>
> (= v1 l1) ==> true
> (get (hash-map v1 :found) l1) ==> nil
>
> You can see why by calling the 'hash' function directly:
>
> (hash v1) ==> 994
> (
> However, it is a Java *contract* [1] that
> (.equals x y) ==> (== (.hashCode x) (.hashCode y)) and currently
> Clojure data structures violate this contract:
> [1]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#hashCode()
And, while on this subject, it's also worth pointing out t
Nope, I have not sent in a CA yet. I'll do it sometime this week.
Now that I think about it some more, though, this change doesn't
really address the whole problem.
; Time to queue up and dequeue a bunch of elements
user> (doseq [n '(10 100 1000 1 10)]
(do (prn n)
(t
>
> Have you considered using clojure.lang.PersistentQueue instead of
> vector and subvec?
Indeed, I am using that, thanks. (I happened to stumble across an
earlier newsgroup post on this subject). Maybe all of the useful conj/
subvec usage patterns for vectors can be served by PersistentQue
Thanks a lot for your very detailed response Chouser! report-seq is a
very useful way to look at this stuff.
> ...
> Unless I've completely misunderstood your scenario, I think this
> demonstrates that the seq abstraction as it currently exists is
> sufficient for providing the kind of laziness
Hey Aria,
Here's my (not functional) but reasonably fast (Knuth) shuffle I've
been using.
(defn random-permutation [s]
"Return a random permutation of this seq."
(let [arr (to-array s) len (alength arr)]
(dotimes [i (dec len)]
(let [r (+ i (rand-int (- len i))),
prev (a
For mapping across maps I often find the following utility helpful:
(defn map-map "Like map, but expects f to produce pairs that are
combined to produce a map output."
[f & maps] (reduce #(conj %1 %2) {} (apply map f maps)))
1:1 user=> (map-map (fn [[k v]] [k (str v " Mark")]) {:greet
"hello"
Hi all,
I've got lots of utilities that I think people might find useful, and
might fit well in clojure.contrib (just sent in my contrib agreement
last week). I don't know how the process works to get code in there,
but I figured I'd go ahead and post them all here so people can chime
in about wh
> > (defn map-when "Like map but discards logically false entries"
> > [fn & seqs]
> > (filter identity (apply map fn seqs)))
>
> I'd use map-when.
>
> > (defn iterate-while [f x]
> > (take-while identity (iterate f x)))
>
> This one too.
>
> It raises a question, though -- how much functionali
I've got Clojure profiling working fairly easily using the free pre-
release build of YourKit [1], and it's already been a big help in
speeding up my application (I'll post on my blog about this soon).
The main difficulty has been figuring out which functions are which in
the output, since the onl
On Jan 13, 1:42 pm, Chouser wrote:
> One of the things I found difficult with CL was the extremely large
> number of builtin functions -- a large vocabulary with subtle
> differences between nearly synonymous-sounding words. It meant that
> at first glance, a particular block of could would look
On Jan 14, 10:10 am, Chouser wrote:
> I also think it's unhelpful for codebases to stray further from the
> builtin functions than needed, because it makes that code harder to
> read as well. So I will consider each of these more carefully.
Thanks for your detailed response! To keep this manag
> Sigh, I wish the API docs were more helpful in this case.
>
> clojure.core/seq?
> ([x])
> Return true if x implements ISeq
>
> It's asking a lot from me to know whether vectors implement ISeq.
If you don't know, you can always just ask the language :)
user> (ancestors (class [1 2 3]))
#{cloju
>>> user> (= '(1) [1])
>>> true
>>
>>> user> (= '() [])
>>> false
>>
>> Hm. That does seem rather odd.
>
> Fixed - svn 1208.
Oh, I always assumed this was intentional ... I guess I never tried
switching the order of arguments. Well, that makes a bit more sense
then :).
--~--~-~
I've already posted here [1] and on the issue board [2] about
hashing. In particular, .hashCode for seqs/colls break the Java
contract that whenever (.equals x y), (= (.hashCode x) (.hashCode
y)). (let x = [1] and y = (seq [1])). As I've mentioned earlier, I
hope that eventually .hashCode and .
> I don't see why the built-in concat couldn't be defined like yours.
OK, great. I then ask that the core concat be changed to
(defn my-concat [& args]
(when (seq args)
(lazy-cat (first args) (my-concat (rest args)
which has more or less the desired effect:
user> (take 0 (apply my
On Jan 14, 12:07 pm, "Michael Harrison (goodmike)"
wrote:
> But I'm not afraid of using reduce, map, and apply to prepare values
> to use as arguments to built-ins. And I'm not afraid to encapsulate
> this into my own functions when I need to. I'm OK with building up a
> bit of a language for wha
Er, oops, forgot you can't HTML here.
Anyway, the upshot is that now
user=> (import '(java.util ArrayList))
nil
(doseq [s ['(1 2) (seq '(1 2)) [1 2] (seq [1 2]) (ArrayList. [1
2])]]
(print "\n" (.hashCode s))
(doseq [t ['(1 2) (seq '(1 2)) [1 2] (seq [1 2]) (ArrayList. [1
2])]]
(print "\
Update: Rich just fixed this in http://code.google.com/p/
clojure/issues/detail?id=37&colspec=ID%20Type%20Status%20Priority
%20Reporter%20Owner%20Summary">svn 1215 .
-Jason
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Gro
On Jan 14, 6:01 pm, Jason Wolfe wrote:
> I've already posted here [1] and on the issue board [2] about
> hashing. In particular, .hashCode for seqs/colls break the Java
> contract that whenever (.equals x y), (= (.hashCode x) (.hashCode
> y)). (let x = [1] and y = (se
> > Instead the first three might suggest corollaries:
> > map-when map-when-not map-while
>
> Perfect.
>
On second thought, do you think map-when-not would actually be
useful? Unless you're interested in the difference between nil and
false, I think it's equivalent to (replicate (count (remove
> >unquotewould not be defined by Clojure, so still an error if allowed
> > to get evaluated.
>
> > Things like your sql would be macros that handled (unquotex)
> > internally.
>
> SVN 1184 implements this.
>
> Feedback welcome on its utility for macro writers.
>
> Rich
I like this a lot. Any c
On Jan 14, 1:03 pm, Jason Wolfe wrote:
> > > (import '(java.util HashSet))
> > > (defn distinct-elts? "Are all of the elements of this sequence
> > > distinct? Works on infinite sequences with repititions, making it
> > > useful for, e.g., detecting
I was doing some microbenchmarking earlier, and I noticed some very
very weird anomalies. If anyone could shed some light on what's
going on that would be awesome. (I'm using the latest SVN, and have
verified this on a totally clean repl).
Simplified as much as possible, the heart of what I obs
> SVN 1216 - thanks for the report.
Thanks for the quick fix!
-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 fr
> > > (defn maximal-elements [f s]
> > > "Return a seq of elements of s maximizing (f elt)."
> > > (when (seq s)
> > > (loop [max-elts (first s),
> > > max-val (f (first s)),
> > > rest-elts (rest s)]
> > > (if (empty? rest-elts)
> > > max-elts
> > > (
> That's a good idea. It would nicely complement the other
> functions so far. Please find attached a patch.
>
> 1:1 user=> '~x
> (clojure.core/unquote x)
> 1:2 user=> '~...@x
> (clojure.core/unquote-splicing x)
>
> Sincerely
> Meikel
Sweet, thanks Meikel! Rich, what do you think about integrati
I've been doing some OO-type Clojure programming, and have run into
the following (quite minor) annoyance:
I've defined a struct with a :class of ::Foo in namespace
my.long.namespace.foo.
In another namespace my.long.namespace.bar, I want to define a
subclass of this struct.
In this namespace, I
A couple more updates to these:
> (defn random-permutation [s]
> "Return a random permutation of this seq."
> (let [arr (to-array s) len (alength arr)]
> (dotimes [i (dec len)]
> (let [r (+ i (rand-int (- len i))),
> prev (aget arr i)]
> (aset arr i (aget arr r))
gt; (using alter-meta!) and tagging instances as described in existing Clojure
> literature you can provide functions to shuffle away the annoyance of
> dealing with keywords and their namespaces entirely.
>
> On Mon, Jan 19, 2009 at 7:29 PM, Jason Wolfe wrote:
>
> > I've been doin
> I'm sorry, Jason, I really thought I answered this the first time you
> asked. But I can't find any such answer in the archives, so I must
> have been mistaken.
No worries, thanks for all your help with this.
>> I can try to make patches for the changes in core, and/or improve
>> and document
> And, lest you think that confusing = and .equals is just a noobie
> mistake, let me point out what seems to be a bug in
> PersistentHashMap.java I just found based on this same confusion. In
> particular, Objects are located in the map using Clojure's hash
> function, which is equivalent to .ha
I ran into a situation in my application where I wanted to take a set-
difference between a small set and a large set. In this circumstance,
clojure.set/difference is needlessly slow. Because of this, in
general, a sequence of n clojure.set operations may run in O(n^2) time
when O(n) is easily a
One caveat: I do like the fact that the set operations currently don't
require the second argument to be a set. In the case that it's not, I
believe the current implementations (at least for difference) are as
good as it gets.
So, I guess fast-difference should read:
(defn fast-difference "Like
> On Jan 20, 4:15 pm, Chouser wrote:
>> On Tue, Jan 20, 2009 at 3:55 PM, Stephen C. Gilardi
>> wrote:
>>
>>
>>
>>> I recommend that proposed changes for clojure-contrib be tracked as
>>> clojure-contrib issues.
>>
>> I agree.
>>
>>> My understanding of the issue policy for Clojure is that Rich
Apologies for multiple posts; I will try to thoroughly investigate
things before starting posting next time. Anyway, to round out the
thread, here are corresponding results for intersection and union:
(defn- fast-intersection- "Expects s1 and s2 sets, s1 bigger than
s2." [s1 s2]
(reduce (fn
> I didn't find any of them compelling enough for core just yet. Putting
> them in contrib first lets people try them out and refine them, point
> out redundancies and conflicts etc.
>
> As a general rule I haven't pulled many simple combining functions
> from contrib, as they just pollute t
On Jan 20, 4:44 pm, Jason Wolfe wrote:
> Apologies for multiple posts; I will try to thoroughly investigate
> things before starting posting next time. Anyway, to round out the
> thread, here are corresponding results for intersection and union:
Well, that didn't last too long .
I just got bit by (clojure.contrib.lazy-seqs/combinations) returning
nil, not [[]] as I expected. I could see arguments for either being
the "correct" output, but let me give my case for [[]].
In my mind, asking what the output of (combinations) should be is
completely analogous to asking what t
I support something like this. Also maybe see my "maximal-elements"
here:
http://groups.google.com/group/clojure/browse_thread/thread/134642cc76de17f7?hl=en#
A nice feature of getting all the maximal elements is you can do
(first (maximal-elements ...)) to recreate functions like yours but
also
I feel like I've seen an answer to this before, but I can't find the
specific thread now. However, the following two threads seem to have
very closely related info (including a reply or two from Rich).
http://groups.google.com/group/clojure/browse_thread/thread/a5e0ba6480d04829/e8e2a14c77f5babf?
On Jan 21, 10:48 pm, Mark Engelberg wrote:
> Is there any way to determine whether something is a "struct" (versus
> an ordinary hash map), and if so, determine which kind of struct it
> was built from?
P.S., for the first part, you can use
(instance? clojure.lang.PersistentStructMap x )
alt
On Jan 21, 11:48 pm, Mark Engelberg wrote:
> Thanks for the thread links. This is basically what I suspected -- if
> you want to use structs in multimethods, you have to roll your own
> constructor which adds some kind of "type" tag to either the hashmap
> or the metadata.
>
> It just seems lik
See also this thread:
http://groups.google.com/group/clojure/browse_thread/thread/134642cc76de17f7?hl=en#
where I also proposed putting power-set in clojure.contrib. I'm just
waiting to hear back from Rich about a few potential changes to core,
and then I will dump all of my remaining proposals
On Jan 23, 7:34 am, "Stephen C. Gilardi" wrote:
> There was a recent suggestion here:
>
> http://groups.google.com/group/clojure/msg/32d323e15f8ce624
>
> about the proper value of:
>
> (clojure.contrib.lazy-seqs/combinations)
>
> (and perhaps by extension (clojure.contrib.lazy-seqs
Two mistakes:
First, if you want sum to take a vector, you should remove the & from
the arglist.
Second, (rest(other)) should be (rest other).
This buys you:
user> (defn sum [more ]
((fn [total other]
(if other
(recur (+ total (first other)) (rest other))
empty seq.
Anyone willing to sign off??
On Jan 21, 5:34 pm, Jason Wolfe wrote:
> I just got bit by (clojure.contrib.lazy-seqs/combinations) returning
> nil, not [[]] as I expected. I could see arguments for either being
> the "correct" output, but let me give my case for [[]]
>
> On Jan 23, 2009, at 1:11 PM, Stephen C. Gilardi wrote:
>
>> I'd be interested in hearing from Chouser before making the change.
>> He added combinations to lazy-seqs.
>
> I think it's quite cool that simply removing the "when" accomplishes
> this.
Yes, exactly :) Returning nil for no-arg
On Jan 19, 4:29 pm, Jason Wolfe wrote:
> I've been doing some OO-type Clojure programming, and have run into
> the following (quite minor) annoyance:
>
> I've defined a struct with a :class of ::Foo in namespace
> my.long.namespace.foo.
>
> In another namespace m
OK, if these are not wanted in core right now, will anyone sign off
for adding them to clojure.contrib?
I can't say I like the idea of having two sets of functions that do
exactly the same thing, but ... sometimes you just don't want things
to run ~1000 times slower than they should.
-Jason
--~
>
> On Fri, Jan 23, 2009 at 12:23 PM, Jason Wolfe
> wrote:
>>
>> OK, if these are not wanted in core right now, will anyone sign off
>> for adding them to clojure.contrib?
>>
>
> Well, *I* want these changes you've proposed in the core, but of
>
On Jan 23, 1:18 pm, Kevin Downey wrote:
> instead of using binding and eval, you can generate a (fn ) form, eval
> it, keep the result function stuffed away somewhere and apply it
> instead of calling eval all the time
Yeah, when I made this optimization to my code a couple weeks ago it
sped the
Every clojure function returns a value. Even if it is only used for
side effects, it still has to return something (probably nil).
-Jason
On Jan 23, 12:17 pm, wubbie wrote:
> Is every function supposed to return something?
> Of course, except for pure side-effects.
>
> -sun
>
> On Jan 23, 3:02
> I appreciate your desire to contribute, but Clojure is not just about
> your needs. You have flooded the group with every idea you have, some
> are bugs (important), some are good ideas, some not, but there are
> simply too many to address at the rate you are producing them.
OK, I am sorry. I
> Hi Jason,
>
> Thanks very much for all your recent thought, work, and postings.
>
> I think it makes sense for clojure-contrib to be much more agile in
> accepting new, experimental, and incrementally improved code than
> Clojure proper. Things in contrib are always optional for end users s
> I'm all for optimizing for size here, however, the fact that these
> functions happen to work when the second argument is not a set is an
> implementation artifact and not a promise of the interface, so I'm not
> in favor of the set? testing or any other accommodation of that.
OK, from that I t
On Jan 24, 2009, at 6:01 PM, Stephen C. Gilardi wrote:
> On Jan 24, 2009, at 8:11 PM, Jason Wolfe wrote:
>> Finally, I don't know how to make a patch, and found nothing in a
>> quick search of the wiki/newsgroup/website. I heard "Git" floating
>> around some
OK, cartesian_product it is.
Two comments on your version. First, unlike mine (and the current
"combinations"), it takes a single argument, a seq of seqs (rather
than multiple seq arguments); which of these ways is preferred?
Second, I had the clauses of my for loop backwards, which was slowing
>
> For simple inputs, the two approaches have similar performance. On
> complex inputs, my tests show the iterative version tends to run about
> twice as fast.
>
> Try running on an extreme input like:
> ["ACDFG" "A" "B" "C" "D" "E" "F" "ABCD" "G" "H" "I" "ABEG" "J" "K"
> "BCDE" "L" "ABCDG" "M"
> Also, it's worth pointing out that your newer version prints the
> combinations out in a non-standard order.
Good point ... I shouldn't have tried to avoid adding the "let":
(defn combinations "Take a seq of seqs and return a lazy list of
ordered combinations (pick 1 from each seq)"
[seq
On Jan 26, 2009, at 10:28 AM, Mark Engelberg wrote:
>
> I've tested that already, and it takes even longer for all but trivial
> inputs, because rec now prevents the combinations sequence from being
> garbage collected, and the memory allocation bogs things down
> tremendously.
Ah, I noticed the
On Jan 26, 2009, at 4:24 PM, Mark Engelberg wrote:
>
> Hey, I just looked back at the original post that started the thread.
> At some point, I had changed my function so (cartesian-product)
> returned nil instead of (nil), but based on Jason's post, I've changed
> it back in another paste annotat
> +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
I think this is not a bug in disj. disj takes a *set* and an element
as input. nil is the empty seq, which is different from the empty set
#{}. The fact that clojure.set functions work at all on things other
than bona fide sets is, in Rich's words, "an implementation artifact
and not a promise
I've posted code for faster, multi-argument clojure.set functions
here:
http://paste.lisp.org/display/74534
Basic algorithms:
intersection: start with smallest set, and remove elements from it
that aren't in each other set
(always iterate through result-in-progress, which
w
> In that case, it makes me think of the degenerate example (I realize
> this is slightly stupid):
>
> (some #{false} (list false))
Maybe this is an argument for adding "any?" to the list of core
functions?
-Jason
--~--~-~--~~~---~--~~
You received this message be
ttp://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html
>
> On Thu, Jan 29, 2009 at 3:38 PM, Jason Wolfe
> wrote:
>
> > In that case, it makes me think of the degenerate example (I realize
> > this is slightly stupid):
> >
> > (some #{f
I think this behavior is as-intended, although I agree that it is
confusing.
The reason for this stems from the fact that lazy-cat returns a seq,
and the only allowed representation for the empty seq is "nil" (i.e.,
Java null). Thus, lazy-cat must always do enough evaluation to know
whether to r
On Jan 30, 5:44 pm, Daniel Renfer wrote:
> user=> (take 0 (lazy-cat [(println 10)] [(println 20)]))
> 10
> nil
>
> What you see here is not an issue with lazy-cat, but rather an issue
> with take. The current implementation of take evaluates one more than
> the n passed to it.
Hmm, I don't thi
While "contains?" treats Clojure maps and java.util.Maps the same, it
doesn't seem to work on java.util.Sets:
user> (let [m (HashMap.)] (.put m "test" "test") (contains? m "test"))
true
user> (let [s (HashSet.)] (.add s "test") (contains? s "test"))
false
user> (let [s (HashSet.)] (.add s "test")
> I'm must be missing something obvious for the [s1 s2] case of union:
>
> Is it only that you've measured (conj s1 s2) to be faster when s2 is
> the smallest ?
Yes, that's it. "conj" iterates through the second argument, and
since count is O(1) for sets, it makes sense to always iterate thro
Hmm, that's an interesting question. It looks to me like into could
be implemented exactly like clojure.set/union, e.g., (reduce conj to
from), so I'm not sure why it's written the way it is ... I must be
missing something.
Anyway, I think clojure.set/union is just a special case of into, at
lea
> ;For my own reference--this is an example of a Clojure sequence
> comprehension
> (for [current-month [months]]
> (let [current-sheet (init-sheet current-month)])
> )
Two things:
- I think you want (for [current-month months] ...
As-is, this will loop a single time, binding current-
On Jan 31, 6:42 pm, Mark Volkmann wrote:
> When a function parameter is named "coll", does that generally mean it
> can be any kind of collection except a map?
> For example, the some function takes a predicate function and a
> "coll", but it can't be a map.
I think it means any class that imple
> I think it means any class that implements java.util.Collection.
To be precise, I think "nil" is also always OK.
Sometimes other seq-able things like Java arrays can be passed too,
although I don't think this is ever promised to work (if it doesn't,
you can always explicitly call seq on them
On Jan 31, 7:09 pm, wubbie wrote:
> Hi,
>
> I saw in ants.clj a notation (->).
> what is it?
> For example,
> (defn place [[x y]]
> (-> world (nth x) (nth y)))
Did you check the docs?
On the website:
http://clojure.org/API#toc21
Within clojure itself:
user> (doc ->)
On Jan 28, 4:14 am, ivant wrote:
> 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?
Coming from CL I was surpr
I believe that any non-special-form has a clojure implementation in
some .clj file, although that implementation may simply be a wrapper
for a method in clojure.lang.RT.
Also check out the source macro in clojure.contrib.repl_utils. It's
quite nifty:
user> (source into)
(defn into
"Returns a
Are you launching Java with any flags? I think by default the heap
limit is quite small (128 MB?)
I use "java -server -Xmx1g ..." as my default for 1 gig of ram; you
should be able to take it from there (-server makes long-running
processes go faster, and perhaps more memory-efficient (?)). As
> There are a very few functions and a few more vars defined only in
> Java code, but that participate in namespaces the normal way and
> therefore don't count as special forms.
>
> One way to find these is to get a list of all the clojure.core vars
> that have no :file metadata:
> (filter #(nil?
This just bit me a second time, since one of my revised set functions
uses "contains?" and thus doesn't work on java.util.Sets (or even
the .keySets of Clojure maps).
user> (contains? (.keySet {:a :b}) :a)
false
It seems that all that's required to make "contains?" work on general
Sets is to rep
On Feb 3, 2009, at 8:16 PM, Stephen C. Gilardi wrote:
>
> On Feb 3, 2009, at 10:44 PM, Jason Wolfe wrote:
>
>> user> (contains? (.keySet {:a :b}) :a)
>> false
>>
>> It seems that all that's required to make "contains?" work on general
>> Se
> On Feb 3, 11:16 pm, "Stephen C. Gilardi" wrote:
>> On Feb 3, 2009, at 10:44 PM, Jason Wolfe wrote:
>>
>>> user> (contains? (.keySet {:a :b}) :a)
>>> false
>>
>>> It seems that all that's required to make "contains?"
On Feb 4, 5:33 am, Rich Hickey wrote:
> On Feb 3, 10:44 pm, Jason Wolfe wrote:
>
> > This just bit me a second time, since one of my revised set functions
> > uses "contains?" and thus doesn't work on java.util.Sets (or even
> > the .keySets of Clojure map
On Feb 4, 5:39 am, Rich Hickey wrote:
> On Feb 3, 11:16 pm, "Stephen C. Gilardi" wrote:
>
> > On Feb 3, 2009, at 10:44 PM, Jason Wolfe wrote:
>
> > > user> (contains? (.keySet {:a :b}) :a)
> > > false
>
> > > It seems that all that'
> (defn mash
> "Reduce a seq-able to a map. The given fn should return a 2-element tuple
> representing a key and value in the new map."
> [f coll]
> (reduce
> (fn [memo elem]
> (let [[k v] (f elem)]
> (assoc memo k v)))
> {} coll))
I called this "map-map" in my util
+1 for the EAP of YourKit. It will expire every now and then, but you
just download the new version.
The only problem I have is that as far as I can figure out, it can't
display source code associated with a function either. This is
usually fine, except for that it can be impossible to figure o
AFAIK no conversion may be necessary, since Clojure maps are Java
maps.
user> (instance? java.util.Map {:foo "foo" :bah 3})
true
The only exception would be if your method expects a mutable map. In
that case,
user> (HashMap. {:foo "foo" :bah 3})
#
-Jason
On Feb 6, 11:02 am, Peter Wolf wr
Oops, missed the String key part -- go with Christophe's answer,
perhaps coupled with the second half of mine.
-Jason
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email
Not yet, but perhaps soon. Code is here:
http://code.google.com/p/clojure-contrib/issues/detail?id=8
-Jason
On Feb 7, 8:51 am, Jeffrey Straszheim
wrote:
>
> Is there a function, perhaps in contrib somewhere, when given a collection,
> returns a single random element?
>
--~--~-~--~--
merge-with says it returns a map, but if you give it no arguments it
gives you back nil instead of the empty map.
In my code, I had something like:
((apply merge-with concat maps) key)
and got NPE rather than "nil" when "maps" was empty.
It looks like "merge" has the same issue too.
Cheers,
J
Nice, I would definitely use this!
One comment/question: would it be more efficient to expand to a bunch
of nested "let" statements, rather than nested function calls? I'm
not sure how Clojure handles "let" under the hood, or how Hotspot
inlining works here. Here's my version:
(defmacro let->
> I know there is no way to import org.newdawn.slick.* (as discussed
> here :http://groups.google.com/group/clojure/browse_thread/thread/fa00a0ff4...
> ). What do you do in programs that need huge list of imports ? I'm
> kinda spoiled by the Eclipse way of doing this, which is roughly :
> import e
> I like that implementation. The recursive call makes it much cleaner.
> A slight improvement (?) yet:
>
> (defmacro let->
> "Provide a name that will be bound to the result of the first form.
> For each additional form, the variable will be
> used in the evaluation, and then rebound to the
I agree that I'd like to (have an option to) see a whole stack trace,
or barring that, bind the most recent exception to some var so I can
look at it later (c.f. *e). The limited trace hindered my debugging
just yesterday.
On Feb 10, 2:01 pm, Jeffrey Straszheim
wrote:
> I've found that, in gene
I was profiling my app today, and noticed lots of time being spent in
Reflector.invokeStaticMethod. The cause was some calls to Math/abs,
which was surprising to me since clojure.org says "Note that type
hints are not needed for static members (or their return values!) as
the compiler always has
Never mind, silly me. Of course, the identity of the method is not
the issue, it's the type of the argument.
user> (defn abs [x] (let [x (double x)] (Math/abs x)))
#'user/abs
; no reflection warning.
-Jason
--~--~-~--~~~---~--~~
You received this message because
> Would you consider changing the names of these 2 functions ?
>
> random-permutation -> shuffle
> random-element -> one-of
>
> Shorter names are a trademark of clojure.
> "one-of" was taken straight from paip =)
I'd be OK with shuffle, I guess, but I don't know if one-of is
descriptive enough
eem to be much lazy about it, right? It is just java's
> shuffle.
>
> On Feb 11, 8:16 pm, Phil Hagelberg wrote:
>> Jason Wolfe writes:
>>>> Would you consider changing the names of these 2 functions ?
>>
>>>> random-permutation -> shuffle
>>&g
s there any reason we can't name random-element something like
> random-elem ? I think that is a fine compromise.
>
> On Wed, Feb 11, 2009 at 6:37 PM, Jeff Valk wrote:
>
> - Original Message -
> From: Phil Hagelberg
> Sent: Wednesday 11 February 2009 13:16
>
&g
1 - 100 of 314 matches
Mail list logo