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
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
>
>> 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
>&
;> 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
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))
>
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
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])
>
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
: 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 []
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
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:
>
&
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
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
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
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
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
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])))
&
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
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://
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
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
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
> 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
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
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
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
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
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
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
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
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
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'
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
/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
'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
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)
>
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
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
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
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
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
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
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
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
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
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
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
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]
>
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]
>
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
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 (
51 matches
Mail list logo