Re: What's the efficient functional way to computing the average of a sequence of numbers?
On Fri, Mar 30, 2012 at 11:01 AM, Larry Travis wrote: > user=> (time (dotimes [i 10] (average1 mill-float-numbs))) > "Elapsed time: 526.674 msecs" > > user=> (time (dotimes [i 10] (average2 mill-float-numbs))) > "Elapsed time: 646.608 msecs" > > user=> (time (dotimes [i 10] (average3 mill-float-numbs))) > "Elapsed time: 405.484 msecs" > > user=> (time (dotimes [i 10] (average4 mill-float-numbs))) > "Elapsed time: 394.31 msecs" I can understand the first one being "slow" but I'm a bit surprised about the loop being the slowest of the four options. Can someone shed some light on that? Nice to see the accumulating reduce being faster since that's how I've settled in to solving this kind of problem in our code, without really wondering about performance (it's "fast enough" and I think it's the more elegant solution). -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What is fn*, fn suffixed with asterisk?
fn* is a compiler intrinsic...it's pretty low-level, it doesn't support destructuring,. So instead, core.clj creates a macro called fn that adds all this other functionality and eventually spits out the fn* in a format the compiler wants. Basically it's set up this way so that you can write the majority of the functionality behind fn can be written in clojure code instead of in Java. Note: there are other forms that are the same as fn*. Namely, loop*, and let*. They all exist for the same reasons. Timothy -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
What is fn*, fn suffixed with asterisk?
Recently, when looking into the clojure source code, core.clj in particular, I found multiple occurrence of 'fn*' instead of 'fn'. Can anyone help explain what fn* is and the difference between fn and fn* Thanks Simon -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What's the efficient functional way to computing the average of a sequence of numbers?
Hi Rob, Appreciate it, I like the code and explanation, great! Simon On Thursday, March 29, 2012 6:28:48 PM UTC+8, Rob Nagle wrote: > > You can reduce in one pass with a function that tracks both the sum > and the count. > > (defn avg [coll] > (apply / (reduce (fn [[sum n] x] [(+ sum x) (inc n)]) [0 0] coll))) > > This reduce function is somewhat unusual in that its arguments have > different forms. As a result, this one does require the initial-value > argument be used. It's set to [0 0] indicating the sum and count both > start at 0. The function then "consumes" the numbers in coll one at a > time, producing the running sum and count each time. Then we just > apply / to divide the sum by the count. > > On Mar 28, 9:18 pm, "simon.T" wrote: > > The obvious way is like the following, which traverse the sequence 2 > times. > > Wondering what will be the efficient way... > > > > (defn avg [coll] > > (/ (reduce + coll) (count coll))) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureScript release 0.0-1006
A quick comment on item 13 in the release. I think that this sort causes some code that I have to fail. The reason is that the code in question inserts js scripts into the header of the page - when bootstrap loads. Subsequent modules require this js to be present - but do not "depend" on it. Example: - I have a ns that I can require that injects jquery. - I also use jayq previously, if I required jayq after requiring my particular ns, Jquery would be present when jayq extended it. This is no longer true - I think due to the sort - since there is no direct dependency of jayq on my library. I realise that this is an edge-case. I can work around it here - but I can't inject javascript in this way any more. To fix it would require that the sort preserve the original require order - where this is not dictated by dependency order. Dave On Saturday, 31 March 2012 04:43:08 UTC+11, Stuart Sierra wrote: > > Just pushed to Sonatype. Will be sync'd to other repos within 24 hours. > > Changes: > http://build.clojure.org/job/clojurescript-release/9/ > > > > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
[ANN] data.zip 0.1.1
Hi everyone, Thanks to a patch from Justin Kramer, data.zip now works properly with the updates to data.xml. org.clojure data.zip 0.1.1 or [org.clojure/data.zip "0.1.1"] Cheers, Aaron -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
On Fri, Mar 30, 2012 at 6:17 PM, Lee Spector wrote: > > On Mar 30, 2012, at 5:11 PM, Cedric Greevey wrote: >> >> That opens a giant can of worms. How, for example, do we discover that >> (partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all >> equal? Nevermind once we get into situations like #(reduce + (map >> (constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n) >> (next s)) n) equals count. > > In fact that's an uncomputable can of worms. I was pretty sure it smelled like halting problem; thanks for confirming. :) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
2012/3/30 Vinzent : > Counter-example: one could write if-authenticated macro, which will take > fixed number of args, but should be indented as normal if. OK, check the macro structure to see if any args are incorporated as invokable forms -- so, in arguments in special forms and macros that are "bodies". (Yes, this is obviously sort of recursive.) The first such arg is treated as the start of a body. Some static dataflow analysis may be needed in case the macro takes the arg, processes it in some way, and then inserts it into its output rather than inserting it directly. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
On Mar 30, 2012, at 5:11 PM, Cedric Greevey wrote: > > That opens a giant can of worms. How, for example, do we discover that > (partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all > equal? Nevermind once we get into situations like #(reduce + (map > (constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n) > (next s)) n) equals count. In fact that's an uncomputable can of worms. But detecting identity of functions that were defined using exactly the same code is computable, whether or not it's advisable or useful (which I don't know). -Lee -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureScript release 0.0-1006
Awesome, I've been looking forward to this release. The new release has made it out to the upstream maven repository. I just pushed out lein-cljsbuild 0.1.4, which has the new 0.0-1006 dependency (as well as some other features [1]. It works on my personal projects! -Evan [1] https://github.com/emezeske/lein-cljsbuild/issues?sort=created&direction=desc&state=closed&page=1&milestone=7 On Friday, March 30, 2012 10:43:08 AM UTC-7, Stuart Sierra wrote: > > Just pushed to Sonatype. Will be sync'd to other repos within 24 hours. > > Changes: > http://build.clojure.org/job/clojurescript-release/9/ > > > > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Better ways to make time tansformations?
I wanted to track a program and set a maximum runtime for it in a way which is readable for the user. So I needed to write a time tansformation which I could use in my track function. First I wanted to use something like the 'defunits' macro from "Let over Lambda" from Doug Hoyte, but I'm not so fit in LISP and Clojure to write/understand it :(. So I use following two function: (defn unit-of-time [value unit] "(unit-of-time value unit) returns the value in relation to the defined unit in seconds. Example: (unit-of-time 10 :minute) will return 600 and (unit-of-time 3 :millisecond) 3/1000. following Keywords are supported: :second :minute :houre :day :millisecond :microsecond :nanosecond" (* value (case unit :second 1 :minute 60 :houre 3600 :day 86400 :millisecond 1/1000 :microsecond 1/100 :nanosecond 1/10))) (defn transform-time [value from to] "(transform-time value from to) calculates the value from the unit 'from' to the unit 'to'" (/ (unit-of-time value from) (unit-of-time 1 to))) The functions, but now I would know if there might be a better way to transform for example a time value given in minutes into the appropriate milli- or nanosecond value? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Vinzent writes: > Probably you slightly misunderstood what I mean. Consider this > scenario: > I've set up a project which uses a new library with non-standart > indent. I've connected to swank and compiled it. Then I'm calling > some clojure-mode-update-indent function, which walks through all > loaded namespaces and collects :indent metadata (on the clojure side) > and saves appropriate define-clojure-indent form somewhere in config > file (on the elisp side). After that I have all macros indented > properly. I see. Yes, that would be better. I don't think it belongs in clojure-mode, but you could make a tool that could collect that data and export it into .dir-locals.el files or something like that. -Phil -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Counter-example: one could write if-authenticated macro, which will take fixed number of args, but should be indented as normal if. суббота, 31 марта 2012 г. 3:07:23 UTC+6 пользователь Cedric Greevey написал: > > On Fri, Mar 30, 2012 at 1:26 PM, Vinzent wrote: > > Another idea is to put :indentation metadata on vars, so user-defined > macros > > could be indented properly. Currently I have (define-clojure-indent ...) > > with a number of forms in my emacs config file, and it seems to be pretty > > common solution. It'd be nice to replace this hack with an > IDE-independent > > way to control the indentation. > > > > Phil, what do you think? Could it be experimentally implemented in > > clojure-mode? > > My thought on this? Just look for the macro to have a rest arg. > Function argument indentation should be used for non-rest macro args, > and body indentation for macro rest args. > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Probably you slightly misunderstood what I mean. Consider this scenario: I've set up a project which uses a new library with non-standart indent. I've connected to swank and compiled it. Then I'm calling some clojure-mode-update-indent function, which walks through all loaded namespaces and collects :indent metadata (on the clojure side) and saves appropriate define-clojure-indent form somewhere in config file (on the elisp side). After that I have all macros indented properly. It's better than manually writing define-clojure-indent form because it's tool-agnostic; say, CCW can use the same data, so library maintainers only have to add {:indent :defn} to their defmacros. суббота, 31 марта 2012 г. 2:32:35 UTC+6 пользователь Phil Hagelberg написал: > > Vinzent writes: > > > I'm not sure how I feel about indentation rules > > changing depending on whether slime is active or not. > > > > What I was thinking, is that there'd be some function which would > > collect and save indentation metadata, so it can be used later. Thus, > > active slime connection required only the first time one uses a > > library with non-standart indentation rules. > > Currently clojure-mode operates on each file in isolation. As soon as > you start "remembering" macro indentation, you're back in a > non-deterministic state where indentation depends on the history of > which files you've visited in the current Emacs session. > > You could make it work just for the macros in a single file, but that > doesn't seem very valuable. > > -Phil > > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
On Fri, Mar 30, 2012 at 2:48 PM, Nathan Matthews wrote: > Also it bothers me that > > (= (partial * 2) (partial * 2)) > > is false. Logically it shouldn't be right? If we captured the function > forms, that would enable better equality for functions. That opens a giant can of worms. How, for example, do we discover that (partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all equal? Nevermind once we get into situations like #(reduce + (map (constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n) (next s)) n) equals count. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
On Fri, Mar 30, 2012 at 1:26 PM, Vinzent wrote: > Another idea is to put :indentation metadata on vars, so user-defined macros > could be indented properly. Currently I have (define-clojure-indent ...) > with a number of forms in my emacs config file, and it seems to be pretty > common solution. It'd be nice to replace this hack with an IDE-independent > way to control the indentation. > > Phil, what do you think? Could it be experimentally implemented in > clojure-mode? My thought on this? Just look for the macro to have a rest arg. Function argument indentation should be used for non-rest macro args, and body indentation for macro rest args. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
On Mar 30, 7:35 am, David Jagoe wrote: > G'day everyone > > I am increasingly relying on clojure and plan to use clojureclr and > clojurescript in production too. I will soon need to hire a clojure > developer and was hoping that someone could suggest a good place to post a > job ad. I've never seen a job posted here but I would like to reach the > community. > > Thanks > David In addition to the resources mentioned so far, I'd add lispjobs.wordpress.com as a potential place to post. I've seen a few Clojure jobs listed there recently. Best regards, Brian Cooley -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Vinzent writes: > I'm not sure how I feel about indentation rules > changing depending on whether slime is active or not. > > What I was thinking, is that there'd be some function which would > collect and save indentation metadata, so it can be used later. Thus, > active slime connection required only the first time one uses a > library with non-standart indentation rules. Currently clojure-mode operates on each file in isolation. As soon as you start "remembering" macro indentation, you're back in a non-deterministic state where indentation depends on the history of which files you've visited in the current Emacs session. You could make it work just for the macros in a single file, but that doesn't seem very valuable. -Phil -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Nathan Matthews writes: > I wrote some code which re-programmed the fn macro to capture the > closures as well as the actual function form, and attach them as > meta-data also on the actual function object. Could you submit it as a patch to serializable-fn? It would be nice to have everything in one place. -Phil -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: kibit is to Clojure what SOUL is to Smalltalk
Nice find. Thanks, '(Devin Walters) On Friday, March 30, 2012 at 2:58 PM, David Nolen wrote: > http://soft.vub.ac.be/SOUL/ > > This project is worth looking at for directions that kibit might want to go. > It's also a good resource for cool ideas on how to leverage core.logic - > miniKanren was designed from the get go to manipulate Lisp source. > > David > > -- > 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 > (mailto:clojure@googlegroups.com) > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > (mailto:clojure+unsubscr...@googlegroups.com) > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
> > I'm not sure how I feel about indentation rules > changing depending on whether slime is active or not. > What I was thinking, is that there'd be some function which would collect and save indentation metadata, so it can be used later. Thus, active slime connection required only the first time one uses a library with non-standart indentation rules. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
kibit is to Clojure what SOUL is to Smalltalk
http://soft.vub.ac.be/SOUL/ This project is worth looking at for directions that kibit might want to go. It's also a good resource for cool ideas on how to leverage core.logic - miniKanren was designed from the get go to manipulate Lisp source. David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Nathan Matthews writes: > I wanted to serialise functions and send them over the network. The > problem with serializable-fn is that it doesn't capture closures. It's designed to capture closures; if it doesn't that would be an (unsurprising) bug. -Phil -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
This seems like a good place. Where's the job? :) On Mar 30, 2012, at 7:35 AM, David Jagoe wrote: > G'day everyone > > I am increasingly relying on clojure and plan to use clojureclr and > clojurescript in production too. I will soon need to hire a clojure developer > and was hoping that someone could suggest a good place to post a job ad. I've > never seen a job posted here but I would like to reach the community. > > Thanks > David > > > -- > 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 your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Hi, I wanted to serialise functions and send them over the network. The problem with serializable-fn is that it doesn't capture closures. I wrote some code which re-programmed the fn macro to capture the closures as well as the actual function form, and attach them as meta-data also on the actual function object. I could share this code if people would find this useful. Its non-trivial due to various complexities and bugs in Clojure. Also it bothers me that (= (partial * 2) (partial * 2)) is false. Logically it shouldn't be right? If we captured the function forms, that would enable better equality for functions. On 29 Mar 2012, at 17:44, Phil Hagelberg wrote: > On Thu, Mar 29, 2012 at 9:29 AM, Petr Gladkikh wrote: >> I am pondering on the idea of having more (or even a lot) of metadata >> that could be useful for debugging and problem resolution. >> Since we can store anything in metadata, can we store not only source >> file path and line number but whole source code that is associated >> with piece of code? > > See https://github.com/technomancy/serializable-fn/ for a > proof-of-concept of this idea. > > It's always bothered be that defn puts metadata on the var and not on > the function itself. > > Anyway, supposedly Rich is in favour of having "dynamicity knobs" > according to his Conj 2011 keynote, and this sounds like just the kind > of thing that would fall under that. > > -Phil > > -- > 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 your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Multiple ClojureScript (sub)projects with shared CLJS libraries per single clojure project
I can confirm Mark Rathewell's note; that's part of what lein-cljsbuild is meant to do. With his configuration, the script1.js and script2.js files would both be built, and each would only contain the code from the project1 or project2 directories, respectively (unless they require code from outside namespaces, then that would be included too). Running "lein cljsbuild once" would build both cljs subprojects in parallel, and "lein cljsbuild auto" would watch both for modifications and rebuild them as needed. -Evan On Friday, March 30, 2012 10:49:29 AM UTC-7, Mark Rathwell wrote: > > I haven't tried yet, but lein-cljsbuild [1] is meant to support > multiple builds, and I believe something like the below config would > be what you are looking for: > > :cljsbuild { > :builds > [{:source-path "src/cljs/project1" > :compiler {:output-to "resources/public/cljs/script1.js" > :externs ["externs/jquery.js"] > :optimizations :advanced > :pretty-print true}} > {:source-path "src/cljs/project2" > :compiler {:output-to "resources/public/cljs/script2.js" > :externs ["externs/jquery.js"] > :optimizations :advanced > :pretty-print true}}]} > > [1] https://github.com/emezeske/lein-cljsbuild > > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What's the efficient functional way to computing the average of a sequence of numbers?
On Thu, 2012-03-29 at 23:31 -0700, Benjamin Peter wrote: > the sequence would have been traversed completely by the reduce call > and therefore clojure could know it's size and provide a constant time > count. > > Could this be implemented? Yes. You could probably implement it yourself, as a wrapper sequence type, though this wouldn't make all other sequence types automatically countable. > Is it? It won't be, in general, because you would have to "hold onto the head" until you got to the end, or go through a costly half-broken weak reference dance. It is worth considering that even for some uncounted sequences, the cost of a second traversal for "count" may be less than the bookkeeping cost of keeping a count as you traverse once. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
On Fri, Mar 30, 2012 at 8:18 AM, Devin Walters wrote: > Try meetup.com and look for Clojure and/or Lispish groups. Contact them with > details. I would be happy to put the word out in our group. Feel free to > pass me details. Also LinkedIn has a Clojure group and that has a Jobs section. If you want a local person, Devin's suggestion of going thru a user group is a great idea. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
David, You might want to try posting at Functional Jobs; I've heard good things about results from there: http://functionaljobs.com/ FYI, I have no affiliation or connection with whoever runs the service. Of course, tweet the opening. I think we'd all be surprised by how many jobs get filled via initial contact on twitter. - Chas -- [Clojure Programming from O'Reilly](http://www.clojurebook.com) On Mar 30, 8:35 am, David Jagoe wrote: > G'day everyone > > I am increasingly relying on clojure and plan to use clojureclr and > clojurescript in production too. I will soon need to hire a clojure > developer and was hoping that someone could suggest a good place to post a > job ad. I've never seen a job posted here but I would like to reach the > community. > > Thanks > David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Vinzent writes: > Phil, what do you think? Could it be experimentally implemented in > clojure-mode? No, clojure-mode determines indentation exclusively from static heuristics. There is dynamic indentation support in slime, but I've never looked into it; I'm not sure how I feel about indentation rules changing depending on whether slime is active or not. -Phil -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What's the efficient functional way to computing the average of a sequence of numbers?
I too think this is interesting because because it serves to illustrate some important general aspects of Clojure with a very simple problem. I wrote four Clojure programs contrasting different ways of solving the problem, and then timed the application of each ten times to a million-item sequence /mill-float-numbs/ of floating-point random numbers. Here are the interesting results: (defn average1 [seq1] (/ (reduce + seq1) (count seq1))) (defn average2 [seq1] (loop [remaining (rest seq1) cnt 1 accum (first seq1)] (if (empty? remaining) (/ accum cnt) (recur (rest remaining) (inc cnt) (+ (first remaining) accum) (defn average3 [seq1] (letfn [(count-add [ [cnt accum] numb] [(inc cnt) (+ accum numb)] ) ] (let [result-couple (reduce count-add [0 0] seq1)] (/ (result-couple 1) (result-couple 0) (defn average4 [seq1] (let [result-couple (reduce (fn [ [cnt accum] numb] [(inc cnt) (+ accum numb)] ) [0 0] seq1)] (/ (result-couple 1) (result-couple 0 user=> (time (dotimes [i 10] (average1 /mill-float-numbs/))) "Elapsed time: 526.674 msecs" user=> (time (dotimes [i 10] (average2 /mill-float-numbs/))) "Elapsed time: 646.608 msecs" user=> (time (dotimes [i 10] (average3 /mill-float-numbs/))) "Elapsed time: 405.484 msecs" user=> (time (dotimes [i 10] (average4 /mill-float-numbs/))) "Elapsed time: 394.31 msecs" --Larry On 3/30/12 1:31 AM, Benjamin Peter wrote: I think this topic is interesting. My guess would be, that the sequence would have been traversed completely by the reduce call and therefore clojure could know it's size and provide a constant time count. Could this be implemented? Is it? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Multiple ClojureScript (sub)projects with shared CLJS libraries per single clojure project
I haven't tried yet, but lein-cljsbuild [1] is meant to support multiple builds, and I believe something like the below config would be what you are looking for: :cljsbuild { :builds [{:source-path "src/cljs/project1" :compiler {:output-to "resources/public/cljs/script1.js" :externs ["externs/jquery.js"] :optimizations :advanced :pretty-print true}} {:source-path "src/cljs/project2" :compiler {:output-to "resources/public/cljs/script2.js" :externs ["externs/jquery.js"] :optimizations :advanced :pretty-print true}}]} [1] https://github.com/emezeske/lein-cljsbuild - Mark On Fri, Mar 30, 2012 at 12:16 PM, Tom Krestle wrote: > Hi, > > The project I envision would consist of multiple completely independent > conglomerates of CLJS scripts compiled into several separate final > production .js with one single Clojure server. > The reason for that is: > 1. Smaller size of .js to load at each stage > 2. Each time a browser transitions from one such a conglomerate to another > one, it has a chance to reset its memory. > 3. Better management of the overall project and easier sharing of components > across projects. > > Do you think this approach makes sense overall? > > Every single lein plugin and tools I encountered (including ClojureScript > One) support single .JS out of all CLJS scripts in src/. Is there an easy > way to leverage this? Or I'll have to build my own support of separate > compilation of CLJS subfolders into separate production .JS files (and > support for shared CLJS libraries)? > > Thank you, > Tom > > -- > 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 your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Multiple ClojureScript (sub)projects with shared CLJS libraries per single clojure project
At Relevance we are working on a project with just this structure. The project has a custom build script that produces mulitple advanced-mode-compiled .js files. We have not developed anything that would be generally reusable, but it's not hard to create custom code to do this. The ClojureScript compiler can be called just like any other function. Look at the compilation code in ClojureScript One for examples. -S -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
ClojureScript release 0.0-1006
Just pushed to Sonatype. Will be sync'd to other repos within 24 hours. Changes: http://build.clojure.org/job/clojurescript-release/9/ -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Source code as metadata
Another idea is to put :indentation metadata on vars, so user-defined macros could be indented properly. Currently I have (define-clojure-indent ...) with a number of forms in my emacs config file, and it seems to be pretty common solution. It'd be nice to replace this hack with an IDE-independent way to control the indentation. Phil, what do you think? Could it be experimentally implemented in clojure-mode? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Multiple ClojureScript (sub)projects with shared CLJS libraries per single clojure project
Hi, The project I envision would consist of multiple completely independent conglomerates of CLJS scripts compiled into several separate final production .js with one single Clojure server. The reason for that is: 1. Smaller size of .js to load at each stage 2. Each time a browser transitions from one such a conglomerate to another one, it has a chance to reset its memory. 3. Better management of the overall project and easier sharing of components across projects. Do you think this approach makes sense overall? Every single lein plugin and tools I encountered (including ClojureScript One) support single .JS out of all CLJS scripts in src/. Is there an easy way to leverage this? Or I'll have to build my own support of separate compilation of CLJS subfolders into separate production .JS files (and support for shared CLJS libraries)? Thank you, Tom -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Alternative download site for Clojure 1.3?
And like Sean mentioned, using Leiningen *really* helps. Especially when you have Emacs with clojure set up as well. On Fri, Mar 30, 2012 at 8:17 AM, Murphy McMahon wrote: > Learning Clojure is the fun part. Setup and maintenance of the tools is a > little less fun, IMO. But where there's a will (and a connection to > freenode), there's a way. > On Mar 30, 2012 9:09 AM, "Chris Webster" wrote: > >> Thanks for the advice, guys. >> >> I think it must just have been some temporary problem on the site, as I >> finally got it to download late last night. Now all I have to do is learn >> Clojure, eh? >> >> >> -- >> 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 >> your first post. >> To unsubscribe from this group, send email to >> clojure+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en > > -- > 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 > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
Yep, just make sure to mention that it's an offer and the location in the subject to make it easy to spot. On Fri, Mar 30, 2012 at 11:39 AM, David Powell wrote: > > > On Fri, Mar 30, 2012 at 1:35 PM, David Jagoe wrote: > >> G'day everyone >> >> I am increasingly relying on clojure and plan to use clojureclr and >> clojurescript in production too. I will soon need to hire a clojure >> developer and was hoping that someone could suggest a good place to post a >> job ad. I've never seen a job posted here but I would like to reach the >> community. >> > > They've been posted here before. I'm sure nobody will mind. > > -- > Dave > > -- > 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 > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
On Fri, Mar 30, 2012 at 1:35 PM, David Jagoe wrote: > G'day everyone > > I am increasingly relying on clojure and plan to use clojureclr and > clojurescript in production too. I will soon need to hire a clojure > developer and was hoping that someone could suggest a good place to post a > job ad. I've never seen a job posted here but I would like to reach the > community. > They've been posted here before. I'm sure nobody will mind. -- Dave -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Where to post job ad
On Friday, March 30, 2012 at 7:35 AM, David Jagoe wrote: > G'day everyone > I am increasingly relying on clojure and plan to use clojureclr and > clojurescript in production too. I will soon need to hire a clojure developer > and was hoping that someone could suggest a good place to post a job ad. I've > never seen a job posted here but I would like to reach the community. > > Try meetup.com and look for Clojure and/or Lispish groups. Contact them with details. I would be happy to put the word out in our group. Feel free to pass me details. Best of Luck, > Thanks > David > > -- > 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 > (mailto:clojure@googlegroups.com) > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > (mailto:clojure+unsubscr...@googlegroups.com) > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Cheap way to find function (defn) name using a macro?
On Thu, Mar 29, 2012 at 11:59 PM, Shantanu Kumar wrote: > The change needs to be least intrusive and doesn't justify exposing > more surface area than it should. It's a trade off. Injecting a version of defn that doesn't do anything different except make a new thing available inside the function isn't very intrusive. Functions that didn't call (find-name) or whatever wouldn't be affected at all. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Where to post job ad
G'day everyone I am increasingly relying on clojure and plan to use clojureclr and clojurescript in production too. I will soon need to hire a clojure developer and was hoping that someone could suggest a good place to post a job ad. I've never seen a job posted here but I would like to reach the community. Thanks David -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Alternative download site for Clojure 1.3?
Learning Clojure is the fun part. Setup and maintenance of the tools is a little less fun, IMO. But where there's a will (and a connection to freenode), there's a way. On Mar 30, 2012 9:09 AM, "Chris Webster" wrote: > Thanks for the advice, guys. > > I think it must just have been some temporary problem on the site, as I > finally got it to download late last night. Now all I have to do is learn > Clojure, eh? > > > -- > 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 > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Howto make println run as fast as python's
Hey All, I'm trying to print the numbers 0-99 as fast as possible. In python, this for i in range(99): print i runs super fast. In clojure, even with type hints, this is slow (def ^java.io.PrintWriter outoutout (java.io.PrintWriter. *out*)) ; yes, I know this one prints to infinity. It's still slow. (defn print1 [] (loop [num 0] (.println outoutout ^Integer num) (recur (unchecked-inc num (defn print2 [] (dotimes [n 99] (.println outoutout n))) Those two functions do not have reflection warnings and are using the raw java statements to print yet are still very slow. How would I print the numbers 0-99 as fast as python? Thank you for your time. -Sean -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Howto make println run as fast as python's
Whoops! I'm sorry. I tried compiling my code into an uberjar and then ran (defn print2 [] (dotimes [n 99] (.println outoutout n))) from main It's very very fast!! Wow! On Thu, Mar 29, 2012 at 8:07 PM, sean neilan wrote: > Hey All, > > I'm trying to print the numbers 0-99 as fast as possible. In python, > this > for i in range(99): > print i > runs super fast. > > In clojure, even with type hints, this is slow > > (def ^java.io.PrintWriter outoutout (java.io.PrintWriter. *out*)) > > ; yes, I know this one prints to infinity. It's still slow. > (defn print1 [] > (loop [num 0] > (.println outoutout ^Integer num) > (recur (unchecked-inc num > > (defn print2 [] > (dotimes [n 99] (.println outoutout n))) > > Those two functions do not have reflection warnings and are using the raw > java statements to print yet are still very slow. > > How would I print the numbers 0-99 as fast as python? > > Thank you for your time. > > -Sean > > -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Alternative download site for Clojure 1.3?
Thanks for the advice, guys. I think it must just have been some temporary problem on the site, as I finally got it to download late last night. Now all I have to do is learn Clojure, eh? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What's the efficient functional way to computing the average of a sequence of numbers?
Hi, On Mar 29, 10:43 pm, Alan Malloy wrote: > "Very likely" strikes me as a huge overstatement here. Most sequences > that you want to average won't be source-code literals, they'll be > lazy sequences, and those aren't counted. I think this topic is interesting. My guess would be, that the sequence would have been traversed completely by the reduce call and therefore clojure could know it's size and provide a constant time count. Could this be implemented? Is it? regards, Benjamin -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: partition-distinct
David Jagoe writes: Hi David, > Thanks! I had a nasty feeling that it could be done in a one-liner > using partition-by or something similar. But of course you need to be > able to look at previous elements... Here's a slightly shorter variant. --8<---cut here---start->8--- (defn partition-distinct [c] (reduce #(if (.contains (last %1) %2) (conj %1 [%2]) (conj (subvec %1 0 (dec (count %1))) (conj (last %1) %2))) [[]] (vec c))) --8<---cut here---end--->8--- The difference is that it'll always return a vector of vectors, and of course the .contains-check is linear for vectors, so it's quadratic to the size of `c` in total. If you don't care about the order of elements in each partition, then you can just go with a vector of sets and have the same performance as Cedric's recursive solution. --8<---cut here---start->8--- (defn partition-distinct [c] (reduce #(if ((last %1) %2) (conj %1 #{%2}) (conj (subvec %1 0 (dec (count %1))) (conj (last %1) %2))) [#{}] (vec c))) --8<---cut here---end--->8--- Bye, Tassilo -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: partition-distinct
Here's a version with reduce. It returns your elements as sets, but you could easily (map seq ,,,) if you really need lists. user=> (reduce (fn [r e] (if ((last r) e) (conj r #{e}) (update-in r [(dec (count r))] conj e))) [#{}] [1 2 2 3 4 4 1 6]) [#{1 2} #{2 3 4} #{1 4 6}] Cheers, Jay On Mar 30, 2012, at 4:29 AM, David Jagoe wrote: > On 29 March 2012 21:41, Cedric Greevey wrote: >> >> On Thu, Mar 29, 2012 at 4:18 PM, David Jagoe wrote: > >>> Given a sequence like this: [1 2 1 2 1 1 2 1 2 2 2] >>> >>> partition it to get this: [(1 2) (1 2) (1) (1 2) (1 2) (2) (2)] >>> ! >> >> (defn partition-distinct [s] >> (lazy-seq >>(loop [seen #{} s (seq s) part []] >> (if s >>(let [[f & r] s] >> (if (seen f) >>(cons (seq part) (partition-distinct s)) >>(recur (conj seen f) r (conj part f >>(if-let [part (seq part)] >> (list part)) >> > > Thanks! I had a nasty feeling that it could be done in a one-liner > using partition-by or something similar. But of course you need to be > able to look at previous elements... > > -- > 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 your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: partition-distinct
On 29 March 2012 21:41, Cedric Greevey wrote: > > On Thu, Mar 29, 2012 at 4:18 PM, David Jagoe wrote: > > Given a sequence like this: [1 2 1 2 1 1 2 1 2 2 2] > > > > partition it to get this: [(1 2) (1 2) (1) (1 2) (1 2) (2) (2)] > >! > > (defn partition-distinct [s] > (lazy-seq > (loop [seen #{} s (seq s) part []] > (if s > (let [[f & r] s] > (if (seen f) > (cons (seq part) (partition-distinct s)) > (recur (conj seen f) r (conj part f > (if-let [part (seq part)] > (list part)) > Thanks! I had a nasty feeling that it could be done in a one-liner using partition-by or something similar. But of course you need to be able to look at previous elements... -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en