Bug in .hashCode for vectors/lists (Old subject: "Bugs in contains? (?))

2009-01-03 Thread Jason Wolfe
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 > (

Re: Bug in .hashCode for vectors/lists (Old subject: "Bugs in contains? (?))

2009-01-03 Thread Jason Wolfe
> 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

Re: Slow nested subvecs (+ fix)

2009-01-04 Thread Jason Wolfe
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

Re: Slow nested subvecs (+ fix)

2009-01-04 Thread Jason Wolfe
> > 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

Re: Questions & workaround regarding Clojure, true laziness, and nil-terminated sequences

2009-01-04 Thread Jason Wolfe
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

Re: Functional Shuffle

2009-01-05 Thread Jason Wolfe
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

Re: Why aren't lists callable?

2009-01-12 Thread Jason Wolfe
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"

Utilities for clojure.contrib?

2009-01-12 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-13 Thread Jason Wolfe
> > (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

Profiling Clojure with YourKit: file names and line numbers?

2009-01-13 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-13 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-14 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-14 Thread Jason Wolfe
> 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

Re: Utilities for clojure.contrib?

2009-01-14 Thread Jason Wolfe
>>> 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 :). --~--~-~

Multiple hashing functions? (+ bug in PersistentHashMap.java?)

2009-01-14 Thread Jason Wolfe
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 .

Re: Utilities for clojure.contrib?

2009-01-14 Thread Jason Wolfe
> 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

Re: Utilities for clojure.contrib?

2009-01-14 Thread Jason Wolfe
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

Re: Bug in .hashCode for vectors/lists (Old subject: "Bugs in contains? (?))

2009-01-15 Thread Jason Wolfe
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 "\

Re: Bug in .hashCode for vectors/lists (Old subject: "Bugs in contains? (?))

2009-01-15 Thread Jason Wolfe
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

Re: Multiple hashing functions? (+ bug in PersistentHashMap.java?)

2009-01-15 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-15 Thread Jason Wolfe
> > 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

Re: A quasiquote for Clojure?

2009-01-15 Thread Jason Wolfe
> >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

Re: Utilities for clojure.contrib?

2009-01-15 Thread Jason Wolfe
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

Mysterious performance anomalies

2009-01-15 Thread Jason Wolfe
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

Re: Mysterious performance anomalies

2009-01-16 Thread Jason Wolfe
> 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

Re: Utilities for clojure.contrib?

2009-01-16 Thread Jason Wolfe
> > > (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 > > >        (

Re: A quasiquote for Clojure?

2009-01-17 Thread Jason Wolfe
> 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

Possible feature: consider aliases when reading namespace-qualified keywords.

2009-01-19 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-20 Thread Jason Wolfe
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))

Re: Possible feature: consider aliases when reading namespace-qualified keywords.

2009-01-20 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-20 Thread Jason Wolfe
> 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

Re: Multiple hashing functions? (+ (update: not a) bug in PersistentHashMap.java?)

2009-01-20 Thread Jason Wolfe
> 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

Proposal: "smarter" set operations that take size into account for speed

2009-01-20 Thread Jason Wolfe
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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-20 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-20 Thread Jason Wolfe
> 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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-20 Thread Jason Wolfe
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

Re: Utilities for clojure.contrib?

2009-01-20 Thread Jason Wolfe
> 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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-20 Thread Jason Wolfe
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 .

(clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-21 Thread Jason Wolfe
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

Re: greatest and least

2009-01-21 Thread Jason Wolfe
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

Re: struct question

2009-01-21 Thread Jason Wolfe
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?

Re: struct question

2009-01-21 Thread Jason Wolfe
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

Re: struct question

2009-01-22 Thread Jason Wolfe
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

Re: A nil puzzle

2009-01-23 Thread Jason Wolfe
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

Re: A nil puzzle

2009-01-23 Thread Jason Wolfe
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

Re: newbie Q: what's wrong with this?

2009-01-23 Thread Jason Wolfe
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))

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Jason Wolfe
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 [[]]

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Jason Wolfe
> > 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

Re: Possible feature: consider aliases when reading namespace-qualified keywords.

2009-01-23 Thread Jason Wolfe
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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-23 Thread Jason Wolfe
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 --~

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-23 Thread Jason Wolfe
> > 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 >

Re: Binding values in a list of symbols and evaluating as code

2009-01-23 Thread Jason Wolfe
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

Re: Not nil and 'true' with conditional functions

2009-01-23 Thread Jason Wolfe
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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-23 Thread Jason Wolfe
> 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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-23 Thread Jason Wolfe
> 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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-24 Thread Jason Wolfe
> 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

Re: Proposal: "smarter" set operations that take size into account for speed

2009-01-24 Thread Jason Wolfe
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

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-25 Thread Jason Wolfe
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

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
> > 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"

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
> 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

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
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

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
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

Re: repeat and replicate

2009-01-28 Thread Jason Wolfe
> +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

Re: Bug with clojure.set/intersection, clojure.set/difference etc.

2009-01-29 Thread Jason Wolfe
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

RFC: new clojure.set functions

2009-01-29 Thread Jason Wolfe
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

Re: Alternatives to contains?

2009-01-29 Thread Jason Wolfe
> 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

Re: Alternatives to contains?

2009-01-29 Thread Jason Wolfe
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

Re: Documentation of lazy-cat should contain a warning

2009-01-30 Thread Jason Wolfe
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

Re: Documentation of lazy-cat should contain a warning

2009-01-30 Thread Jason Wolfe
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

Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-01-30 Thread Jason Wolfe
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")

Re: RFC: new clojure.set functions

2009-01-31 Thread Jason Wolfe
> 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

Re: into vs. clojure.set/union

2009-01-31 Thread Jason Wolfe
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

Re: Why Isn't This Working

2009-01-31 Thread Jason Wolfe
> ;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-

Re: meaning of coll

2009-01-31 Thread Jason Wolfe
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

Re: meaning of coll

2009-01-31 Thread Jason Wolfe
> 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

Re: what does -> mean?

2009-01-31 Thread Jason Wolfe
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 ->)

Re: Turning a sequence of chars into a string.

2009-02-01 Thread Jason Wolfe
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

Re: special forms vs. functions and macros

2009-02-02 Thread Jason Wolfe
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

Re: Possible to create a much larger "world" than ants.clj?

2009-02-02 Thread Jason Wolfe
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

Re: special forms vs. functions and macros

2009-02-03 Thread Jason Wolfe
> 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?

Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-03 Thread Jason Wolfe
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

Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-03 Thread Jason Wolfe
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

Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Jason Wolfe
> 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?"

Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Jason Wolfe
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

Re: Bug or desired behavior: "contains?" doesn't seem to work on java.util.Sets.

2009-02-04 Thread Jason Wolfe
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'

Re: Map from generator?

2009-02-06 Thread Jason Wolfe
> (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

Re: What profilers are you using?

2009-02-06 Thread Jason Wolfe
+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

Re: Clojure Maps and Java Maps

2009-02-06 Thread Jason Wolfe
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

Re: Clojure Maps and Java Maps

2009-02-06 Thread Jason Wolfe
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

Re: Random elements

2009-02-07 Thread Jason Wolfe
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? > --~--~-~--~--

Minor bug report: (merge-with f) returns nil, not {}

2009-02-07 Thread Jason Wolfe
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

Re: A pipe macro for left-to-right coll streams

2009-02-09 Thread Jason Wolfe
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->

Re: Clojure + Slick - "stylistic" questions

2009-02-09 Thread Jason Wolfe
> 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

Re: A pipe macro for left-to-right coll streams

2009-02-09 Thread Jason Wolfe
> 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

Re: Suggestion: test-is should print *all* frames of exceptions caught while testing

2009-02-10 Thread Jason Wolfe
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

Calling static methods without reflection?

2009-02-10 Thread Jason Wolfe
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

Re: Calling static methods without reflection?

2009-02-10 Thread Jason Wolfe
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

Re: Random elements

2009-02-11 Thread Jason Wolfe
> 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

Re: Random elements

2009-02-11 Thread Jason Wolfe
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

Re: Random elements

2009-02-11 Thread Jason Wolfe
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   2   3   4   >