Re: Can this function be simpler?

2011-03-10 Thread Jason Wolfe
   - Is there a way to make this function less complicated? without    recursion maybe? Looks like you're covered on this one.    - Is there something simpler than (concat even-more (list (hash-map k    v)) to append an element at the end of a sequence? Clojure is opinionated in this sense.

Re: unchecked-divide etc being replaced in 1.3 - no more support for longs?

2011-03-01 Thread Jason Wolfe
But I don't know what the plan is if you really do want truncating arithmetic on longs. On 1.3 alpha 4: user= (+ Long/MAX_VALUE Long/MAX_VALUE) ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1581) user= (set! *unchecked-math* true) true user= (+

Re: Defrecord and = docstring clarifications (regarding record equality)

2011-02-10 Thread Jason Wolfe
Alternatively, records could have an enforced mapping {:type TheRecordsClass} that does not actually take up storage space, but appears when records are queried and automatically imposes the desired equality semantics if records were simply treated as maps -- other than that a plain map with

Defrecord and = docstring clarifications (regarding record equality)

2011-01-31 Thread Jason Wolfe
I just ran into the following surprise: user (defrecord P []) user.P user (defrecord Q []) user.Q user (= (P.) (Q.)) false user (.equals (P.) (Q.)) true This is not a bug (but I do find it confusing -- I did not expect (P.) and (Q.) to collide as map keys):

Re: Enhanced Primitive Support Syntax

2011-01-17 Thread Jason Wolfe
On Jan 16, 6:18 pm, Sean Corfield seancorfi...@gmail.com wrote: On Sun, Jan 16, 2011 at 3:50 PM, Jason Wolfe ja...@w01fe.com wrote: Moreover, we do not need to redefine the class at run-time.  A simple way to do this: when you compile a function with arithmetic operations, concatenate

Re: Enhanced Primitive Support Syntax

2011-01-17 Thread Jason Wolfe
On Jan 17, 3:24 pm, Brian Goslinga quickbasicg...@gmail.com wrote: On Jan 17, 3:17 pm, Jason Wolfe ja...@w01fe.com wrote: I think you can.   Let me elaborate on my simplistic example.  Compile the code for a function twice -- once where everything works within primitives, and once where

Re: Enhanced Primitive Support Syntax

2011-01-16 Thread Jason Wolfe
(a) unsafe/incorrect value on overflow/fastest/unifiable* vs. (b) safe/error on overflow/fast/unifiable vs. (c) safe/promoting on overflow/slow/not-unifiable If I understand correctly, the issue with auto-promotion is that we have to box the output of an operation even if it turns out

Re: Enhanced Primitive Support Syntax

2011-01-15 Thread Jason Wolfe
(a) unsafe/incorrect value on overflow/fastest/unifiable* vs. (b) safe/error on overflow/fast/unifiable vs. (c) safe/promoting on overflow/slow/not-unifiable If I understand correctly, the issue with auto-promotion is that we have to box the output of an operation even if it turns out to fit

Re: What am I not getting here?

2011-01-06 Thread Jason Wolfe
You're not capturing the output of the reduce anywhere; doseq is for side-effects only. If you wrapped the doseq in a (def dictionary ...) it would work, but this is not recommended. Instead, you should either use nested reductions, or produce a simple list of tokens first (simpler): (defn

Re: Speed of clojure hash map vs java hash map

2010-12-29 Thread Jason Wolfe
Since transients enforce single-threadedness, there's no reason to put it in an atom.  You're right that would work for the truly single-threaded scenario.  I'm more interested right now in the scenario of multi-threaded, low-contention, only occasionally need a snapshot (for iteration

Re: Speed of clojure hash map vs java hash map

2010-12-28 Thread Jason Wolfe
On Dec 28, 10:28 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Tue, Dec 28, 2010 at 10:15 PM, David Nolen dnolen.li...@gmail.com wrote: Even in in a single threaded context raw insert performance isn't the final word. What if you want to be able to deliver a snapshot for reporting?

Re: Clojure 1.3 Alpha 4

2010-12-15 Thread Jason Wolfe
On Dec 15, 10:05 am, Ken Wesson kwess...@gmail.com wrote: On Wed, Dec 15, 2010 at 12:52 PM, Mike Meyer mwm-keyword-googlegroups.620...@mired.org wrote: One of the things those of us on your side *begged* for (and apparently also didn't get) was that the versions with correct behavior

Re: Bug in clojure.contrib.core/-? (improper quoting?)

2010-12-07 Thread Jason Wolfe
On Dec 6, 8:41 pm, Ken Wesson kwess...@gmail.com wrote: On Mon, Dec 6, 2010 at 10:27 PM, Jason Wolfe jawo...@berkeley.edu wrote: This happens in both Clojure 1.2 and 1.3-latest: user= (require 'clojure.contrib.core) nil user= (clojure.contrib.core/-? 1 inc) 2 user

Re: Bug in clojure.contrib.core/-? (improper quoting?)

2010-12-07 Thread Jason Wolfe
Great, thanks! -Jason On Dec 7, 2:52 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Will provide a patch soon, thanks for the bug report 2010/12/7 Jason Wolfe jawo...@berkeley.edu On Dec 6, 8:41 pm, Ken Wesson kwess...@gmail.com wrote: On Mon, Dec 6, 2010 at 10:27 PM, Jason Wolfe

Re: Bug in clojure.contrib.core/-? (improper quoting?)

2010-12-07 Thread Jason Wolfe
Posting a reply to someone that consists solely of a link that, when accessed by that someone, throws up an access denied message in their face, is an equivalent act to sending them an encrypted reply for which they don't have the key, or handing them a locked briefcase for which they don't

Bug in clojure.contrib.core/-? (improper quoting?)

2010-12-06 Thread Jason Wolfe
This happens in both Clojure 1.2 and 1.3-latest: user= (require 'clojure.contrib.core) nil user= (clojure.contrib.core/-? 1 inc) 2 user= (clojure.contrib.core/-? 1 inc inc) CompilerException java.lang.Exception: Unable to resolve symbol: -? in this context, compiling:(NO_SOURCE_PATH:3) I assume

Re: Fixing minmax algorithm

2010-12-04 Thread Jason Wolfe
You're looking for apply. user2 (max 1 2 3) 3 user2 (max [1 2 3]) [1 2 3] user2 (apply max [1 2 3]) 3 -Jason On Dec 4, 3:30 am, zmyrgel timo.my...@gmail.com wrote: I'm trying to make a functional version of minmax algorithm as shown in John Hughes Why functional programming matters? work

Re: Error message specifies wrong line # in source file if function lacks argvec.

2010-11-19 Thread Jason Wolfe
http://dev.clojure.org/jira/browse/CLJ-420 Perhaps it's the same bug? -Jason On Nov 18, 8:09 pm, Ken Wesson kwess...@gmail.com wrote: I got this oddity while debugging a Clojure sourcefile today: user= right click load file in netbeans #CompilerException java.lang.IllegalArgumentException:

Re: REQUEST for feedback on http://clojure.org

2010-11-02 Thread Jason Wolfe
Not sure if you count this as off limits as part of the API page, but its first line points to a stale official source code for clojure -- should be updated to the new github repo. -Jason On Oct 30, 7:38 pm, Alex Miller alexdmil...@yahoo.com wrote: Hi all, I'm doing a bit of doc cleanup

Re: strange bug in range or lazy-seq?

2010-10-12 Thread Jason Wolfe
On Oct 11, 6:56 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: When a var's definition has a lazy reference to itself, as primes does below, then your results will be dependent on the lazy/chunky/strict-ness of the calls leading to the lazy reference. While I agree that this sort of

Re: Is This Function Idiomatic Clojure?

2010-10-07 Thread Jason Wolfe
(defn d-map [ args] (apply map (fn [ vals] (zipmap (map first args) vals)) (map second args))) On Oct 7, 12:54 am, Stefan Rohlfing stefan.rohlf...@gmail.com wrote: Thank you all for your great code examples! The goal of the function 'd-map' is to return a collection of maps that

Re: Is This Function Idiomatic Clojure?

2010-10-07 Thread Jason Wolfe
: Since variety is the spice of life, here's my (less clean and untested) code that I was about to post when your message arrived in my inbox:   (apply map #(into {} %) (for [[k vs] args] (for [v vs] [k v] -Per On Thu, Oct 7, 2010 at 3:18 PM, Jason Wolfe jawo...@berkeley.edu wrote

Re: Clojure 1.3 amap/aset issue?

2010-10-05 Thread Jason Wolfe
Are you using lein repl? If so, I suspect that may be your issue; at least on some systems, it seems to currently lose type hints: http://groups.google.com/group/clojure/browse_thread/thread/41fd58c62ef1be36/40c88038f1a77d9c?show_docid=40c88038f1a77d9c -Jason On Oct 4, 11:05 pm, Sean Corfield

Re: Clojure 1.3 amap/aset issue?

2010-10-05 Thread Jason Wolfe
A quick test to see if this is the issue; you should see this: user (meta ^:foo []) {:tag :foo} (from lein swank on my system), not this: user= (meta ^:foo []) nil (from lein repl on my system). On Oct 4, 11:50 pm, Jason Wolfe jawo...@berkeley.edu wrote: Are you using lein repl?  If so, I

Re: Clojure 1.3 amap/aset issue?

2010-10-05 Thread Jason Wolfe
On Oct 5, 10:16 am, Sean Corfield seancorfi...@gmail.com wrote: On Tue, Oct 5, 2010 at 9:52 AM, Sean Corfield seancorfi...@gmail.com wrote: but when I try lein swank I get exceptions: Exception in thread main java.lang.IllegalArgumentException: Unable to resolve classname: ARef,

Re: why the big difference in speed?

2010-09-21 Thread Jason Wolfe
next-gaussian is the bottleneck as you say. On Sep 21, 12:20 am, Jason Wolfe jawo...@berkeley.edu wrote: On Sep 20, 4:43 pm, Ranjit rjcha...@gmail.com wrote: I'm glad you think partition is the problem, because that was my guess too. But I think I have the answer. This is the fastest

Re: why the big difference in speed?

2010-09-21 Thread Jason Wolfe
]         (aset-double ^doubles (aget result i) j (+ (aget arr1 i j)                              (aget arr2 i j))) but it's surprisingly slow compared to numpy again. On Sep 21, 2:26 pm, Jason Wolfe jawo...@berkeley.edu wrote: FYI I fired up a profiler and more than 2/3 of the runtime

Re: why the big difference in speed?

2010-09-21 Thread Jason Wolfe
second extra per loop. Not that I want to use this approach anymore, but what other type hints could I add to my Java array addition function? The only unhinted variables I see left are the indices. Thanks for all your help, -Ranjit On Sep 21, 5:48 pm, Jason Wolfe jawo...@berkeley.edu

Re: why the big difference in speed?

2010-09-20 Thread Jason Wolfe
in the emacs buffer, and the warnings weren't visible. I have a question about gaussian-matrix3 though. What is aset- double2? Is that a macro that has a type hint for an array of doubles? Thanks, -Ranjit On Sep 19, 5:37 pm, Jason Wolfe jawo...@berkeley.edu wrote: Hi Ranjit, The big perf

Re: why the big difference in speed?

2010-09-20 Thread Jason Wolfe
still about 4x slower than gaussian-matrix5 above. There must be a way to improve on the inner loop here that doesn't require using indices, right? On Sep 20, 12:32 pm, Jason Wolfe jawo...@berkeley.edu wrote: Oops, I found aset-double2 with tab completion and figured it was build-in.  Forgot

Re: why the big difference in speed?

2010-09-20 Thread Jason Wolfe
. The for, and doseq macros seems like they're pretty slow. -Ranjit On Sep 20, 3:30 pm, Jason Wolfe jawo...@berkeley.edu wrote: I think partition is slowing you down (but haven't profiled to verify).  Here's a functional version that's about 70% as fast as my 5: (defn gaussian-matrix6 [L

Re: why the big difference in speed?

2010-09-19 Thread Jason Wolfe
Microbench is a little utility I wrote that executes a piece of code for awhile to warm up, then records timings for as many runs as will fit in a preset time limit and reports statistics. So the numbers you see are min/median/max milleseconds per run, and number of runs that fit in 3 seconds of

1.2 RC2 exception line numbering bug.

2010-08-07 Thread Jason Wolfe
This bug still seems to be present in 1.2 RC2, and is more general than I previously thought: jawo...@[~/Projects/testproj]: cat src/test.clj bla jawo...@[~/Projects/testproj]: cat src/test2.clj (bla) jawo...@[~/Projects/testproj]: lein repl user= (require 'test) java.lang.Exception: Unable

Re: 1.2 RC2 exception line numbering bug.

2010-08-07 Thread Jason Wolfe
OK, done. http://www.assembla.com/spaces/clojure/tickets/420-some-compiler-exceptions-erroneously-using-repl-line-numbers- I don't have more details on what kinds of errors are affected; but, I believe the wrong line numbers are the REPL line numbers, if that helps.. Thanks, Jason On Aug 7,

Re: Bug: contains? doesn't work on transient maps or sets

2010-08-01 Thread Jason Wolfe
Related: in 1.2 RC1, find also fails to work with transient maps (although it does throw an error, rather than fail silently). On Aug 1, 12:25 pm, Mark Engelberg mark.engelb...@gmail.com wrote: I just tested this in Clojure 1.2, and the bug is still there: (contains? (transient #{1 2}) 1) -

1.2 error message improvement suggestion (missing line #s for some defrecord errors)

2010-07-30 Thread Jason Wolfe
I'm converting my ~30Kloc project to 1.2 RC1 from a months-old snapshot, and so far it's been smooth sailing. One thing I've noticed, however, is that defrecord parse error exceptions seem to be missing line numbers. The example I ran into was user (defrecord foo [bar] :as this ) ; Evaluation

Re: 1.2 error message improvement suggestion (missing line #s for some defrecord errors)

2010-07-30 Thread Jason Wolfe
) java.lang.IllegalArgumentException: Unsupported option(s) - :as (test.clj:2) user= (use 'test) java.lang.IllegalArgumentException: Unsupported option(s) - :as (test.clj:3) user= (use 'test) Line numbers for some other exceptions seem to be behaving properly. -Jason On Jul 30, 5:38 pm, Jason

Re: Variadic arguments and macros

2010-07-07 Thread Jason Wolfe
Hi Cameron, On Jul 7, 9:49 am, Cameron cpuls...@gmail.com wrote: Hello all! Today, I've either discovered a bug, or I've discovered a flaw in my understanding of macros. Most likely the latter :-) Could anyone set me straight? While this is not the macro I was trying to write, it falls over

Re: Enhanced Primitive Support

2010-06-17 Thread Jason Wolfe
At first read this all looks awesome to me, and I'd love to see prim/ num/equals in 1.2! Type hinting math has been a pain, I rarely need bigints and would be happy being explicit about them when I do, and I can't think of obvious cases where I'd need (equals? [2.0] [2]), which I gather will no

Re: reducing runtime errors due to mistyped keywords

2010-04-22 Thread Jason Wolfe
Hi Istvan, I've run into this a fair bit too. To catch such problems (at runtime), I sprinkle my code with (safe-get m :key) in key places, rather than (:key m) or (m :key) or (get m :key). safe-get: (defmacro lazy-get Like get but lazy about evaluating default [m k d] `(if-let [pair#

Re: Datatypes and Protocols update

2010-04-22 Thread Jason Wolfe
+1, I am also using this feature of the old deftype. On Apr 22, 12:15 pm, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 22.04.2010, at 18:53, Rich Hickey wrote: Feedback and errata welcome as always, One feature in the deftype/defrecord split that I regret is that defrecord no longer

Re: scoped local memoize

2010-03-19 Thread Jason Wolfe
For recursive one-shot memoized functions, I've been using this: (defmacro memoized-fn [name args body] `(let [a# (atom {})] (fn ~name ~args (let [m# @a# args# ~args] (if-let [[_# v#] (find m# args#)] v# (let [v# (do ~...@body)]

Re: Achieving high performance, mutable primitives?

2010-03-13 Thread Jason Wolfe
BTW your 5 literal is boxed, which is causing slowness: user (time (dotimes [n 5000] (loop [accum (int 0) i (int 0)] (if ( i (int 5)) (recur (+ accum i) (inc i)) accum Elapsed time: 861.027 msecs On Mar 13, 10:59 am, CuppoJava patrickli_2...@hotmail.com

Re: Can I make this faster?

2010-02-18 Thread Jason Wolfe
Hey Aria, If you really want a mutable Counter, IMO you might as well do things your Java way with a HashMap ... or at least that's how I would do it. A more Clojure way would be a totally safe, functional counter: (deftype ClojureCounter2 [counts total] Counter (getCount [k] (get counts

Re: defmethod question....

2009-12-27 Thread Jason Wolfe
That doesn't seem to be possible - I can't find a function that accepts a PersistentStructMap and returns the symbol passed to struct so it knows the keylist to use for the arguments. Nor could I find the magic incantation to let me use those symbol names with derive, which would let me use

Re: Datatypes and protocols - update

2009-12-11 Thread Jason Wolfe
I've been trying out the new branch, and on the whole I like it a lot. I know it'll take some time to learn how do things properly the new way, and I've figured out how to do most of the things I want to do thus far. Thanks, Rich! One thing I haven't figured out how to do cleanly without

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Jason Wolfe
I like almost all of this a lot. My only disagreement is on prefix lists ... I wouldn't want to lose them, and in fact would prefer to see them extended to recursive prefix lists (trees). -Jason On Nov 11, 10:12 am, Stephen C. Gilardi squee...@mac.com wrote: On Nov 10, 2009, at 9:08 PM, John

Re: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-26 Thread Jason Wolfe
Hi Mark, Thanks for the patch! Have you seen this page? http://clojure.org/contributing You should follow the instructions there to get your patch included. In particular, that page tells you where to post it, and has other details; for instance, you must send a CA to Rich before any code you

Re: read-line in emacs slime on windows problem

2009-10-07 Thread Jason Wolfe
Happens for me too, on OS X. I always just switch to the *inferior- lisp* REPL (C-s i) before starting any commands that expect user input. -Jason On Oct 7, 3:37 am, Kelvin Ward kelvin.d.w...@googlemail.com wrote: Just to update, I've confirmed that this also happens on Ubuntu Linux. I did a

Re: Bug in count for hash-maps with nil values

2009-09-24 Thread Jason Wolfe
I guess this is already ticketed. I should have searched first, sorry for the noise. http://www.assembla.com/spaces/clojure/tickets/192-hashmaps--count-is-not-always-updated-when-associng-dissocing-a-nil-key -Jason --~--~-~--~~~---~--~~ You received this message

Bug in count for hash-maps with nil values

2009-09-23 Thread Jason Wolfe
On the most recent git revision of Clojure (branch master, commit 64323d8c6ad4962ac780d4d904b69a891ab312f8), user= (count {1 nil 2 nil 3 nil 4 nil 5 nil 6 nil 7 nil 8 nil}) 8 user= (count {1 nil 2 nil 3 nil 4 nil 5 nil 6 nil 7 nil 8 nil 9 nil}) 0 user= (count {1 nil 2 nil 3 nil 4 nil 5 nil 6 nil

Re: Possible bug report

2009-07-30 Thread Jason Wolfe
On Jul 30, 2009, at 6:51 AM, Rich Hickey wrote: On Jul 29, 6:09 pm, Jason Wolfe jawo...@berkeley.edu wrote: Is this a bug? user (eval `(make-array ~Byte/TYPE 2)) ; Evaluation aborted. (ExceptionInInitializerError) Compare: user (eval `(make-array ~Byte 2)) #Byte[] [Ljava.lang.Byte

Possible bug report

2009-07-29 Thread Jason Wolfe
Is this a bug? user (eval `(make-array ~Byte/TYPE 2)) ; Evaluation aborted. (ExceptionInInitializerError) Compare: user (eval `(make-array ~Byte 2)) #Byte[] [Ljava.lang.Byte;@26fcfd5c user (eval `(make-array Byte/TYPE 2)) #byte[] [...@1f0feb6e user (make-array (eval Byte/TYPE) 2) #byte[]

Re: map lookup with numeric return value fails

2009-07-20 Thread Jason Wolfe
My guess is that you're running into the discrepancy between map key equality and Clojure's =. Because Clojure's collections implement the Java Collection interfaces, they are required to test keys with Java's .equals, and use a hash function that matches. Java defines a particular semantics

Re: Breaking out of infinite loops

2009-05-13 Thread Jason Wolfe
I believe if you update to the newest versions of SLIME, swank- clojure, clojure, and clojure-contrib, ctrl-c ctrl-c should just work out of the box in SLIME without any modifications to your user code. I haven't used clojure-box though. -Jason On May 12, 11:11 pm, Mark Engelberg

Re: partition improvement

2009-05-09 Thread Jason Wolfe
See also partition-all in clojure.contrib.seq-utils. It isn't as feature-complete as your version, but is instead a drop-in replacement for partition that always returns the final part (regardless of whether or not it's long enough). -Jason On May 8, 4:02 pm, DiG

Re: learning clojure, converting a sequence with repetitions to a multi-map

2009-04-28 Thread Jason Wolfe
(defn seq-to-multimap   takes a sequence s of possibly repeating elements    and converts it to a map, where keys are obtained by applying key- fn    to elements of s and values are sequence of all elements of s with the particular key [s key-fn] (apply merge-with concat (map (fn [x]

Re: clojure.contrib.repl-utils/source: getting source not found

2009-04-25 Thread Jason Wolfe
Hi, Did you update to the newest versions of clojure and clojure-contrib? I think the way source filenames are stored in metadata changed recently, and source was temporarily broken by this change. Cheers, Jason On Apr 24, 11:41 pm, Sigrid keyd...@gmx.de wrote: Hi, I'm just starting with

Re: ICFP 2009

2009-04-23 Thread Jason Wolfe
I'm interested, although I'm not sure if I'll be around that weekend. I've done quite well in past TopCoder-style contests (where I've had to use Java); it would be fun to do a competition in Clojure. -Jason --~--~-~--~~~---~--~~ You received this message because

Re: Possible contrib contribution: clojure.contrib.timing

2009-04-15 Thread Jason Wolfe
I have some related contributions ... if clojure.contrib.timing is created, maybe some of these would be useful too: http://groups.google.com/group/clojure/browse_frm/thread/231cc06b4b13744c?hl=en# -Jason --~--~-~--~~~---~--~~ You received this message because

Re: Question about metadata on map keys

2009-04-10 Thread Jason Wolfe
Probably this is expected, since metadata is defined not to affect equality, and maps rely on equality semantics.  I would recommend against storing metadata on map keys.  In general, if the metadata matters for the value of an object, then it shouldn't be metadata. Some alternatives: 1)

Re: Transparent delays

2009-04-09 Thread Jason Wolfe
Hi Chas, Have you considered wrapping the computation in a lazy sequence? (lazy-seq [(expensive-calculation)]) The, instead of (force ...), you just use (first ...). I think equality and hashing will automatically work like you want them to. Cheers, Jason On Apr 9, 11:55 am, Chas Emerick

Question about metadata on map keys

2009-04-09 Thread Jason Wolfe
I just tracked down a bug in my code, which boiled down to this: user ^(key (first (assoc {[] :old-val} (with-meta [] {:some :metadata}) :val))) nil Namely, if a map already contains a given key, when you attempt to assoc in a version of the key with new metadata this is not recorded. It seems

clojure.inspector/inspect-tree doesn't work on sets; patch attached

2009-03-19 Thread Jason Wolfe
I was debugging with inspect-tree and noticed that it errors when it encounters a set (it thinks it's not atomic, but then nth produces an UnsupportedOperationException). I made a small patch (below) that makes inspect-tree work on java.util.Sets, and also anything else that implements

Printing, Reading, and Serializing (+ bug?)

2009-03-17 Thread Jason Wolfe
Does anyone have suggestions on the best way to store Clojure objects to a file and later read them back in? The obvious option would be to use the build-in printer and reader. One limitation here, which I'm OK with for now, is that this doesn't work for arbitrary serializable objects (which

Re: Debugging support for clojure?

2009-03-12 Thread Jason Wolfe
On Mar 11, 2009, at 11:04 AM, Jerry K wrote: Also, I've not looked at any of the math code in clojure contrib, but expressed as such, I wouldn't expect the idiom (mod (expt n exp) m) to be at all fast for reasons largely independent of the numeric implementation underneath. Computing the

Re: Bug in set?

2009-03-12 Thread Jason Wolfe
Also, union/difference/intersection/symmetric-diff are binary. Would there be any interest in a patch to make them n-ary? Union, difference, and intersection are all variadic as of a month or so ago. Are you on the latest SVN? -Jason --~--~-~--~~~---~--~~

Re: Bug in set?

2009-03-12 Thread Jason Wolfe
On Mar 12, 2009, at 3:34 PM, Kyle Schaffrick wrote: On Thu, 12 Mar 2009 12:45:00 -0700 (PDT) Jason Wolfe jawo...@berkeley.edu wrote: Also, union/difference/intersection/symmetric-diff are binary. Would there be any interest in a patch to make them n-ary? Union, difference

Re: Bug in set?

2009-03-12 Thread Jason Wolfe
union does an implicit distinct operation, as it returns a set. I didn't think Clojure had multisets, unless we've had another Rich's Time Machine moment :) Nope, it doesn't have multisets ... I somehow read that as apply concat rather than apply union ... maybe I need some more sleep

Re: Problems with read-line

2009-03-09 Thread Jason Wolfe
I think this was discussed here: http://groups.google.com/group/clojure/browse_frm/thread/48f1fb08b3052083/85f858df39daca2a?hl=enlnk=gstq=linenumberingpushbackreader#85f858df39daca2a I'm not sure what the resolution was, if any. -Jason On Mar 9, 4:33 am, David Sletten da...@bosatsu.net

Re: version of - short-circuiting on nil

2009-03-09 Thread Jason Wolfe
(let [person (get-the-person)]   (when-not (nil? person)     (let [address (.getAddress person)]       (when-not (nil? address)          (let [street (.getStreet address)]             (when-not (nil? street)                (do-something-finally-with-street street) ?- sounds

Re: Static type guy trying to convert

2009-03-09 Thread Jason Wolfe
Hi Curtis, I get my fuzzies from at least a few places: 1. bottom-up, interactive development. This means frequent testing (at the REPL) of individual or small sets of functions, as I write them. 2. assertions liberally sprinkled in key places. 3. multimethods that are difficult to

Re: Clojure infinite loop

2009-03-06 Thread Jason Wolfe
(Ctrl-C pressed here) Traceback (most recent call last):   File stdin, line 1, in module KeyboardInterrupt That is something I miss from SBCL. In SLIME-SBCL, you can just Ctrl- C Ctrl-C to interrupt your code. I think it's not possible (or at least easy) in Clojure without adding

Re: Clojure infinite loop

2009-03-06 Thread Jason Wolfe
I just added a couple functions to clojure.contrib.repl-utils in an attempt to support Ctrl-C: user= (use 'clojure.contrib.repl-utils) nil user= (add-break-thread!) {1 #WeakReference java.lang.ref.weakrefere...@e29820} This registers the current thread to be stopped next time an INT

Re: calling overloaded Java methods

2009-03-06 Thread Jason Wolfe
On Mar 6, 3:23 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: The code below gives java.lang.IllegalArgumentException: More than one matching method found: submit. Is there a way to tell Clojure which submit method I want? (defn do-stuff []   (+ 2 2)) (let [executor

Re: :use feature requests

2009-03-05 Thread Jason Wolfe
Thanks, Steve and Chouser! Well, there's been two proposals. In my original less radical one, I already addressed this requirement. For your example: (ns util (:use [really.long.namespace.util :as util :exclude ()])) That would be perfectly fine with me. I just wanted to mention

Re: fitness

2009-03-05 Thread Jason Wolfe
Without seeing your code, it's hard to say exactly what's best. I assume when you say mutating function, you mean function that returns a fresh map representing a new individual. One option is to make all of your mutations go through a single utility function, which will make the change and

Re: fitness

2009-03-05 Thread Jason Wolfe
The mutation constructing function seems obvious in hindsight. I feel stupid now. You shouldn't :). Immutability definitely takes some getting used to; I know it's taking me quite some time to wrap my head around it. -Jason --~--~-~--~~~---~--~~ You

Re: fitness

2009-03-04 Thread Jason Wolfe
Let me add my 2 cents here. The delay solution seems like the right one, with one caveat: two otherwise identical individuals will no longer have the same hash value or compare as =. If you're trying to remove duplicate individuals or some such, this may be a problem; otherwise, probably not.

Re: :use feature requests

2009-03-04 Thread Jason Wolfe
Intentionally referring an entire namespace in and also aliasing it seems a very odd thing to do. The number of libs this change would break is very likely to be tiny and the breakage will be obvious and easy to fix. I just ran into an instance where I might want to do just this. I have a

Re: Concatenating many lists (stack overflow problem)

2009-03-02 Thread Jason Wolfe
decidedly non-intuitive to me. You're welcome. Also, maybe see the wikibook, in particular http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#Lazy_Evaluation_of_Sequences -Jason On Mar 2, 12:07 am, Jason Wolfe jawo...@berkeley.edu wrote: No, it will be O(n), where the cool magic

Re: member function

2009-03-02 Thread Jason Wolfe
There's also includes? in clojure.contrib.seq-utils. -Jason On Mar 2, 6:07 am, David Sletten da...@bosatsu.net wrote: On Mar 2, 2009, at 4:01 AM, Mark Volkmann wrote: It's verbose in order to discourage its use since its a linear search. See the discussion about the contains? function

Re: Concatenating many lists (stack overflow problem)

2009-03-01 Thread Jason Wolfe
Hi, The problem is that you end up with the front of your worklist being wrapped in n-lines nested calls to lazy-seq, one per each call to concat. Then, realizing the first element causes a stack overflow. This wouldn't happen if you reversed the arguments to concat, but then you wouldn't get

Re: Concatenating many lists (stack overflow problem)

2009-03-01 Thread Jason Wolfe
backward)? Or does it do some other cool magic to make this quick? On Mar 1, 9:07 pm, Jason Wolfe jawo...@berkeley.edu wrote: Hi, The problem is that you end up with the front of your worklist being wrapped in n-lines nested calls to lazy-seq, one per each call to concat. Then, realizing

Re: Please explain

2009-02-27 Thread Jason Wolfe
Here's an example: user (def x) #'user/x user (defn foo [] (set! x 10)) #'user/foo user (binding [x 1] [x (binding [x 2] [x (do (foo) x)]) x]) [1 [2 10] 1] Foo passes information to the calling form by assigning to x, within the innermost binding only. It sounds like the quote should say

Re: Observations about new lazy branch

2009-02-27 Thread Jason Wolfe
I'm not sure which old-map you mean here. If you mean the old lazy-cons version, using your above macro, this will have too many lazy-seq calls. Yeah, you're right ... I managed to confuse myself. Off the top of my head I can't think of a nicer way to write lazier- map than what you've

Re: some vs. contains? for a list

2009-02-26 Thread Jason Wolfe
Hi Mark, The results will depend on the objects you are comparing. If you need to search through the list multiple times, converting to a set once is almost certainly going to be faster. But, if you're just doing it once, iterating will usually be much faster: user (time (dotimes [_ 10]

Re: some vs. contains? for a list

2009-02-26 Thread Jason Wolfe
On Feb 26, 2009, at 12:15 PM, Mark Volkmann wrote: On Thu, Feb 26, 2009 at 12:02 PM, Jason Wolfe jawo...@berkeley.edu wrote: Hi Mark, The results will depend on the objects you are comparing. If you need to search through the list multiple times, converting to a set once is almost

Re: Extensive use of let?

2009-02-25 Thread Jason Wolfe
There's also a middle ground: (defn my-fn2 [input]   (op5 (op4 (op1 input) (op2 input If your op names are descriptive, this can still be very easy to read, with significantly fewer characters than the let version (you'll get use to reading inside-out quickly). You can also

Timing utilities for clojure.contrib?

2009-02-25 Thread Jason Wolfe
I wrote a small set of functions for executing code while measuring and/or limiting its time and/or memory consumption. I did this both to run timing experiments, and to let me run things at the REPL without risking an infinite loop (and having to restart Clojure from scratch). Would anyone

Re: dorun and map

2009-02-24 Thread Jason Wolfe
You could use doseq? Now, if you want eager evalation *and* a result seq, I think you're stuck with (doall (for ...)) or (doall (map ...)). -Jason On Feb 24, 9:49 am, Mark Volkmann r.mark.volkm...@gmail.com wrote: It seems that, at least in demo code that I write, I frequently call dorun on

Re: dorun and map

2009-02-24 Thread Jason Wolfe
On Feb 24, 2009, at 11:58 AM, Mark Volkmann wrote: On Tue, Feb 24, 2009 at 12:23 PM, Jason Wolfe jawo...@berkeley.edu wrote: You could use doseq? I don't have a body to execute though. I need to build things with map first. Huh? As far as I know, as long as you're only iterating

Re: dorun and map

2009-02-24 Thread Jason Wolfe
On Feb 24, 2009, at 12:07 PM, Jason Wolfe wrote: On Feb 24, 2009, at 11:58 AM, Mark Volkmann wrote: On Tue, Feb 24, 2009 at 12:23 PM, Jason Wolfe jawo...@berkeley.edu wrote: You could use doseq? I don't have a body to execute though. I need to build things with map first. Huh

Re: Macro madness

2009-02-23 Thread Jason Wolfe
Check out the part of this page on syntax quote http://clojure.org/reader As I understand it, syntax-quote namespace-resolves symbols to prevent accidental variable capture. 90% of the time, any variables you let within a macro should be suffixed by a #. So, if you replace all occurrences of

Operating on multidimensional primitive arrays without reflection?

2009-02-23 Thread Jason Wolfe
I'm trying to call some third-party code that expects a two- dimensional double array, and I can't figure out how to create and fill this in Clojure without a huge perf hit (which profiling shows to be coming from reflection): user (time (let [arr (make-array Double/TYPE 1)] (dotimes [_ 10]

Re: Operating on multidimensional primitive arrays without reflection?

2009-02-23 Thread Jason Wolfe
-arr (aget arr 0)] (aset-float sub-arr 0 0.0) Seems to work? Looks an eligible candidate for a macro. On Mon, Feb 23, 2009 at 9:04 PM, Jason Wolfe jawo...@berkeley.edu wrote: I'm trying to call some third-party code that expects a two- dimensional double array, and I can't

Re: structmap instance test

2009-02-21 Thread Jason Wolfe
I don't think so. See http://groups.google.com/group/clojure/browse_thread/thread/74d430f8e4353725/ab7fe2144e09b56a?hl=enlnk=gstq=instance+defstruct#ab7fe2144e09b56a (and other threads on this issue too, IIRC.) Cheers, Jason On Feb 21, 6:08 am, Mark Volkmann r.mark.volkm...@gmail.com wrote:

Re: Calling method in Java that mutates passed argument

2009-02-20 Thread Jason Wolfe
Hmmm, that is weird ... I would expect the sort to throw an exception, but it seems to complete happily. (If you try it with a vector instead of a list, it will error). Anyway, the typical way to do this would be to convert your Clojure data structure to a mutable Java type first, then convert

Re: Possible bug in sorted-set, question about comparisons

2009-02-20 Thread Jason Wolfe
It probably does an identical? call on a pair before calling compare, for efficiency. In other words, it may work on non- comparable types, but only when passed n instances of the exact same object: user (sorted-set '(1) '(1)) ; Exception user (let [x '(1)] (sorted-set x x)) #{(1)} This is

Re: Have get calculate not-found value only if key does not exist

2009-02-20 Thread Jason Wolfe
That looks about right. I proposed adding this to clojure.contrib as lazy-get: http://code.google.com/p/clojure-contrib/issues/detail?id=10 along with a corresponding safe-get function that errors if the key is not found. -Jason On Feb 20, 4:42 pm, Rowdy Rednose rowdy.redn...@gmx.net wrote:

<    1   2   3   >