Re: proposal for core arithmatic functions

2010-03-13 Thread Konrad Hinsen
On 13 Mar 2010, at 03:32, Jonathan Shore wrote: Could + and other operators be changed to a macro mapping rather than the current defn, mapping the argument list to a binary expression tree (+ (+ (+ ... instead of the list style application (I'm guessing yes, not being familiar with CL-st

Re: proposal for core arithmatic functions

2010-03-13 Thread Jonathan Shore
Thanks for your thoughtful reply, see below. On Mar 13, 2010, at 3:03 AM, Konrad Hinsen wrote: > On 13 Mar 2010, at 03:32, Jonathan Shore wrote: > >> Could + and other operators be changed to a macro mapping rather than the >> current defn, mapping the argument list to a binary expression tree

filter sequence until false result

2010-03-13 Thread Glen Rubin
Hey all! I am trying to filter a sequence until a false value is returned. Is there a control-flow form to do this? ( I know I could write a loop statement to do it) Here are more details of what I am actually trying to do, in case above is not clear. input is the lazy sequence of primes: (u

Re: filter sequence until false result

2010-03-13 Thread CuppoJava
You can use either take-while or for to do what you want. (take-while #(< % 20) primes) (for [p primes :while (< p 20)] p) Hope that helps -Patrick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@google

Re: filter sequence until false result

2010-03-13 Thread Michał Marczyk
On 13 March 2010 15:49, Glen Rubin wrote: > If I try: > > (filter #(while (< % 20)) primes) > > It gets hung up since filter keeps testing primes, despite the fact > that they have grown too large.  So, I would like filter to stop at > the first false result. Actually that's not what happens. Exe

[ANN] clj-native 0.8.1

2010-03-13 Thread mac
Hello all. I have had some time lately to work on my C FFI for Clojure and I think it's pretty much feature complete now. It has support for functions, callbacks, structures, unions and globals. For structures there is support for different alignments. The library has two main namespaces: clj-nati

Achieving high performance, mutable primitives?

2010-03-13 Thread CuppoJava
Hi, I just ran these two microbenchmarks, where I attempted to measure the overhead in Clojure's loop-recur form as compared to just mutating an array. ;;loop-recur (5300 msecs) (time (dotimes [n 5000] (loop [accum (int 0) i (int 0)] (if (< i 5) (recur (+ accum i) (inc i))

Re: Achieving high performance, mutable primitives?

2010-03-13 Thread David Nolen
On Sat, Mar 13, 2010 at 1:59 PM, CuppoJava wrote: > Hi, > I just ran these two microbenchmarks, where I attempted to measure the > overhead in Clojure's loop-recur form as compared to just mutating an > array. > > ;;loop-recur (5300 msecs) > (time > (dotimes [n 5000] >(loop [accum (int 0) i (

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 wrote: > Hi, > I jus

Re: binary representation + operators

2010-03-13 Thread Michał Marczyk
On 12 March 2010 23:26, Scott wrote: > How do I write a function 'bit' that converts an integer to binary > representation: > > (bit 0) -> 2r0 > (bit 1) -> 2r1 > (bit 2) -> 2r10 > (bit 3) -> 2r11 I understand that you want a way to obtain a string representation of a number in binary. I think you

Good practice for documenting structmaps?

2010-03-13 Thread Matt Lehman
Is there a good practice for documenting the structure basis object for structmaps? As I'm using more Clojure code on a production, I'm finding it useful to document structmaps, but the only way I can find to do it is using the following pattern to add the doc meta to a var: (def #^{:doc "..."}

Re: Something similar to (match) from scheme?

2010-03-13 Thread Luka
thanx, that's a start. It seems that plt-scheme's match is a bit more powerful, but I think I can manage with this as well. So far the biggest annoyance is the fact that I can match a number or a string, but not a symbol (I can in :when condition, I know...) which is something I can live with. --

Re: Something similar to (match) from scheme?

2010-03-13 Thread Luka
I just found clojure.contrib.types match which maybe fits more with what I'm trying to do... I'll check it out tomorrow, almost 3am here... -- 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 N

Re: proposal for core arithmatic functions

2010-03-13 Thread Per Vognsen
On Sat, Mar 13, 2010 at 9:32 AM, Jonathan Shore wrote: > Hi, > > I've been evaluating clojure with a bias around performance (I do a lot of > numerical work).   I don't need to the metal, but want to see that > fundamental operations are comparable to java in performance and that > performance

Re: proposal for core arithmatic functions

2010-03-13 Thread Per Vognsen
On Sat, Mar 13, 2010 at 3:03 PM, Konrad Hinsen wrote: > On 13 Mar 2010, at 03:32, Jonathan Shore wrote: > >> Could + and other operators be changed to a macro mapping rather than the >> current defn, mapping the argument list to a binary expression tree  (+ (+ >> (+ ...  instead of the list style

Re: proposal for core arithmatic functions

2010-03-13 Thread Per Vognsen
As a mea culpa for my earlier stupidity, here's a proposed solution that is semantically transparent if somewhat inelegantly brute force in its approach: http://gist.github.com/331211 If need be, it could also define entries for :inline and :inline-entries for the auto-generated arity overloads.

Zip function

2010-03-13 Thread Marmaduke
Hello, I'm new to Clojure, but in other languages, zip is a workhorse, and I didn't find it, so I (defn zip [& ss] (partition (count ss) (apply interleave ss))) but because I didn't find it, I am suspicious: is there a better way? Marmaduke ps. As a first-poster: thanks to Rich Hickey and St

Newbie question: Why does clojure prefer java.lang.Exception?

2010-03-13 Thread CloudiDust
Greetings everyone! I am currently beginning to learn clojure, and here's one thing that I don't quite understand, that many exceptions thrown by clojure are the most generic java.lang.Exception's (e.g. when a symbol cannot be resolved). Why aren't more specific exception classes used, like clojur

Re: quote versus backquote

2010-03-13 Thread Felix Breuer
Thank you, this has been very helpfull. The reason I came across this problem is that I never intended to evaluate the symbols in the expression trees. I rather wanted to use them to represent symbolic constants in an abstract expression tree. I am now convinced that using keywords throughout is t

Re: bounded memoize

2010-03-13 Thread Meikel Brandmeyer
Hello Christophe, On Fri, Mar 12, 2010 at 08:27:15PM +0100, Christophe Grand wrote: > See my memoize5: the call isn't computed inside the swap!s That doesn't mean, that it is not computed several times! user=> (defn f [x] (println "Got" x "from" (Thread/currentThread))

Re: Leiningen, Clojure and libraries: what am I missing?

2010-03-13 Thread Meikel Brandmeyer
Hi, On Thu, Mar 11, 2010 at 01:32:36PM -0800, Phil Hagelberg wrote: > Historically this has been because calculating the classpath couldn't > be done in Clojure itself since it needed to be done before the JVM > booted. Having to figure this kind of thing out in a shell script or > in elisp is a

Re: (seq? x) vr.s (not (empty? x))

2010-03-13 Thread Meikel Brandmeyer
Hi, On Fri, Mar 12, 2010 at 08:25:23AM +1100, Alex Osborne wrote: > The list equivalent to the vec or set functions is (apply list ...) -- > there's no shorthand for it as you shouldn't be using lists much > explicitly, use a vector instead. In fact there is a short-hand: user=> (seq []) nil us

Re: Achieving high performance, mutable primitives?

2010-03-13 Thread CuppoJava
I see, so that's what I was missing. Thanks for your help! -Patrick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with

Re: filter sequence until false result

2010-03-13 Thread Matt
I think what you want is take-while instead of filter: (take-while %(< % 20) primes) -Matt -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated -

Re: filter sequence until false result

2010-03-13 Thread Matt
Hmm.. I should re-read messages before sending them. The correct code is: (take-while #(< % 20) primes) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are

Re: Zip function

2010-03-13 Thread Meikel Brandmeyer
Hi, On Sat, Mar 13, 2010 at 06:55:56AM -0800, Marmaduke wrote: > I'm new to Clojure, but in other languages, zip is a workhorse, and I > didn't find it, so I > > (defn zip [& ss] > (partition (count ss) (apply interleave ss))) > > but because I didn't find it, I am suspicious: is there a bett

Re: Zip function

2010-03-13 Thread Vagif Verdi
In clojure map works like zipWith. So you can pass to it vector if you want just plain zip: (map vector colls) That makes making a special named function unnesessary. On Mar 13, 6:55 am, Marmaduke wrote: > Hello, > > I'm new to Clojure, but in other languages, zip is a workhorse, and I > didn't

Re: bounded memoize

2010-03-13 Thread Christophe Grand
Hi Meikel, On Sat, Mar 13, 2010 at 10:51 PM, Meikel Brandmeyer wrote: > On Fri, Mar 12, 2010 at 08:27:15PM +0100, Christophe Grand wrote: > > > See my memoize5: the call isn't computed inside the swap!s > > That doesn't mean, that it is not computed several times! > I agree: it can be concurre

Re: binary representation + operators

2010-03-13 Thread Scott
java to the rescue! Thanks to all for your suggestions Scott On Mar 13, 3:45 pm, Michał Marczyk wrote: > On 12 March 2010 23:26, Scott wrote: > > > How do I write a function 'bit' that converts an integer to binary > > representation: > > > (bit 0) -> 2r0 > > (bit 1) -> 2r1 > > (bit 2) -> 2r10

extending protocol

2010-03-13 Thread aria42
Is there a way to say that a protocol extends another protocol or interface? I.e. can i specify that a given protocol must also support the "seq" method from clojure.lang.Seqable? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group,

Re: bounded memoize

2010-03-13 Thread Eugen Dück
On Mar 13, 4:51 pm, Christophe Grand wrote: > My variations on memoize use a single atom: your bounded-memoize id roughly > equivalent to my memoize2 + fifo-strategy, > seehttp://gist.github.com/330644#LID19. I finally found the time to fully read your gist, and I see you are indeed doing the sa

Re: bounded memoize

2010-03-13 Thread Eugen Dück
On Mar 14, 11:57 am, Eugen Dück wrote: > This gap shrinks when using memoize7 thanks to the use of delays, but > it is not completely closed and can still lead to multiple delays of > the same computation. If we want to get rid off this gap and make it Actually, I take that back. The delay might

Re: extending protocol

2010-03-13 Thread Konrad Hinsen
of Clojure, in my opinion: all checks of the type "does this value fit with that function" are done at runtime. Konrad __ Information provenant d'ESET NOD32 Antivirus, version de la base des signatures de virus 4942 (20100313) __ Le message a été vérifié par ES

Re: proposal for core arithmatic functions

2010-03-13 Thread Konrad Hinsen
Konrad. __ Information provenant d'ESET NOD32 Antivirus, version de la base des signatures de virus 4942 (20100313) __ Le message a été vérifié par ESET NOD32 Antivirus. http://www.eset.com -- You received this message because you are subscribed to the Google Groups &quo

Re: bounded memoize

2010-03-13 Thread Eugen Dück
Hi Christophe, your fifo-strategy (the one that uses "identity" as the hit method) does not work: user=> (def g (memoize7 identity (fifo-strategy 3))) #'user/g user=> (g 1) 1 user=> (g 1) java.lang.IllegalArgumentException: Wrong number of args passed to: core$identity (NO_SOURCE_FILE:0) You hav