Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-16 Thread Mayank Jain
ugust 14, 2015 at 9:43:52 AM UTC-5, Carlo wrote: >> >> Hey Mayank! >> >> Similarly to your attempt last time, you need to use gen/bind to get the >> result of a generator which you can then use to make a new generator. >> >> (defn- rand-interleave* [coll acc

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Gary Fredericks
new generator. > > (defn- rand-interleave* [coll acc] > (if (seq coll) > (gen/bind (gen/choose 0 (dec (count coll))) > (fn [index] > (let [value (first (get coll index)) > coll (->> (update-in coll [in

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Mayank Jain
> >> Thanks again for your help! :) >> >> On Fri, Aug 14, 2015 at 8:13 PM, Carlo Zancanaro < >> carlozancan...@gmail.com> wrote: >> >>> Hey Mayank! >>> >>> Similarly to your attempt last time, you need to use gen/bind to get >&

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Carlo Zancanaro
;> Similarly to your attempt last time, you need to use gen/bind to get the >> result of a generator which you can then use to make a new generator. >> >> (defn- rand-interleave* [coll acc] >> (if (seq coll) >> (gen/bind (gen/choose 0 (dec

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Mayank Jain
a generator which you can then use to make a new generator. > > (defn- rand-interleave* [coll acc] > (if (seq coll) > (gen/bind (gen/choose 0 (dec (count coll))) > (fn [index] > (let [value (first (get coll index)) >

Re: Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Carlo Zancanaro
Hey Mayank! Similarly to your attempt last time, you need to use gen/bind to get the result of a generator which you can then use to make a new generator. (defn- rand-interleave* [coll acc] (if (seq coll) (gen/bind (gen/choose 0 (dec (count coll))) (fn [index

Need suggestions on how to write rand-interleave test.check generator.

2015-08-14 Thread Mayank Jain
Hi Everyone, Here's the problem I am facing, I need to write a generator which takes any number of sequences, interleaves them but maintains the order within each sequence. Assume each sequence has at least one element. For example: (rand-interleave [1 2 3 4] [:a :b] [:A :B :C :D :E]) >

Re: Newbie re-implement 'interleave' found type conversion error

2015-04-02 Thread Stephen Wakely
Instead of : (if (s1) You just want : (if s1 s1 is a Long, not a function. On Thu, Apr 2, 2015 at 8:56 AM michael zhuang wrote: > : i'm new to clojure, when I try to implementation 'interleave', get error > from type convertion "java.lang。Long cannot be cast to

Newbie re-implement 'interleave' found type conversion error

2015-04-02 Thread michael zhuang
: i'm new to clojure, when I try to implementation 'interleave', get error from type convertion "java.lang。Long cannot be cast to clojure.lang.IFN". ; Now im reading stack trace, try to figure out what's going on.. (defn myIL [col1 col2] (loop [m []

Re: "interleave" with one argument

2013-09-17 Thread Paul
My bad - fixed in 1.6! On Friday, February 15, 2013 9:15:31 PM UTC, Denis Washington wrote: > > Hi, > > I just solved the "Replicate a Sequence" problem on 4clojure [1] using > "interleave". However, I noticed that "interleave" cannot be called w

Re: "interleave" with one argument

2013-09-17 Thread Paul
Hi Denis, This should also work, but fails for the same reason you outline: #(apply interleave (repeat %2 %1)) The jira ticket says the enhancement was closed in V1.3 although it is still failing in V1.5.1. P. On Friday, February 15, 2013 9:15:31 PM UTC, Denis Washington wrote: > &

Re: "interleave" with one argument

2013-02-15 Thread Andy Fingerhut
There's a ticket requesting that enhancement: http://dev.clojure.org/jira/browse/CLJ-863 Andy On Feb 15, 2013, at 1:15 PM, Denis Washington wrote: > Hi, > > I just solved the "Replicate a Sequence" problem on 4clojure [1] using > "interleave". Howeve

"interleave" with one argument

2013-02-15 Thread Denis Washington
Hi, I just solved the "Replicate a Sequence" problem on 4clojure [1] using "interleave". However, I noticed that "interleave" cannot be called with a single argument. My first attempt at solving the problem was like this: (defn replicate-n-times [xs n] (ap

Re: interleave

2012-10-04 Thread Marc Dzaebel
At the end, the problem is apply (apply + '(1 2 3 4 5 6 7 8 9 10)) is ~60 times slower than (+ 1 2 3 4 5 6 7 8 9 10) -- 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 n

Re: interleave

2012-10-04 Thread Stathis Sideris
You are right, but still: > (time (dotimes [_ 100] (dorun (apply mapcat list [[1 2 3] [7 7 7]] "Elapsed time: 4177.113292 msecs" > (time (dotimes [_ 100] (dorun (interleave [1 2 3] [7 7 7] "Elapsed time: 1156.658738 msecs" :-) Stathis On Thursday, 4 O

Re: interleave

2012-10-04 Thread Meikel Brandmeyer (kotarak)
Hi, you should probably add some dorun somewhere. Kind regards Meikel -- 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 wi

Re: interleave

2012-10-04 Thread Mayank Jain
On Thu, Oct 4, 2012 at 4:28 PM, Stathis Sideris wrote: > Maybe performance is the reason: > > > (time (dotimes [_ 100] (apply mapcat list [[1 2 3] [7 7 7]]))) > "Elapsed time: 1853.904337 msecs" > > (time (dotimes [_ 100] (interleave [1 2 3] [7 7 7]))) &

Re: interleave

2012-10-04 Thread Stathis Sideris
Maybe performance is the reason: > (time (dotimes [_ 100] (apply mapcat list [[1 2 3] [7 7 7]]))) "Elapsed time: 1853.904337 msecs" > (time (dotimes [_ 1000000] (interleave [1 2 3] [7 7 7]))) "Elapsed time: 81.000798 msecs" On Wednesday, 3 October 2012 19:21:37

Re: interleave

2012-10-03 Thread Marc Dzaebel
Thanks for the link! I proposed the change there. Am Mittwoch, 3. Oktober 2012 20:06:42 UTC+2 schrieb Andy Fingerhut: > > I don't know the reason for the current implementation rather than your > suggested one, but at least on the comment about 0 or 1 arguments has a > ticket for it: > > http://

Re: interleave

2012-10-03 Thread Andy Fingerhut
I don't know the reason for the current implementation rather than your suggested one, but at least on the comment about 0 or 1 arguments has a ticket for it: http://dev.clojure.org/jira/browse/CLJ-863 Andy On Oct 3, 2012, at 11:03 AM, Marc Dzaebel wrote: > clojure.core/interleave

interleave

2012-10-03 Thread Marc Dzaebel
clojure.core*/interleave *could be implemented as: (defn *interleave *[& s] (apply mapcat list s)) rather than: (defn *interleave* ([c1 c2] (lazy-seq (let [s1 (seq c1) s2 (seq c2)] (when (and s1 s2) (cons (first s1) (cons (firs

Re: seeking a lazy way to interleave a constant

2012-04-10 Thread Alan Malloy
On Apr 10, 12:36 am, David Powell wrote: > > As an aside.. I just looked at the source for this, what does the :static > > tag in the metadata do? > > From what I can make out... nothing.  I think it is left over from an > experiment to improve var lookup times prior to dynamic binding being > dis

Re: seeking a lazy way to interleave a constant

2012-04-10 Thread David Powell
> As an aside.. I just looked at the source for this, what does the :static tag in the metadata do? >From what I can make out... nothing. I think it is left over from an experiment to improve var lookup times prior to dynamic binding being disabled by default. -- You received this message becau

Re: seeking a lazy way to interleave a constant

2012-04-09 Thread Ben Mabey
On 4/9/12 9:10 PM, Cedric Greevey wrote: On Mon, Apr 9, 2012 at 10:31 PM, Andrew wrote: Given a lazy sequence of numbers is there a way to interleave a constant and get another lazy sequence? Say the first sequence is 1 2 3 4 ... I'd like the second sequence to be 1 0 2 0 3 0 4 0 T

Re: seeking a lazy way to interleave a constant

2012-04-09 Thread Cedric Greevey
On Mon, Apr 9, 2012 at 10:31 PM, Andrew wrote: > Given a lazy sequence of numbers is there a way to interleave a constant and > get another lazy sequence? Say the first sequence is 1 2 3 4 ... I'd like > the second sequence to be 1 0 2 0 3 0 4 0 > > Thanks in advance! us

Re: seeking a lazy way to interleave a constant

2012-04-09 Thread Ben Mabey
On 4/9/12 8:31 PM, Andrew wrote: Given a lazy sequence of numbers is there a way to interleave a constant and get another lazy sequence? Say the first sequence is 1 2 3 4 ... I'd like the second sequence to be 1 0 2 0 3 0 4 0 Thanks in advance! Yep, and it is even called inter

Re: seeking a lazy way to interleave a constant

2012-04-09 Thread dennis zhuang
D o you want this? user=> (def x (interleave (iterate inc 1) (repeat 0))) #'user/x user=> (take 10 x) (1 0 2 0 3 0 4 0 5 0) 2012/4/10 Andrew > Given a lazy sequence of numbers is there a way to interleave a constant > and get another lazy sequence? Say the first sequence i

seeking a lazy way to interleave a constant

2012-04-09 Thread Andrew
Given a lazy sequence of numbers is there a way to interleave a constant and get another lazy sequence? Say the first sequence is 1 2 3 4 ... I'd like the second sequence to be 1 0 2 0 3 0 4 0 Thanks in advance! -- You received this message because you are subscribed to the Google G

Re: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Alan Malloy
On Nov 3, 4:18 am, Ben Smith-Mannschott wrote: > On Thu, Nov 3, 2011 at 03:14, Alex Baranosky > > wrote: > > What a coincidence. My instinct would be to make (interleave) return an > > empty seq, instead of nil. I wonder the trade-offs between the two? > > There is no

Re: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Ben Smith-Mannschott
hile this is true, the following is dangerous > >> Returning nil has the advantage that nil is false in a boolean context. >> >> (when-let [s (apply interleave ...)] ... ) > > The input sequences to interleave might be all nil. Since interleave is also > lazy, you have to

Re: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Meikel Brandmeyer
is false in a boolean context. > > (when-let [s (apply interleave ...)] ... ) The input sequences to interleave might be all nil. Since interleave is also lazy, you have to put a seq around the apply when you use it in a when-let. Whether (interleave) returns nil or () is not really impor

Re: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Ben Smith-Mannschott
On Thu, Nov 3, 2011 at 03:14, Alex Baranosky wrote: > What a coincidence. My instinct would be to make (interleave) return an > empty seq, instead of nil. I wonder the trade-offs between the two? There is no such thing as an empty seq. Or put another way, the empty seq *is* nil. You'

Re: Any reason interleave needs 2 or more collections?

2011-11-02 Thread Alex Baranosky
What a coincidence. My instinct would be to make (interleave) return an empty seq, instead of nil. I wonder the trade-offs between the two? On Wed, Nov 2, 2011 at 10:02 PM, Alan Malloy wrote: > > http://groups.google.com/group/clojure-dev/browse_thread/thread/b81c6c8621629960/b73ed6ba28

Re: Any reason interleave needs 2 or more collections?

2011-11-02 Thread Alan Malloy
/thread/b81c6... > > http://www.google.com/url?sa=D&q=http://dev.clojure.org/jira/browse/C... > > On Nov 2, 6:28 pm, Alex Baranosky > wrote: > > > > > > > > > Something interesting I've noticed: > > > I've recently realized I could

Re: Any reason interleave needs 2 or more collections?

2011-11-02 Thread Alan Malloy
've noticed: > > I've recently realized I could simplify some application code of mine by > using interleave.  I immediately noticed that in the spot I was using it I > would never be sure to have 2+ streams (from > here<https://github.com/AlexBaranosky/EmailClojMatic/blob/m

Re: Any reason interleave needs 2 or more collections?

2011-11-02 Thread Sean Corfield
code of mine by > using interleave.  I immediately noticed that in the spot I was using it I > would never be sure to have 2+ streams (from here): > > (defmethod parse-reminder-dates :day-of-month [s] >    (let [[ordinals-part] (re-captures day-of-month-identifier-regex s) >

Any reason interleave needs 2 or more collections?

2011-11-02 Thread Alex Baranosky
Something interesting I've noticed: I've recently realized I could simplify some application code of mine by using interleave. I immediately noticed that in the spot I was using it I would never be sure to have 2+ streams (from here<https://github.com/AlexBaranosky/EmailClojMatic/bl

Re: (apply interleave [[1 2]])

2010-06-06 Thread Eugen Dück
And we could actually also add an no-arg version. My own version of interleave that I use looks like this: (defn interleav ([] nil) ([c] (seq c)) ([c1 c2] (interleave c1 c2)) ([c1 c2 & colls] (apply interleave c1 c2 colls))) I guess that's as generic as it gets. Does Rich

Re: (apply interleave [[1 2]])

2010-05-31 Thread Daniel Werner
On May 31, 10:07 pm, Daniel Werner wrote: > quantitative logic That should have been "quantification logic". -- 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 membe

Re: (apply interleave [[1 2]])

2010-05-31 Thread Daniel Werner
On May 30, 12:51 am, Eugen Dück wrote: > How often do you do: > (+ 5) > or > (* 3) > > ? But you might have used something like > (apply + coll) > or > (reduce + coll) > > and under certain circumstances your coll might have had only one > element. This is a good line of reasoning. Let's add an e

Re: (apply interleave [[1 2]])

2010-05-31 Thread Paul Hobbs
Makes sense. -- Paul Hobbs On Sat, May 29, 2010 at 11:51 PM, Eugen Dück wrote: > Paul, > > I already gave a minimal example of the code it makes simpler, i.e. > work in the first place: > > (apply interleave some-colls) > > I ran into this a couple of times, and

Re: (apply interleave [[1 2]])

2010-05-29 Thread Eugen Dück
Paul, I already gave a minimal example of the code it makes simpler, i.e. work in the first place: (apply interleave some-colls) I ran into this a couple of times, and wrote my own variant of interleave that handles the one-coll case. I'd rather see this case handled by interleave. How

Re: (apply interleave [[1 2]])

2010-05-29 Thread Michael Gardner
end up calling a function with "degenerate" arguments in corner cases. I much prefer functions that handle such degenerate arguments gracefully when it makes sense to do so, which it absolutely does for interleave. -- You received this message because you are subscribed to the Google Group

Re: (apply interleave [[1 2]])

2010-05-29 Thread Paul Hobbs
What code would this make simpler? Are you constantly having to check this special case? If not, I don't see a reason to include it. -- Paul Hobbs On Sat, May 29, 2010 at 1:32 AM, Eugen Dück wrote: > When I do > > (apply interleave some-colls) > > and some-colls is a se

(apply interleave [[1 2]])

2010-05-28 Thread Eugen Dück
When I do (apply interleave some-colls) and some-colls is a sequence/collection of only one sequence/ collection, it will throw: user=> (apply interleave [[1 2]]) java.lang.IllegalArgumentException: Wrong number of args passed to: core$interleave (NO_SOURCE_FILE:0) (Of course I don't

Re: inverse of interleave = unravel

2009-12-02 Thread ataggart
On Dec 2, 12:02 pm, Chouser wrote: > On Wed, Dec 2, 2009 at 2:06 PM, ataggart wrote: > > > On Dec 2, 9:10 am, Konrad Kułakowski (kony) > > wrote: > >> Recently I need something which works as "inverse of interleave" > > > How about this? > &g

Re: inverse of interleave = unravel

2009-12-02 Thread Chouser
On Wed, Dec 2, 2009 at 2:06 PM, ataggart wrote: > > > On Dec 2, 9:10 am, Konrad Kułakowski (kony) > wrote: >> Recently I need something which works as "inverse of interleave" > > How about this? > > (defn skip [coll n] >  (lazy-seq >    (when-let [s

Re: inverse of interleave = unravel

2009-12-02 Thread Christophe Grand
Hi, 2009/12/2 Konrad Kułakowski (kony) > Recently I need something which works as "inverse of interleave" > > I did something like that: > > (defn unravel [expr-list] >(loop [flist () slist () tic-tac 0 olist expr-list] >

Re: inverse of interleave = unravel

2009-12-02 Thread ataggart
On Dec 2, 9:10 am, Konrad Kułakowski (kony) wrote: > Recently I need something which works as "inverse of interleave" > > I did something like that: > > (defn unravel [expr-list] >         (loop [flist () slist () tic-tac 0 olist expr-list] >        

Re: inverse of interleave = unravel

2009-12-02 Thread Wilson MacGyver
the only solution comes to mind is a two pass partition. ie (flatten (partition 1 2 dl)) for the first list and (flatten (partition 1 2 (rest dl))) for the 2nd list. 2009/12/2 Konrad Kułakowski (kony) : > Recently I need something which works as "inverse of interleave" > > I

inverse of interleave = unravel

2009-12-02 Thread kony
Recently I need something which works as "inverse of interleave" I did something like that: (defn unravel [expr-list] (loop [flist () slist () tic-tac 0 olist expr-list] (let [item (first olist)] (if (