Re: I can not find any function that might give rise tothisStackOverflow error
Thank you again. This has been educational. On Monday, April 3, 2017 at 1:07:18 PM UTC-4, Sean Corfield wrote: > > This is lazy: (remove #{(first scores)} scores) > > > > Since find-related-positive-negative-true-false-records does not realize > set-of-scores in order to return its value, then you still have laziness on > scores. > > > > I think, in your original, if you wrap that remove call with doall, you > won’t get a stack overflow. > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > On 4/3/17, 9:24 AM, "clo...@googlegroups.com on behalf of > piast...@gmail.com " <clo...@googlegroups.com > on behalf of piast...@gmail.com > wrote: > > > > I apologize for my ignorance, but why is this lazy? > > > > (conj vector-of-maps-of-vector-key-and-score > (find-related-positive-negative-true-false-records scores (first scores > > > > Assuming the functions are not called eagerly simply because I am in a > loop. But what would the eager version of this be? I > > > > > On Sunday, April 2, 2017 at 1:42:20 AM UTC-4, Sean Corfield wrote: > > > But does that mean one can't use functions to build up sequences in a > loop? That seems to limit loops a great deal. > > You just need to ensure you are building the sequences in an eager manner, > rather than a lazy manner. > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > *From: *piast...@gmail.com > *Sent: *Saturday, April 1, 2017 9:56 PM > *To: *Clojure > *Subject: *Re: I can not find any function that might give rise > tothisStackOverflow error > > > > > > Because when you recur in your loop, you’re passing in lazy sequences, > so those > > are essentially building up a giant stack of delayed evaluations – and > when you hit bottom > > and try to realize those, that’s when your stack overflow hits you. > > I was thinking the answer had something to do with the lazyness, but I > wasn't sure because the app seemed to die before the loop finished -- which > I assume is before the functions were realized. But it is possible the > logging functions were slow and didn't show the whole truth. I am grateful > to have someone with your experience clarify this. > > But does that mean one can't use functions to build up sequences in a > loop? That seems to limit loops a great deal. > > > > On Saturday, April 1, 2017 at 10:22:04 PM UTC-4, Sean Corfield wrote: > > Because when you recur in your loop, you’re passing in lazy sequences, so > those are essentially building up a giant stack of delayed evaluations – > and when you hit bottom and try to realize those, that’s when your stack > overflow hits you. > > > > By contrast, your reduce code is eager so the work is done as you work > through the sequence, instead of “stacked up” lazily, to be done later. > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > *From: *piast...@gmail.com > *Sent: *Saturday, April 1, 2017 6:52 PM > *To: *Clojure > *Subject: *Re: I can not find any function that might give rise to > thisStackOverflow error > > > > > Crazy! I re-wrote the (loop) to use (reduce) instead and now everything > works: > > > (defn loop-over-scores > [set-of-scores] > "2017-03-08 -- called from start.clj" > (reduce >;; 2017-04-01 -- we assume vector-with-path-score looks like this: >;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] >;; so we do a minor bit of destructuring >(fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] > (conj vector-of-maps-of-vector-key-and-score >(dire/supervise #'map-of-vector-path-and-true-false-scores > vector-with-path))) >[] >set-of-scores)) > > > The StackOverflow error is gone. > > Sad to say, I'm left with a feeling as if I know nothing about Clojure. I > don't know why (loop) gave me a StackOverflow error whereas (reduce) works > just fine. This is black magic to me, which, sad to say, is not a > comfortable feeling. > > > > > > > On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: &g
Re: I can not find any function that might give rise tothisStackOverflow error
This is lazy: (remove #{(first scores)} scores) Since find-related-positive-negative-true-false-records does not realize set-of-scores in order to return its value, then you still have laziness on scores. I think, in your original, if you wrap that remove call with doall, you won’t get a stack overflow. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood On 4/3/17, 9:24 AM, "clojure@googlegroups.com on behalf of piastkra...@gmail.com" <clojure@googlegroups.com on behalf of piastkra...@gmail.com> wrote: I apologize for my ignorance, but why is this lazy? (conj vector-of-maps-of-vector-key-and-score (find-related-positive-negative-true-false-records scores (first scores Assuming the functions are not called eagerly simply because I am in a loop. But what would the eager version of this be? I On Sunday, April 2, 2017 at 1:42:20 AM UTC-4, Sean Corfield wrote: > But does that mean one can't use functions to build up sequences in a loop? > That seems to limit loops a great deal. You just need to ensure you are building the sequences in an eager manner, rather than a lazy manner. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood From: piast...@gmail.com Sent: Saturday, April 1, 2017 9:56 PM To: Clojure Subject: Re: I can not find any function that might give rise tothisStackOverflow error > Because when you recur in your loop, you’re passing in lazy sequences, so > those > are essentially building up a giant stack of delayed evaluations – and when > you hit bottom > and try to realize those, that’s when your stack overflow hits you. I was thinking the answer had something to do with the lazyness, but I wasn't sure because the app seemed to die before the loop finished -- which I assume is before the functions were realized. But it is possible the logging functions were slow and didn't show the whole truth. I am grateful to have someone with your experience clarify this. But does that mean one can't use functions to build up sequences in a loop? That seems to limit loops a great deal. On Saturday, April 1, 2017 at 10:22:04 PM UTC-4, Sean Corfield wrote: Because when you recur in your loop, you’re passing in lazy sequences, so those are essentially building up a giant stack of delayed evaluations – and when you hit bottom and try to realize those, that’s when your stack overflow hits you. By contrast, your reduce code is eager so the work is done as you work through the sequence, instead of “stacked up” lazily, to be done later. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood From: piast...@gmail.com Sent: Saturday, April 1, 2017 6:52 PM To: Clojure Subject: Re: I can not find any function that might give rise to thisStackOverflow error Crazy! I re-wrote the (loop) to use (reduce) instead and now everything works: (defn loop-over-scores [set-of-scores] "2017-03-08 -- called from start.clj" (reduce ;; 2017-04-01 -- we assume vector-with-path-score looks like this: ;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] ;; so we do a minor bit of destructuring (fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] (conj vector-of-maps-of-vector-key-and-score (dire/supervise #'map-of-vector-path-and-true-false-scores vector-with-path))) [] set-of-scores)) The StackOverflow error is gone. Sad to say, I'm left with a feeling as if I know nothing about Clojure. I don't know why (loop) gave me a StackOverflow error whereas (reduce) works just fine. This is black magic to me, which, sad to say, is not a comfortable feeling. On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: Well, I am out of ideas. Let's assume I'll re-write this some other way. What would be better than using (loop)? What would be less likely to cause StackOverflow, or at least reveal why I'm seeing it. On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: I have a function that will run repeatedly, so I use the at-at library to call it: https://github.com/overtone/at-at I don't think this is the problem. Sad to say, the Error is catching a StackOverflow, which I'm having trouble finding. I don't see a place where I call a function recursively, so I don't see where any of this becomes stackoverflow. I'm using Dire to catch errors, but for now I'm just logging them. I don't see anything fancy or clever that would give me a stackoverflow, and yet this anonymous function called b
Re: I can not find any function that might give rise tothisStackOverflow error
I apologize for my ignorance, but why is this lazy? (conj vector-of-maps-of-vector-key-and-score (find-related-positive-negative-true-false-records scores (first scores Assuming the functions are not called eagerly simply because I am in a loop. But what would the eager version of this be? I On Sunday, April 2, 2017 at 1:42:20 AM UTC-4, Sean Corfield wrote: > > > But does that mean one can't use functions to build up sequences in a > loop? That seems to limit loops a great deal. > > You just need to ensure you are building the sequences in an eager manner, > rather than a lazy manner. > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > *From: *piast...@gmail.com > *Sent: *Saturday, April 1, 2017 9:56 PM > *To: *Clojure > *Subject: *Re: I can not find any function that might give rise > tothisStackOverflow error > > > > > > Because when you recur in your loop, you’re passing in lazy sequences, > so those > > are essentially building up a giant stack of delayed evaluations – and > when you hit bottom > > and try to realize those, that’s when your stack overflow hits you. > > I was thinking the answer had something to do with the lazyness, but I > wasn't sure because the app seemed to die before the loop finished -- which > I assume is before the functions were realized. But it is possible the > logging functions were slow and didn't show the whole truth. I am grateful > to have someone with your experience clarify this. > > But does that mean one can't use functions to build up sequences in a > loop? That seems to limit loops a great deal. > > > > On Saturday, April 1, 2017 at 10:22:04 PM UTC-4, Sean Corfield wrote: > > Because when you recur in your loop, you’re passing in lazy sequences, so > those are essentially building up a giant stack of delayed evaluations – > and when you hit bottom and try to realize those, that’s when your stack > overflow hits you. > > > > By contrast, your reduce code is eager so the work is done as you work > through the sequence, instead of “stacked up” lazily, to be done later. > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > *From: *piast...@gmail.com > *Sent: *Saturday, April 1, 2017 6:52 PM > *To: *Clojure > *Subject: *Re: I can not find any function that might give rise to > thisStackOverflow error > > > > > Crazy! I re-wrote the (loop) to use (reduce) instead and now everything > works: > > > (defn loop-over-scores > [set-of-scores] > "2017-03-08 -- called from start.clj" > (reduce >;; 2017-04-01 -- we assume vector-with-path-score looks like this: >;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] >;; so we do a minor bit of destructuring >(fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] > (conj vector-of-maps-of-vector-key-and-score >(dire/supervise #'map-of-vector-path-and-true-false-scores > vector-with-path))) >[] >set-of-scores)) > > > The StackOverflow error is gone. > > Sad to say, I'm left with a feeling as if I know nothing about Clojure. I > don't know why (loop) gave me a StackOverflow error whereas (reduce) works > just fine. This is black magic to me, which, sad to say, is not a > comfortable feeling. > > > > > > > On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: > > Well, I am out of ideas. Let's assume I'll re-write this some other way. > What would be better than using (loop)? What would be less likely to cause > StackOverflow, or at least reveal why I'm seeing it. > > > On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: > > > I have a function that will run repeatedly, so I use the at-at library to > call it: > > https://github.com/overtone/at-at > > I don't think this is the problem. > > Sad to say, the Error is catching a StackOverflow, which I'm having > trouble finding. I don't see a place where I call a function recursively, > so I don't see where any of this becomes stackoverflow. > > I'm using Dire to catch errors, but for now I'm just logging them. I don't > see anything fancy or clever that would give me a stackoverflow, and yet > this anonymous function called by at-at is definitely giving rise to > StackOverflow. > > (defn- calculat
RE: I can not find any function that might give rise tothisStackOverflow error
> But does that mean one can't use functions to build up sequences in a loop? > That seems to limit loops a great deal. You just need to ensure you are building the sequences in an eager manner, rather than a lazy manner. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood From: piastkra...@gmail.com Sent: Saturday, April 1, 2017 9:56 PM To: Clojure Subject: Re: I can not find any function that might give rise tothisStackOverflow error > Because when you recur in your loop, you’re passing in lazy sequences, so > those > are essentially building up a giant stack of delayed evaluations – and when > you hit bottom > and try to realize those, that’s when your stack overflow hits you. I was thinking the answer had something to do with the lazyness, but I wasn't sure because the app seemed to die before the loop finished -- which I assume is before the functions were realized. But it is possible the logging functions were slow and didn't show the whole truth. I am grateful to have someone with your experience clarify this. But does that mean one can't use functions to build up sequences in a loop? That seems to limit loops a great deal. On Saturday, April 1, 2017 at 10:22:04 PM UTC-4, Sean Corfield wrote: Because when you recur in your loop, you’re passing in lazy sequences, so those are essentially building up a giant stack of delayed evaluations – and when you hit bottom and try to realize those, that’s when your stack overflow hits you. By contrast, your reduce code is eager so the work is done as you work through the sequence, instead of “stacked up” lazily, to be done later. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood From: piast...@gmail.com Sent: Saturday, April 1, 2017 6:52 PM To: Clojure Subject: Re: I can not find any function that might give rise to thisStackOverflow error Crazy! I re-wrote the (loop) to use (reduce) instead and now everything works: (defn loop-over-scores [set-of-scores] "2017-03-08 -- called from start.clj" (reduce ;; 2017-04-01 -- we assume vector-with-path-score looks like this: ;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] ;; so we do a minor bit of destructuring (fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] (conj vector-of-maps-of-vector-key-and-score (dire/supervise #'map-of-vector-path-and-true-false-scores vector-with-path))) [] set-of-scores)) The StackOverflow error is gone. Sad to say, I'm left with a feeling as if I know nothing about Clojure. I don't know why (loop) gave me a StackOverflow error whereas (reduce) works just fine. This is black magic to me, which, sad to say, is not a comfortable feeling. On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: Well, I am out of ideas. Let's assume I'll re-write this some other way. What would be better than using (loop)? What would be less likely to cause StackOverflow, or at least reveal why I'm seeing it. On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: I have a function that will run repeatedly, so I use the at-at library to call it: https://github.com/overtone/at-at I don't think this is the problem. Sad to say, the Error is catching a StackOverflow, which I'm having trouble finding. I don't see a place where I call a function recursively, so I don't see where any of this becomes stackoverflow. I'm using Dire to catch errors, but for now I'm just logging them. I don't see anything fancy or clever that would give me a stackoverflow, and yet this anonymous function called by at-at is definitely giving rise to StackOverflow. (defn- calculate--scores [] (let [my-pool (at/mk-pool)] (at/every 18 (fn [] (append-to-file "/var/log/example/-scores.log" "Will attempt to write scores") (future (try (let [ map-of-all-sums (api/get-accuracy-and-precision) set-of-all-scores (dire/supervise #'api/path-entries map-of-all-sums) path-and--scores (dire/supervise #'api/loop-over-scores set-of-all-scores) ] (append-to-file "/var/log/example/-scores.log" "\n\n\n\n\n") (append-to-file "/var/log/example/-scores.log" " path-and--scores: ") (append-to-file "/var/log/example/-scores.log" (str "(count set-of-all-scores): " (count set-of-all-scores))) (append-to-file "/var/log/example/-
Re: I can not find any function that might give rise to thisStackOverflow error
> Because when you recur in your loop, you’re passing in lazy sequences, so those > are essentially building up a giant stack of delayed evaluations – and when you hit bottom > and try to realize those, that’s when your stack overflow hits you. I was thinking the answer had something to do with the lazyness, but I wasn't sure because the app seemed to die before the loop finished -- which I assume is before the functions were realized. But it is possible the logging functions were slow and didn't show the whole truth. I am grateful to have someone with your experience clarify this. But does that mean one can't use functions to build up sequences in a loop? That seems to limit loops a great deal. On Saturday, April 1, 2017 at 10:22:04 PM UTC-4, Sean Corfield wrote: > > Because when you recur in your loop, you’re passing in lazy sequences, so > those are essentially building up a giant stack of delayed evaluations – > and when you hit bottom and try to realize those, that’s when your stack > overflow hits you. > > > > By contrast, your reduce code is eager so the work is done as you work > through the sequence, instead of “stacked up” lazily, to be done later. > > > > Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > > *From: *piast...@gmail.com > *Sent: *Saturday, April 1, 2017 6:52 PM > *To: *Clojure > *Subject: *Re: I can not find any function that might give rise to > thisStackOverflow error > > > > > Crazy! I re-wrote the (loop) to use (reduce) instead and now everything > works: > > > (defn loop-over-scores > [set-of-scores] > "2017-03-08 -- called from start.clj" > (reduce >;; 2017-04-01 -- we assume vector-with-path-score looks like this: >;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] >;; so we do a minor bit of destructuring >(fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] > (conj vector-of-maps-of-vector-key-and-score >(dire/supervise #'map-of-vector-path-and-true-false-scores > vector-with-path))) >[] >set-of-scores)) > > > The StackOverflow error is gone. > > Sad to say, I'm left with a feeling as if I know nothing about Clojure. I > don't know why (loop) gave me a StackOverflow error whereas (reduce) works > just fine. This is black magic to me, which, sad to say, is not a > comfortable feeling. > > > > > > > On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: > > Well, I am out of ideas. Let's assume I'll re-write this some other way. > What would be better than using (loop)? What would be less likely to cause > StackOverflow, or at least reveal why I'm seeing it. > > > On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: > > > I have a function that will run repeatedly, so I use the at-at library to > call it: > > https://github.com/overtone/at-at > > I don't think this is the problem. > > Sad to say, the Error is catching a StackOverflow, which I'm having > trouble finding. I don't see a place where I call a function recursively, > so I don't see where any of this becomes stackoverflow. > > I'm using Dire to catch errors, but for now I'm just logging them. I don't > see anything fancy or clever that would give me a stackoverflow, and yet > this anonymous function called by at-at is definitely giving rise to > StackOverflow. > > (defn- calculate--scores [] > (let [my-pool (at/mk-pool)] > (at/every 18 > (fn [] > (append-to-file "/var/log/example/-scores.log" "Will > attempt to write scores") > (future > (try > (let [ > map-of-all-sums > (api/get-accuracy-and-precision) > set-of-all-scores (dire/supervise > #'api/path-entries map-of-all-sums) > path-and--scores (dire/supervise > #'api/loop-over-scores set-of-all-scores) > ] > (append-to-file "/var/log/example/-scores.log" > "\n\n\n\n\n") > (append-to-file "/var/log/example/-scores.log" " > path-and--scores: ") > (append-to-file "/var/log/example/-scores.log" (str > "(count set-of-all-scores): " (count set-of-all-scores))) > (append-to-file "/var/log/example/-scores.log" > path-and--scores)) >
RE: I can not find any function that might give rise to thisStackOverflow error
Because when you recur in your loop, you’re passing in lazy sequences, so those are essentially building up a giant stack of delayed evaluations – and when you hit bottom and try to realize those, that’s when your stack overflow hits you. By contrast, your reduce code is eager so the work is done as you work through the sequence, instead of “stacked up” lazily, to be done later. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood From: piastkra...@gmail.com Sent: Saturday, April 1, 2017 6:52 PM To: Clojure Subject: Re: I can not find any function that might give rise to thisStackOverflow error Crazy! I re-wrote the (loop) to use (reduce) instead and now everything works: (defn loop-over-scores [set-of-scores] "2017-03-08 -- called from start.clj" (reduce ;; 2017-04-01 -- we assume vector-with-path-score looks like this: ;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] ;; so we do a minor bit of destructuring (fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] (conj vector-of-maps-of-vector-key-and-score (dire/supervise #'map-of-vector-path-and-true-false-scores vector-with-path))) [] set-of-scores)) The StackOverflow error is gone. Sad to say, I'm left with a feeling as if I know nothing about Clojure. I don't know why (loop) gave me a StackOverflow error whereas (reduce) works just fine. This is black magic to me, which, sad to say, is not a comfortable feeling. On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: Well, I am out of ideas. Let's assume I'll re-write this some other way. What would be better than using (loop)? What would be less likely to cause StackOverflow, or at least reveal why I'm seeing it. On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: I have a function that will run repeatedly, so I use the at-at library to call it: https://github.com/overtone/at-at I don't think this is the problem. Sad to say, the Error is catching a StackOverflow, which I'm having trouble finding. I don't see a place where I call a function recursively, so I don't see where any of this becomes stackoverflow. I'm using Dire to catch errors, but for now I'm just logging them. I don't see anything fancy or clever that would give me a stackoverflow, and yet this anonymous function called by at-at is definitely giving rise to StackOverflow. (defn- calculate--scores [] (let [my-pool (at/mk-pool)] (at/every 18 (fn [] (append-to-file "/var/log/example/-scores.log" "Will attempt to write scores") (future (try (let [ map-of-all-sums (api/get-accuracy-and-precision) set-of-all-scores (dire/supervise #'api/path-entries map-of-all-sums) path-and--scores (dire/supervise #'api/loop-over-scores set-of-all-scores) ] (append-to-file "/var/log/example/-scores.log" "\n\n\n\n\n") (append-to-file "/var/log/example/-scores.log" " path-and--scores: ") (append-to-file "/var/log/example/-scores.log" (str "(count set-of-all-scores): " (count set-of-all-scores))) (append-to-file "/var/log/example/-scores.log" path-and--scores)) (catch Exception e (do (append-to-file "/var/log/example/-scores.log" (str " EXCEPTION:: " e)) (append-to-file "/var/log/example/-scores.log" (stack/parse-exception e)) (errors/error e))) (catch Error o (println (str " a problem in the anonymous function in calculate--scores: " o))) ))) my-pool))) The problem appears to be here, which will loop several thousand times and then die. But I don't see why. (This function used to just be a loop, and I added the (let) so I could see if I could read the end -- but I could not reach the end). (defn loop-over-scores [set-of-scores] "2017-03-08 -- called from start.clj" (try (let [return-value (loop [ how-many-loops 0 scores set-of-scores vector-of-maps-of-vector-key-and-score [] ] (println (str " in loop-over-scores again " how-many-loops)) (if (next scores) (recur (inc how-many-loops)
Re: I can not find any function that might give rise to this StackOverflow error
I'm away from a Clojure REPL to poke at this but I think trapping this in a debugger would trivially reveal the source of recursion. Set a breakpoint at the start of the loop and step through. If using Cursive / IntelliJ set a breakpoint to detect StackOverflow and inspect the call stack. > On Apr 1, 2017, at 6:52 PM, piastkra...@gmail.com wrote: > > > Crazy! I re-wrote the (loop) to use (reduce) instead and now everything > works: > > > (defn loop-over-scores > [set-of-scores] > "2017-03-08 -- called from start.clj" > (reduce >;; 2017-04-01 -- we assume vector-with-path-score looks like this: >;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] >;; so we do a minor bit of destructuring >(fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] > (conj vector-of-maps-of-vector-key-and-score >(dire/supervise #'map-of-vector-path-and-true-false-scores > vector-with-path))) >[] >set-of-scores)) > > > The StackOverflow error is gone. > > Sad to say, I'm left with a feeling as if I know nothing about Clojure. I > don't know why (loop) gave me a StackOverflow error whereas (reduce) works > just fine. This is black magic to me, which, sad to say, is not a comfortable > feeling. > > > > > > >> On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: >> Well, I am out of ideas. Let's assume I'll re-write this some other way. >> What would be better than using (loop)? What would be less likely to cause >> StackOverflow, or at least reveal why I'm seeing it. >> >> >>> On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: >>> >>> I have a function that will run repeatedly, so I use the at-at library to >>> call it: >>> >>> https://github.com/overtone/at-at >>> >>> I don't think this is the problem. >>> >>> Sad to say, the Error is catching a StackOverflow, which I'm having trouble >>> finding. I don't see a place where I call a function recursively, so I >>> don't see where any of this becomes stackoverflow. >>> >>> I'm using Dire to catch errors, but for now I'm just logging them. I don't >>> see anything fancy or clever that would give me a stackoverflow, and yet >>> this anonymous function called by at-at is definitely giving rise to >>> StackOverflow. >>> >>> (defn- calculate--scores [] >>> (let [my-pool (at/mk-pool)] >>> (at/every 18 >>> (fn [] >>> (append-to-file "/var/log/example/-scores.log" "Will >>> attempt to write scores") >>> (future >>> (try >>> (let [ >>> map-of-all-sums (api/get-accuracy-and-precision) >>> set-of-all-scores (dire/supervise >>> #'api/path-entries map-of-all-sums) >>> path-and--scores (dire/supervise >>> #'api/loop-over-scores set-of-all-scores) >>> ] >>> (append-to-file "/var/log/example/-scores.log" >>> "\n\n\n\n\n") >>> (append-to-file "/var/log/example/-scores.log" " >>> path-and--scores: ") >>> (append-to-file "/var/log/example/-scores.log" (str >>> "(count set-of-all-scores): " (count set-of-all-scores))) >>> (append-to-file "/var/log/example/-scores.log" >>> path-and--scores)) >>> (catch Exception e >>> (do >>> (append-to-file "/var/log/example/-scores.log" (str >>> " EXCEPTION:: " e)) >>> (append-to-file "/var/log/example/-scores.log" >>> (stack/parse-exception e)) >>> (errors/error e))) >>> (catch Error o >>> (println (str " a problem in the anonymous function >>> in calculate--scores: " o))) >>> ))) >>> my-pool))) >>> >>> >>> The problem appears to be here, which will loop several thousand times and >>> then die. But I don't see why. (This function used to just be a loop, and I >>> added the (let) so I could see if I could read the end -- but I could not >>> reach the end). >>> >>> >>> >>> (defn loop-over-scores >>> [set-of-scores] >>> "2017-03-08 -- called from start.clj" >>> (try >>> (let [return-value (loop [ >>>how-many-loops 0 >>>scores set-of-scores >>>vector-of-maps-of-vector-key-and-score [] >>>] >>> >>> (println (str " in loop-over-scores again " >>> how-many-loops)) >>> (if (next scores) >>> (recur >>> (inc how-many-loops) >>> (remove #{(first scores)} scores) >>> (conj vector-of-maps-of-vector-key-and-score >>>
Re: I can not find any function that might give rise to this StackOverflow error
Crazy! I re-wrote the (loop) to use (reduce) instead and now everything works: (defn loop-over-scores [set-of-scores] "2017-03-08 -- called from start.clj" (reduce ;; 2017-04-01 -- we assume vector-with-path-score looks like this: ;; [[:positive :true 0.88 19 60 10 12 3 1 3 1 2 1] 1] ;; so we do a minor bit of destructuring (fn [vector-of-maps-of-vector-key-and-score [vector-with-path score]] (conj vector-of-maps-of-vector-key-and-score (dire/supervise #'map-of-vector-path-and-true-false-scores vector-with-path))) [] set-of-scores)) The StackOverflow error is gone. Sad to say, I'm left with a feeling as if I know nothing about Clojure. I don't know why (loop) gave me a StackOverflow error whereas (reduce) works just fine. This is black magic to me, which, sad to say, is not a comfortable feeling. On Saturday, April 1, 2017 at 7:51:08 PM UTC-4, piast...@gmail.com wrote: > > Well, I am out of ideas. Let's assume I'll re-write this some other way. > What would be better than using (loop)? What would be less likely to cause > StackOverflow, or at least reveal why I'm seeing it. > > > On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: >> >> >> I have a function that will run repeatedly, so I use the at-at library to >> call it: >> >> https://github.com/overtone/at-at >> >> I don't think this is the problem. >> >> Sad to say, the Error is catching a StackOverflow, which I'm having >> trouble finding. I don't see a place where I call a function recursively, >> so I don't see where any of this becomes stackoverflow. >> >> I'm using Dire to catch errors, but for now I'm just logging them. I >> don't see anything fancy or clever that would give me a stackoverflow, and >> yet this anonymous function called by at-at is definitely giving rise to >> StackOverflow. >> >> (defn- calculate--scores [] >> (let [my-pool (at/mk-pool)] >> (at/every 18 >> (fn [] >> (append-to-file "/var/log/example/-scores.log" "Will >> attempt to write scores") >> (future >> (try >> (let [ >> map-of-all-sums >> (api/get-accuracy-and-precision) >> set-of-all-scores (dire/supervise >> #'api/path-entries map-of-all-sums) >> path-and--scores (dire/supervise >> #'api/loop-over-scores set-of-all-scores) >> ] >> (append-to-file "/var/log/example/-scores.log" >> "\n\n\n\n\n") >> (append-to-file "/var/log/example/-scores.log" " >> path-and--scores: ") >> (append-to-file "/var/log/example/-scores.log" >> (str "(count set-of-all-scores): " (count set-of-all-scores))) >> (append-to-file "/var/log/example/-scores.log" >> path-and--scores)) >> (catch Exception e >> (do >> (append-to-file "/var/log/example/-scores.log" >> (str " EXCEPTION:: " e)) >> (append-to-file "/var/log/example/-scores.log" >> (stack/parse-exception e)) >> (errors/error e))) >> (catch Error o >> (println (str " a problem in the anonymous function >> in calculate--scores: " o))) >> ))) >> my-pool))) >> >> >> The problem appears to be here, which will loop several thousand times >> and then die. But I don't see why. (This function used to just be a loop, >> and I added the (let) so I could see if I could read the end -- but I could >> not reach the end). >> >> >> >> (defn loop-over-scores >> [set-of-scores] >> "2017-03-08 -- called from start.clj" >> (try >> (let [return-value (loop [ >>how-many-loops 0 >>scores set-of-scores >>vector-of-maps-of-vector-key-and-score [] >>] >> >> (println (str " in loop-over-scores again " >> how-many-loops)) >> (if (next scores) >> (recur >> (inc how-many-loops) >> (remove #{(first scores)} scores) >> (conj vector-of-maps-of-vector-key-and-score >> (find-related-positive-negative-true-false-records scores (first scores >> vector-of-maps-of-vector-key-and-score)) >> ] >> >> (println " return-value in loop-over-scores " return-value " in >> loop-over-scores") >> return-value) >> (catch Exception e (println " exception in loop-over-scores: " e >> >> >> So this line prints out a result several thousand times: >> >> (println " return-value in loop-over-scores " return-value " in >> loop-over-scores") >> >> >>
Re: I can not find any function that might give rise to this StackOverflow error
Well, I am out of ideas. Let's assume I'll re-write this some other way. What would be better than using (loop)? What would be less likely to cause StackOverflow, or at least reveal why I'm seeing it. On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: > > > I have a function that will run repeatedly, so I use the at-at library to > call it: > > https://github.com/overtone/at-at > > I don't think this is the problem. > > Sad to say, the Error is catching a StackOverflow, which I'm having > trouble finding. I don't see a place where I call a function recursively, > so I don't see where any of this becomes stackoverflow. > > I'm using Dire to catch errors, but for now I'm just logging them. I don't > see anything fancy or clever that would give me a stackoverflow, and yet > this anonymous function called by at-at is definitely giving rise to > StackOverflow. > > (defn- calculate--scores [] > (let [my-pool (at/mk-pool)] > (at/every 18 > (fn [] > (append-to-file "/var/log/example/-scores.log" "Will > attempt to write scores") > (future > (try > (let [ > map-of-all-sums > (api/get-accuracy-and-precision) > set-of-all-scores (dire/supervise > #'api/path-entries map-of-all-sums) > path-and--scores (dire/supervise > #'api/loop-over-scores set-of-all-scores) > ] > (append-to-file "/var/log/example/-scores.log" > "\n\n\n\n\n") > (append-to-file "/var/log/example/-scores.log" " > path-and--scores: ") > (append-to-file "/var/log/example/-scores.log" (str > "(count set-of-all-scores): " (count set-of-all-scores))) > (append-to-file "/var/log/example/-scores.log" > path-and--scores)) > (catch Exception e > (do > (append-to-file "/var/log/example/-scores.log" > (str " EXCEPTION:: " e)) > (append-to-file "/var/log/example/-scores.log" > (stack/parse-exception e)) > (errors/error e))) > (catch Error o > (println (str " a problem in the anonymous function > in calculate--scores: " o))) > ))) > my-pool))) > > > The problem appears to be here, which will loop several thousand times and > then die. But I don't see why. (This function used to just be a loop, and I > added the (let) so I could see if I could read the end -- but I could not > reach the end). > > > > (defn loop-over-scores > [set-of-scores] > "2017-03-08 -- called from start.clj" > (try > (let [return-value (loop [ >how-many-loops 0 >scores set-of-scores >vector-of-maps-of-vector-key-and-score [] >] > > (println (str " in loop-over-scores again " > how-many-loops)) > (if (next scores) > (recur > (inc how-many-loops) > (remove #{(first scores)} scores) > (conj vector-of-maps-of-vector-key-and-score > (find-related-positive-negative-true-false-records scores (first scores > vector-of-maps-of-vector-key-and-score)) > ] > > (println " return-value in loop-over-scores " return-value " in > loop-over-scores") > return-value) > (catch Exception e (println " exception in loop-over-scores: " e > > > So this line prints out a result several thousand times: > > (println " return-value in loop-over-scores " return-value " in > loop-over-scores") > > > And then I get stackoverflow. > > But nothing seems suspicious here: > > > (defn find-related-positive-negative-true-false-records [set-of-scores > vector-with-path-score] > (println " in find-related-positive-negative-true-false-records the > vector-with-path-score " vector-with-path-score) > > (let [ > [vector-with-path score] vector-with-path-score > ;; 2017-03-08 -- seq-as-path should be something like [30 8 34 > 20.94 2] > seq-as-path (rest (rest vector-with-path)) > > ;;_ (append-to-file "/var/log/example/-scores.log" "seq-as-path") > ;; _ (append-to-file "/var/log/example/-scores.log" > seq-as-path) > > vector-as-path (apply conj [] seq-as-path) > > _ (append-to-file "/var/log/example/-scores.log" "vector-as-path") > _ (append-to-file "/var/log/example/-scores.log" vector-as-path) > ] > (dire/supervise #'map-of-vector-path-and-true-false-scores > vector-as-path))) > > > Nor here: > > > (defn
Re: I can not find any function that might give rise to this StackOverflow error
So for instances, starting with an object that has about 32,000 lines that need to be looped over, the code gets this far: in loop-over-scores again 2375 It prints that out and then throws StackOverflow error. But I don't see anything in there that would exhaust the stack. These functions run, return a value, and are done. On Saturday, April 1, 2017 at 6:23:29 PM UTC-4, piast...@gmail.com wrote: > > > I have a function that will run repeatedly, so I use the at-at library to > call it: > > https://github.com/overtone/at-at > > I don't think this is the problem. > > Sad to say, the Error is catching a StackOverflow, which I'm having > trouble finding. I don't see a place where I call a function recursively, > so I don't see where any of this becomes stackoverflow. > > I'm using Dire to catch errors, but for now I'm just logging them. I don't > see anything fancy or clever that would give me a stackoverflow, and yet > this anonymous function called by at-at is definitely giving rise to > StackOverflow. > > (defn- calculate--scores [] > (let [my-pool (at/mk-pool)] > (at/every 18 > (fn [] > (append-to-file "/var/log/example/-scores.log" "Will > attempt to write scores") > (future > (try > (let [ > map-of-all-sums > (api/get-accuracy-and-precision) > set-of-all-scores (dire/supervise > #'api/path-entries map-of-all-sums) > path-and--scores (dire/supervise > #'api/loop-over-scores set-of-all-scores) > ] > (append-to-file "/var/log/example/-scores.log" > "\n\n\n\n\n") > (append-to-file "/var/log/example/-scores.log" " > path-and--scores: ") > (append-to-file "/var/log/example/-scores.log" (str > "(count set-of-all-scores): " (count set-of-all-scores))) > (append-to-file "/var/log/example/-scores.log" > path-and--scores)) > (catch Exception e > (do > (append-to-file "/var/log/example/-scores.log" > (str " EXCEPTION:: " e)) > (append-to-file "/var/log/example/-scores.log" > (stack/parse-exception e)) > (errors/error e))) > (catch Error o > (println (str " a problem in the anonymous function > in calculate--scores: " o))) > ))) > my-pool))) > > > The problem appears to be here, which will loop several thousand times and > then die. But I don't see why. (This function used to just be a loop, and I > added the (let) so I could see if I could read the end -- but I could not > reach the end). > > > > (defn loop-over-scores > [set-of-scores] > "2017-03-08 -- called from start.clj" > (try > (let [return-value (loop [ >how-many-loops 0 >scores set-of-scores >vector-of-maps-of-vector-key-and-score [] >] > > (println (str " in loop-over-scores again " > how-many-loops)) > (if (next scores) > (recur > (inc how-many-loops) > (remove #{(first scores)} scores) > (conj vector-of-maps-of-vector-key-and-score > (find-related-positive-negative-true-false-records scores (first scores > vector-of-maps-of-vector-key-and-score)) > ] > > (println " return-value in loop-over-scores " return-value " in > loop-over-scores") > return-value) > (catch Exception e (println " exception in loop-over-scores: " e > > > So this line prints out a result several thousand times: > > (println " return-value in loop-over-scores " return-value " in > loop-over-scores") > > > And then I get stackoverflow. > > But nothing seems suspicious here: > > > (defn find-related-positive-negative-true-false-records [set-of-scores > vector-with-path-score] > (println " in find-related-positive-negative-true-false-records the > vector-with-path-score " vector-with-path-score) > > (let [ > [vector-with-path score] vector-with-path-score > ;; 2017-03-08 -- seq-as-path should be something like [30 8 34 > 20.94 2] > seq-as-path (rest (rest vector-with-path)) > > ;;_ (append-to-file "/var/log/example/-scores.log" "seq-as-path") > ;; _ (append-to-file "/var/log/example/-scores.log" > seq-as-path) > > vector-as-path (apply conj [] seq-as-path) > > _ (append-to-file "/var/log/example/-scores.log" "vector-as-path") > _ (append-to-file "/var/log/example/-scores.log" vector-as-path) > ] >
I can not find any function that might give rise to this StackOverflow error
I have a function that will run repeatedly, so I use the at-at library to call it: https://github.com/overtone/at-at I don't think this is the problem. Sad to say, the Error is catching a StackOverflow, which I'm having trouble finding. I don't see a place where I call a function recursively, so I don't see where any of this becomes stackoverflow. I'm using Dire to catch errors, but for now I'm just logging them. I don't see anything fancy or clever that would give me a stackoverflow, and yet this anonymous function called by at-at is definitely giving rise to StackOverflow. (defn- calculate--scores [] (let [my-pool (at/mk-pool)] (at/every 18 (fn [] (append-to-file "/var/log/example/-scores.log" "Will attempt to write scores") (future (try (let [ map-of-all-sums (api/get-accuracy-and-precision) set-of-all-scores (dire/supervise #'api/path-entries map-of-all-sums) path-and--scores (dire/supervise #'api/loop-over-scores set-of-all-scores) ] (append-to-file "/var/log/example/-scores.log" "\n\n\n\n\n") (append-to-file "/var/log/example/-scores.log" " path-and--scores: ") (append-to-file "/var/log/example/-scores.log" (str "(count set-of-all-scores): " (count set-of-all-scores))) (append-to-file "/var/log/example/-scores.log" path-and--scores)) (catch Exception e (do (append-to-file "/var/log/example/-scores.log" (str " EXCEPTION:: " e)) (append-to-file "/var/log/example/-scores.log" (stack/parse-exception e)) (errors/error e))) (catch Error o (println (str " a problem in the anonymous function in calculate--scores: " o))) ))) my-pool))) The problem appears to be here, which will loop several thousand times and then die. But I don't see why. (This function used to just be a loop, and I added the (let) so I could see if I could read the end -- but I could not reach the end). (defn loop-over-scores [set-of-scores] "2017-03-08 -- called from start.clj" (try (let [return-value (loop [ how-many-loops 0 scores set-of-scores vector-of-maps-of-vector-key-and-score [] ] (println (str " in loop-over-scores again " how-many-loops)) (if (next scores) (recur (inc how-many-loops) (remove #{(first scores)} scores) (conj vector-of-maps-of-vector-key-and-score (find-related-positive-negative-true-false-records scores (first scores vector-of-maps-of-vector-key-and-score)) ] (println " return-value in loop-over-scores " return-value " in loop-over-scores") return-value) (catch Exception e (println " exception in loop-over-scores: " e So this line prints out a result several thousand times: (println " return-value in loop-over-scores " return-value " in loop-over-scores") And then I get stackoverflow. But nothing seems suspicious here: (defn find-related-positive-negative-true-false-records [set-of-scores vector-with-path-score] (println " in find-related-positive-negative-true-false-records the vector-with-path-score " vector-with-path-score) (let [ [vector-with-path score] vector-with-path-score ;; 2017-03-08 -- seq-as-path should be something like [30 8 34 20.94 2] seq-as-path (rest (rest vector-with-path)) ;;_ (append-to-file "/var/log/example/-scores.log" "seq-as-path") ;; _ (append-to-file "/var/log/example/-scores.log" seq-as-path) vector-as-path (apply conj [] seq-as-path) _ (append-to-file "/var/log/example/-scores.log" "vector-as-path") _ (append-to-file "/var/log/example/-scores.log" vector-as-path) ] (dire/supervise #'map-of-vector-path-and-true-false-scores vector-as-path))) Nor here: (defn map-of-vector-path-and-true-false-scores [vector-as-path] (println " at the start of map-of-vector-path-and-true-false-scores") (try (if-not (empty? vector-as-path) (let [ ;; 2017-03-30 -- this fails: ;; user> (apply conj [:positive :false] (30 6 40)) ;; ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/eval1719 (NO_SOURCE_FILE:1) ;; ;; but this works: ;; user> (apply conj [:positive :false] '(30 6 40)) ;;[:positive
Re: No any? function
Thanks for the responses. I agree that some takes care of things quite nicely. The asymmetrical naming convention in this case was what caught my eye. Just wanted to make sure if it was a deliberate design decision or an oversight. Sounds like it was done by design. On Jun 14, 9:29 am, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Hi David, any? would be redundant and less general than some, if I am not mistaken. Compare the docstrings for the hypothetical any?. (some p coll) Returns the *first logical true value* of (pred x) for any x in coll, else *nil*. (any? p coll) Returns *true* if (pred x) is logical true for any x in coll, else *false*. Since *nil* and *false* are both falsy, some can be used as a predicate that is truthy when it finds truthy result, otherwise falsy. This is exactly the behavior expected from an any? function. some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Perhaps a pointer to some should be added in the docstring of not-any?. Although a quick look at the source makes it crystal clear. I wasn't aware of not-any?s existence, maybe noting it in somes docstring could be beneficial also. Thanks, Ambrose On Tue, Jun 14, 2011 at 3:08 PM, de1976 davidescobar1...@gmail.com wrote: Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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
No any? function
Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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: No any? function
Hi David, any? would be redundant and less general than some, if I am not mistaken. Compare the docstrings for the hypothetical any?. (some p coll) Returns the *first logical true value* of (pred x) for any x in coll, else *nil*. (any? p coll) Returns *true* if (pred x) is logical true for any x in coll, else *false*. Since *nil* and *false* are both falsy, some can be used as a predicate that is truthy when it finds truthy result, otherwise falsy. This is exactly the behavior expected from an any? function. some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Perhaps a pointer to some should be added in the docstring of not-any?. Although a quick look at the source makes it crystal clear. I wasn't aware of not-any?s existence, maybe noting it in somes docstring could be beneficial also. Thanks, Ambrose On Tue, Jun 14, 2011 at 3:08 PM, de1976 davidescobar1...@gmail.com wrote: Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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: No any? function
I actually had the same thought as the OP when reading through docs not too long ago. +1 for adding a pointer to some in the docstring of not-any? -kb On Tue, Jun 14, 2011 at 11:29 AM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Hi David, any? would be redundant and less general than some, if I am not mistaken. Compare the docstrings for the hypothetical any?. (some p coll) Returns the *first logical true value* of (pred x) for any x in coll, else *nil*. (any? p coll) Returns *true* if (pred x) is logical true for any x in coll, else *false*. Since *nil* and *false* are both falsy, some can be used as a predicate that is truthy when it finds truthy result, otherwise falsy. This is exactly the behavior expected from an any? function. some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Perhaps a pointer to some should be added in the docstring of not-any?. Although a quick look at the source makes it crystal clear. I wasn't aware of not-any?s existence, maybe noting it in somes docstring could be beneficial also. Thanks, Ambrose On Tue, Jun 14, 2011 at 3:08 PM, de1976 davidescobar1...@gmail.comwrote: Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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: No any? function
Inspired by seq/empty? docstrings. not-any? Returns false if (pred x) is logical true for any x in coll, else true - same as (not (some pred coll)). some Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll) Please use the idiom (not-any? pred coll) rather than (not (some pred coll)) Thoughts? Ambrose On Wed, Jun 15, 2011 at 2:31 AM, Kevin Baribeau kevin.barib...@gmail.comwrote: I actually had the same thought as the OP when reading through docs not too long ago. +1 for adding a pointer to some in the docstring of not-any? -kb On Tue, Jun 14, 2011 at 11:29 AM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Hi David, any? would be redundant and less general than some, if I am not mistaken. Compare the docstrings for the hypothetical any?. (some p coll) Returns the *first logical true value* of (pred x) for any x in coll, else *nil*. (any? p coll) Returns *true* if (pred x) is logical true for any x in coll, else *false*. Since *nil* and *false* are both falsy, some can be used as a predicate that is truthy when it finds truthy result, otherwise falsy. This is exactly the behavior expected from an any? function. some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Perhaps a pointer to some should be added in the docstring of not-any?. Although a quick look at the source makes it crystal clear. I wasn't aware of not-any?s existence, maybe noting it in somes docstring could be beneficial also. Thanks, Ambrose On Tue, Jun 14, 2011 at 3:08 PM, de1976 davidescobar1...@gmail.comwrote: Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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 -- 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: No any? function
Looks good to me. I wasn't familiar with the docs around (seq x) vs (not (empty? x)). That seems like a good place to draw the language from. -kb On Tue, Jun 14, 2011 at 1:43 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Inspired by seq/empty? docstrings. not-any? Returns false if (pred x) is logical true for any x in coll, else true - same as (not (some pred coll)). some Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll) Please use the idiom (not-any? pred coll) rather than (not (some pred coll)) Thoughts? Ambrose On Wed, Jun 15, 2011 at 2:31 AM, Kevin Baribeau kevin.barib...@gmail.comwrote: I actually had the same thought as the OP when reading through docs not too long ago. +1 for adding a pointer to some in the docstring of not-any? -kb On Tue, Jun 14, 2011 at 11:29 AM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Hi David, any? would be redundant and less general than some, if I am not mistaken. Compare the docstrings for the hypothetical any?. (some p coll) Returns the *first logical true value* of (pred x) for any x in coll, else *nil*. (any? p coll) Returns *true* if (pred x) is logical true for any x in coll, else *false*. Since *nil* and *false* are both falsy, some can be used as a predicate that is truthy when it finds truthy result, otherwise falsy. This is exactly the behavior expected from an any? function. some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Perhaps a pointer to some should be added in the docstring of not-any?. Although a quick look at the source makes it crystal clear. I wasn't aware of not-any?s existence, maybe noting it in somes docstring could be beneficial also. Thanks, Ambrose On Tue, Jun 14, 2011 at 3:08 PM, de1976 davidescobar1...@gmail.comwrote: Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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 -- 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: No any? function
On Tue, Jun 14, 2011 at 12:29 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Notably, with a map as first argument it returns the first (truthy) mapped value for any of the keys in a coll: (if-let [f (some fn-map [:super-override :override :normal])] (f args)) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: No any? function
There is one use of any? over some which hasn't been mentioned: checking whether a list contains a nil. ie. (when (any? nil? xs) (do stuff)) vs. (when (some nil? xs) (do stuff)) -Patrick On Jun 14, 9:00 pm, Ken Wesson kwess...@gmail.com wrote: On Tue, Jun 14, 2011 at 12:29 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Notably, with a map as first argument it returns the first (truthy) mapped value for any of the keys in a coll: (if-let [f (some fn-map [:super-override :override :normal])] (f args)) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: No any? function
On Wed, Jun 15, 2011 at 9:14 AM, CuppoJava patrickli_2...@hotmail.comwrote: There is one use of any? over some which hasn't been mentioned: checking whether a list contains a nil. ie. (when (any? nil? xs) (do stuff)) vs. (when (some nil? xs) (do stuff)) Actually, this case works with `some`. user= (def any? (comp not not some)) #'user/any? user= (any? nil? [1 nil 2]) true user= (any? nil? [1 2]) false user= (some nil? [1 nil 2]) true user= (some nil? [1 2]) nil Comparing the general semantics, I can see no (useful) distinction between the two in `any?`s favor. `some` returns nil (falsy) on failure else truthy `any?` returns false (falsy) on failure else true (truthy) .. defining failure as all (pred x) in coll being falsy. Thanks, Ambrose -Patrick On Jun 14, 9:00 pm, Ken Wesson kwess...@gmail.com wrote: On Tue, Jun 14, 2011 at 12:29 PM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Notably, with a map as first argument it returns the first (truthy) mapped value for any of the keys in a coll: (if-let [f (some fn-map [:super-override :override :normal])] (f args)) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: No any? function
Could someone add this as a Jira ticket or similar to be reviewed? Ambrose On Wed, Jun 15, 2011 at 2:43 AM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Inspired by seq/empty? docstrings. not-any? Returns false if (pred x) is logical true for any x in coll, else true - same as (not (some pred coll)). some Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll) Please use the idiom (not-any? pred coll) rather than (not (some pred coll)) Thoughts? Ambrose On Wed, Jun 15, 2011 at 2:31 AM, Kevin Baribeau kevin.barib...@gmail.comwrote: I actually had the same thought as the OP when reading through docs not too long ago. +1 for adding a pointer to some in the docstring of not-any? -kb On Tue, Jun 14, 2011 at 11:29 AM, Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com wrote: Hi David, any? would be redundant and less general than some, if I am not mistaken. Compare the docstrings for the hypothetical any?. (some p coll) Returns the *first logical true value* of (pred x) for any x in coll, else *nil*. (any? p coll) Returns *true* if (pred x) is logical true for any x in coll, else *false*. Since *nil* and *false* are both falsy, some can be used as a predicate that is truthy when it finds truthy result, otherwise falsy. This is exactly the behavior expected from an any? function. some is a poster boy for Clojure's well thought out truthyness system, this is a great example of the types of general functions it allows. Perhaps a pointer to some should be added in the docstring of not-any?. Although a quick look at the source makes it crystal clear. I wasn't aware of not-any?s existence, maybe noting it in somes docstring could be beneficial also. Thanks, Ambrose On Tue, Jun 14, 2011 at 3:08 PM, de1976 davidescobar1...@gmail.comwrote: Hello everyone. In looking through the API documentation, I've noticed that there is a not-any? function available, but there is no corresponding inverse any? function that I can find. There are, however, every? and not-every? functions available. The closest I could find was some, but wouldn't it make sense to have an any? function for more obvious consistency? Thanks. -- 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 -- 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: any? function
On Sun, Oct 5, 2008 at 2:55 PM, Vincent Foley [EMAIL PROTECTED] wrote: I was surprised to see that Clojure doesn't have an any? function. I saw every?, not-every? and not-any? but no any?. Is there a reason for this? user= (doc some) - clojure/some ([pred coll]) Returns the first logical true value of (pred x) for any x in coll, else nil. It's not identical to yours, as it returns whatever pred returned, instead of always returning true. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---