Iterate through transient map?

2018-04-27 Thread Didier
Don't think so. But the conversion back and forth is O(1). So it shouldn't affect performance. -- 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 moderate

Iterate through transient map?

2018-04-27 Thread Tom Locke
I can iterate through a transient vector, as count and nth can be used directly on the transient. Is there any way to iterate through the keys (or key/value pairs) of a transient hash, other than just making a persistent version of it? I guess the meta-question is, any advice on finding which

Iterate over transient map

2016-05-13 Thread JvJ
on the transient itself without having to call persistent! if possible. I realize that the transient-to-persistent conversion should ideally be O(1), but there are certain cases where I have to iterate over some structures to achieve what I'm looking for. Is there a way to get some kind of ite

Re: arity-3 `iterate`

2015-11-16 Thread Ben Wolfson
ncomp would be faster if it's implemented a la exponentiation by squaring. On Mon, Nov 16, 2015 at 12:55 PM, Ben Wolfson wrote: > If you rearrange the arguments of your proposed three-argument iterate: > > (defn iterate > ... > ([f n x] >(if (zero? n) > x

Re: arity-3 `iterate`

2015-11-16 Thread Ben Wolfson
If you rearrange the arguments of your proposed three-argument iterate: (defn iterate ... ([f n x] (if (zero? n) x (recur f (f x) (dec n it supports partial application of the multiply-composed function to different arguments more easily, which suggests redefinition as

arity-3 `iterate`

2015-11-16 Thread Jason Felice
I *frequently* see: (nth (iterate foo bar) n) And: (->> (iterate foo bar) (drop n) first) I've also coded this in `avi` after being surprised no such thing exists: (defn n-times [thing n a-fn] (reduce (fn [thing n] (a-fn thing)) thing (range n))) (which

Re: newbie Q: how to tweak file-seq (original: how to selectively iterate through a tree of directories) ?

2015-10-05 Thread Andy-
Try to adapt my code: https://gist.github.com/rauhs/63054a06631c0be598d3 where you change your accept function to incorporate: http://stackoverflow.com/questions/813710/java-1-6-determine-symbolic-links HTH On Saturday, October 3, 2015 at 5:14:51 PM UTC-4, hpw...@gmail.com wrote: > > The direc

Re: newbie Q: how to tweak file-seq (original: how to selectively iterate through a tree of directories) ?

2015-10-03 Thread Gary Verhaegen
Sorry, I meant :when, not :where. Though it won't change the problem. Here's the rub: first file-seq produces its whole seq, then for comes along and filters out some of it. So (ignoring lazyness) file-seq ha already traversed symbolic links (at least for folders) by the time for sees it. I fear

Re: newbie Q: how to tweak file-seq (original: how to selectively iterate through a tree of directories) ?

2015-10-03 Thread hpwei01
The directory structure is /path/top/dir1 /path/top/dir1/f1 /path/top/dir1/f2 /path/top/dir2 -> /another/path/dir2 -- /another/path/dir2/g1 /another/path/dir2/g2 I tried this (following suggestion): (for [file (file-seq dir) :while (.isFile file)] (.getPath file))

Re: newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread Gary Verhaegen
I'm on Windows at the moment, so I can't test, but I think you can filter on isFile: (for [file (file-seq dir) :where (.isFile file)] (.getName file)) should work, I think. On 3 October 2015 at 07:36, wrote: > Under linux, I have a tree of directories like this: > > /path/top > > /path

newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread hpwei01
Under linux, I have a tree of directories like this: /path/top /path/top/dir1 (in here there are two files f1, f2) /path/top/dir2 -> /another-path/dir2 (a symbolic link) and under /another-path/dir2 there are two files g1, g2 If I use below code, I would get a list of file

Re: A generalization of iterate

2015-09-28 Thread Yoshinori Kohyama
Hi nchurch and all. Your idea to generalize `iterate` looks very cool for me. I wrote another implementation not to consume stack. (defn generate' [f h & r] (cons h (lazy-seq (apply generate' f (reverse (cons (apply f h r) (reverse r))) will work, if it i

Re: A generalization of iterate

2015-09-23 Thread nchurch
, Max Countryman wrote: > > Your problem with recur is because you can only recur from the tail > position. > > On Sep 23, 2015, at 12:28, nchurch > > wrote: > > Yeah, it consumes stack just like the Clojurescript version of Iterate. > I'm curious if anyo

Re: A generalization of iterate

2015-09-23 Thread Max Countryman
Your problem with recur is because you can only recur from the tail position. > On Sep 23, 2015, at 12:28, nchurch wrote: > > Yeah, it consumes stack just like the Clojurescript version of Iterate. I'm > curious if anyone knows how to avoid this. The Clojure version of I

Re: A generalization of iterate

2015-09-23 Thread nchurch
Yeah, it consumes stack just like the Clojurescript version of Iterate. I'm curious if anyone knows how to avoid this. The Clojure version of Iterate is Java; and for some reason 'recur' can't be used inside of lazy-cat (not really documented, but apparently true). On T

Re: A generalization of iterate

2015-09-22 Thread Max Countryman
gt; exercise. It occurred to me that the iterate function could be generalized > in a reasonable way, so that the next value is generated by applying the > function to the last N items so far, where N is the number of initial > arguments beyond the function. Thus: > > (generate i

A generalization of iterate

2015-09-22 Thread nchurch
I was going through 4clojure (highly recommended!) and doing the Fibonacci exercise. It occurred to me that the iterate function could be generalized in a reasonable way, so that the next value is generated by applying the function to the last N items so far, where N is the number of initial

Re: How to iterate over maps and drop one specific element each time?

2014-06-11 Thread Jonathan Winandy
-11 21:09 GMT+08:00 Hussein B. : > > Hi, >> >> I have a seq of maps: >> >> [ {:op :e :v 1} {:op :n :b 2} {:op :m :z 2.3} ] >> >> How to iterate over the sequence and extracting only the non-op entries? >> >> Desired result is: >> >>

Re: How to iterate over maps and drop one specific element each time?

2014-06-11 Thread Di Xu
(map #(dissoc % :op) [{:op :e :v 1} {:op :n :b 2} {:op :m :z 2.3}]) 2014-06-11 21:09 GMT+08:00 Hussein B. : > Hi, > > I have a seq of maps: > > [ {:op :e :v 1} {:op :n :b 2} {:op :m :z 2.3} ] > > How to iterate over the sequence and extracting only the non-op entries?

How to iterate over maps and drop one specific element each time?

2014-06-11 Thread Hussein B.
Hi, I have a seq of maps: [ {:op :e :v 1} {:op :n :b 2} {:op :m :z 2.3} ] How to iterate over the sequence and extracting only the non-op entries? Desired result is: [ {:v 1} {:b 2} {:z 2.3} ] Thanks for help and time. -- You received this message because you are subscribed to the Google

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-12-02 Thread Christophe Grand
(filter >> (fn isprime[n] >> >> (every? >> #(pos? (mod n %)) >> (take-while #(<=(* % %)n) primes))) >> (iterate inc 3 >> user=> (take 50 primes) >> (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-12-02 Thread maclo
Hi user=> (def primes > (cons 2 > (filter > (fn isprime[n] > > (every? > #(pos? (mod n %)) > (take-while #(<=(* % %)n) primes))) > (iterate inc 3 > user=> (take 50 primes) > (2 3 5 7 11 13 17 19 23 29 31 37

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-30 Thread Christophe Grand
Hallo, On Thu, Nov 29, 2012 at 11:20 PM, Ulrich wrote: > Now should we consider this a clojure bug? > It is, see http://dev.clojure.org/jira/browse/CLJ-457 What clojure version are you using btw to get the exceptions? master from Github with my patch to CLJ-457 applied :-) Now, that's clear

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-29 Thread Ulrich
from '(2 3 5) to '(2 3) realizing that it didn't work any longer. Then finding that with "iterate" it did. Then further reduced to '(2) and '(), finding that it still worked. What clojure version are you using btw to get the exceptions? I never got those excep

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-29 Thread Christophe Grand
On Wed, Nov 28, 2012 at 5:24 PM, Ulrich wrote: > Then I found the solution with "iterate" and then further reduced starting > values to '(2) and then to '() what worked as well, > as every? returns true for empty sequences, what is right from a logical > point of

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Ulrich
... so the main problem seems to be chunked vs. unchunked sequences in corecursion. I read a bit into "chunked sequences" and so far it seems that a sequence is either chunked with size 32 or unchunked. So a "rechunk" of variable size seems of no use. Instead I found an "unchunk" at stackoverfl

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Ulrich
x27;t work any more, as 25 is included in the first "batch" (of the so called chunked sequence) which is only tested against the starting value of primes. Then I found the solution with "iterate" and then further reduced starting values to '(2) and then to '() wha

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Christophe Grand
> (every? > #(pos? (mod n %)) > (take-while #(<=(*%%)n) primes))) > (iterate inc 3 > > > So now we have two behaviours to explain: > 1/ why it works with iterate > 2/ why it doesn't work with range > The difference comes from

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Christophe Grand
? #(pos? (mod n %)) (take-while #(<=(*%%)n) primes))) (iterate inc 3 So now we have two behaviours to explain: 1/ why it works with iterate 2/ why it doesn't work with range The difference comes from range returning a chunked seq (which explain the batched processing you

(iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Ulrich
primes) ) ) (iterate inc 2) ) ) Seems there's nothing wrong with that, it's just the algorithm straightly set down in a functional way. And it works correctly as one can quickly confirm by "(take 50 primes)". But if replacing "(iterate inc 2)" with "(drop 2 (range))&

Re: idiomatic use of iterate + cycle ?

2012-09-16 Thread Jim - FooBar();
exactly!!! this is great stuff indeed! I spent all morning trying to find more info than the actual docstring but I can't find anything! It seems to work as advertised though...very handy but it only works with 1.5 :-) (reduce #(if (= 3 %2) (reduced %) (conj % %2)) [] (range 5)) =>[0 1 2] J

Re: idiomatic use of iterate + cycle ?

2012-09-16 Thread Sean Corfield
On Sun, Sep 16, 2012 at 5:15 AM, Jim - FooBar(); wrote: > It turns out that reduce is exactly what I need...I didn't know this but > there is a handy 'reduced' fn that makes it easy to terminate from within a > reduce at any given time. At least this is what i understand from the > docs...so the f

Re: idiomatic use of iterate + cycle ?

2012-09-16 Thread Jim - FooBar();
o create a 'tournament' fn that basically alternates between players (in turns) and calls soem 'move' fn on each. Now, obviously this can be done with loop/recur no problem, however perhaps a combination of cycle & iterate is more appropriate...so I'm, thinking something

idiomatic use of iterate + cycle ?

2012-09-16 Thread Jim - FooBar();
Hi all, I'm trying to come up with a way to create a 'tournament' fn that basically alternates between players (in turns) and calls soem 'move' fn on each. Now, obviously this can be done with loop/recur no problem, however perhaps a combination of cycle & iter

Re: Iterate and stack overflow

2012-06-14 Thread vmargioulas
Thanks, this explains the stack overflow On Thursday, June 14, 2012 4:12:28 PM UTC+3, Dave Sann wrote: > > also > > (first (drop 100000 (iterate #(doall (map inc %)) (range 10 > > so the better answer is probably - because map is lazy > > > On Thursday, 14 June

Re: Iterate and stack overflow

2012-06-14 Thread Dave Sann
also (first (drop 10 (iterate #(doall (map inc %)) (range 10 so the better answer is probably - because map is lazy On Thursday, 14 June 2012 23:06:27 UTC+10, Dave Sann wrote: > > I suspect that the answer is the use of partial and the implementation of > iterate > >

Re: Iterate and stack overflow

2012-06-14 Thread Dave Sann
I suspect that the answer is the use of partial and the implementation of iterate with (comp vec... you force realisation of the vector without this I think you get (partial map (partial map (partial ) as f is repeatedly applied if you do this, (first (drop 10 (iterate #(apply list

Re: Iterate and stack overflow

2012-06-14 Thread Dave Sann
ah...but does for 1 On Thursday, 14 June 2012 22:58:58 UTC+10, Dave Sann wrote: > > It doesn't overflow for me. > > > user=> (first (drop 1000 (iterate (partial map inc) (range 10 > (1000 1001 1002 1003 1004 1005 1006 1007 1008 1009) > > > On Thu

Re: Iterate and stack overflow

2012-06-14 Thread Dave Sann
It doesn't overflow for me. user=> (first (drop 1000 (iterate (partial map inc) (range 10 (1000 1001 1002 1003 1004 1005 1006 1007 1008 1009) On Thursday, 14 June 2012 22:52:33 UTC+10, vmargioulas wrote: > > Can someone explain why > ... iterating over a sequence cause

Iterate and stack overflow

2012-06-14 Thread vmargioulas
Can someone explain why ... iterating over a sequence cause a stack overflow (first (drop 1000 (iterate (partial map inc) (range 10 -> java.lang.StackOverflowError ...but iterating over a vector works ok? (first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 - > [100

Re: iterate with side-effect function?

2011-09-28 Thread siyu798
Thanks everyone. -- 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, se

Re: iterate with side-effect function?

2011-09-28 Thread Meikel Brandmeyer (kotarak)
Hi, there is ye olde loop/recur, which handles side effects (and this case in particular) quite nicely. The only advantage of iterate is that the sequence of intermediate values is available to an outside observer. However, as stated before: mixing lazy sequences with side effects is asking

Re: iterate with side-effect function?

2011-09-28 Thread siyu798
Odyssomay, While does not work in this case as ctx will be "updated" on each iteration and fed to the next iteration. Thanks, siyu -- 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 t

Re: iterate with side-effect function?

2011-09-28 Thread Jonathan Fischer Friberg
How about while? (while not-finished (do stuff ...)) On Wed, Sep 28, 2011 at 4:23 AM, Nathan Sorenson wrote: > Quite often I convince myself I need state or some effectful trigger, but > further thought reveals a simpler stateless approach. > > That being said--if you absolutely need to be do

Re: iterate with side-effect function?

2011-09-27 Thread Nathan Sorenson
Quite often I convince myself I need state or some effectful trigger, but further thought reveals a simpler stateless approach. That being said--if you absolutely need to be doing something based on effects, something that absolutely can't be tracked via values in a purely functional way--like

Re: iterate with side-effect function?

2011-09-27 Thread siyu798
Nathan, Thanks for the explanation, what i'm trying to do is to "repeatedly" run a side-effect function until the return value of it meets certain criteria. It could have been done using loop/recur as shown below, and wondering if there's alternatives. Is a there general approach to accomp

Re: iterate with side-effect function?

2011-09-27 Thread Nathan Sorenson
Because the fn is wrapped in a lazy sequence, the effects won't run if you ask for the same value again-- For instance: (def a (iterate (fn [cnt] (prn cnt) ;; save data to csv (inc cnt)) 0)) (nth a 5) ... all the effects are fired. (nt

iterate with side-effect function?

2011-09-27 Thread siyu798
Hi, From clojure doc, it states iterate takes a side-effect free function, and what's the implication if the function has side-effect as follow? (->> 0 (iterate (fn [cnt] (prn cnt) ;; save data to csv (Thread/sleep 6000)

Re: iterate?

2011-07-04 Thread Alan Malloy
Or, to defeat the purpose of iterate entirely: (= (repeat 100 :foo) (take 100 (iterate (constantly :foo) :foo))) On Jul 4, 3:51 am, Christophe Grand wrote: > => (= (repeat 100 :foo) >         (take 100 (iterate identity :foo))) > true > > hth, > > Christophe > >

Re: iterate?

2011-07-04 Thread Christophe Grand
=> (= (repeat 100 :foo) (take 100 (iterate identity :foo))) true hth, Christophe On Mon, Jul 4, 2011 at 12:39 PM, Antonio Recio wrote: > Do you know how to solve this? > > (= (repeat 100 :foo) > (take 100 (iterate ___ :foo))) > > -- > You received this

iterate?

2011-07-04 Thread Antonio Recio
Do you know how to solve this? (= (repeat 100 :foo) (take 100 (iterate ___ :foo))) -- 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: clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-06 Thread hoeck
nt for map, filter, reduce and friends, but as a more convenient replacement to loop/recur and areduce. Maybe, if there is some interest in it, we could make a unified iterate implementation? Erik On 6 Nov., 01:03, Daniel Janus wrote: > Dear all, > > I am happy to announce the public avail

Re: clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread Timothy Pratley
On Nov 6, 12:51 pm, Daniel Janus wrote: > As another example, consider multiplying the first 42 elements of a > list of numbers by 42, and leaving the rest unchanged. It's much more > straightforward for me to write (and then read) > > (iter (for x in lst) >      (for i from 0) >      (collect (

Re: clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread Daniel Janus
(3 4 5 2 1) (4 5 3 2) (5 4 3)) > > I hate to be the party-pooper in this bunch On the contrary, criticism is most welcome too. Especially when the comments show a way of solving a problem (as in the case of the sliding window) I would never have thought of. Thank you (and also to Kyle for offer

Re: [ANN] clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread John Harrop
>(iter (for s on [1 2 3 4 5]) >(for q initially () then (cons (first s) q)) >(collect (cons (first s) (concat (take 2 (rest s)) (take 2 > q) >==> ((1 2 3) (2 3 4 1) (3 4 5 2 1) (4 5 3 2) (5 4 3)) I hate to be the party-pooper in this bunch, but what's the adva

Re: clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread kyle smith
What's wrong with (map + [31 41 59 26] (iterate inc 1)) ? (use 'clojure.contrib.seq-utils) (defn sliding-window [coll size] (let [idx (into {} (indexed coll))] (map #(vals (select-keys idx (range (- % size) (+ % size 1 (range (count coll) This is the same as y

Re: [ANN] clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread Stefan Arentz
On 2009-11-05, at 7:03 PM, Daniel Janus wrote: > > Dear all, > > I am happy to announce the public availability of clj-iter, an > Iterate- > like iteration macro. It is free (available under the terms of MIT > license) and can be found on GitHub: http://github.com/nathell

[ANN] clj-iter, an iteration macro for Clojure inspired by Common Lisp's Iterate

2009-11-05 Thread Daniel Janus
Dear all, I am happy to announce the public availability of clj-iter, an Iterate- like iteration macro. It is free (available under the terms of MIT license) and can be found on GitHub: http://github.com/nathell/clj-iter The design goal was to keep it as simple as possible, and make it blend

Re: iterate

2008-11-13 Thread Parth Malwankar
On Nov 13, 12:25 pm, notallama <[EMAIL PROTECTED]> wrote: > i put this at the end of my boot.clj for added fun: > > (defn iterate >   "returns a lazy seq of arg1, arg2 ... argn, (f arg1 ... argn), (f > arg2 ... argn (f arg1 ... argn)), etc." >   [f & [x &a

iterate

2008-11-12 Thread notallama
i put this at the end of my boot.clj for added fun: (defn iterate "returns a lazy seq of arg1, arg2 ... argn, (f arg1 ... argn), (f arg2 ... argn (f arg1 ... argn)), etc." [f & [x & rest :as all]] (lazy-cons x (apply iterate f (concat rest [(apply f all)] user=>