Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-27 Thread Brian Marick
On May 27, 2013, at 1:38 PM, Armando Blancas wrote: >> It's fun to make use of esoterica like `seq`'s behavior with an empty list. >> Back in the early days, it was necessary. [2 examples] >> >> But, for the rest of us, the necessity has drained out of that kind of >> esoterica. > > I don't

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-27 Thread Armando Blancas
> > There is no one who understands `(if (seq thing)` who wouldn't understand > `(if (not (empty? thing))` or, better, `(if (not-empty? thing)`. The > converse is not true. That suggests that the latter should be the idiom No, it doesn't. That simply illustrates that idioms must be learned, as

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-27 Thread Alexander L.
I really liked your take on this *Brian*. You kinda convinced me to use (if (not-empty? foo)) from now on :) Alexander On Monday, May 27, 2013 2:58:38 AM UTC+3, Brian Marick wrote: > > > On May 26, 2013, at 5:47 AM, "Alex L." > > wrote: > > First, the use of seq as a > > terminating condition

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-27 Thread Brian Marick
On May 26, 2013, at 5:47 AM, "Alex L." wrote: > First, the use of seq as a > terminating condition is the idiomatic way to test whether a sequence is > empty. In natural languages, idioms change. Sometimes it's to the despair of purists: for example, I've had to accept that "hopefully" at the

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-26 Thread Cedric Greevey
To that excellent analysis I would add that, if you're going to iterate through a whole collection, it's much more efficient to call seq on it at the outset, and then use (next s) to progress through the seq; (next s) returns nil when there are no more elements, and is semantically equivalent to (s

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-26 Thread Alex L.
Hello, I just wanted to share the following piece from The Joy of Clojure, *Chapter 3, page 45*, since I found it interesting and it might be valuable to the t

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Mike Thvedt
In regards to the allocation objection--how often are you calling seq millions of times on something that's not already a seq? In re using count instead of seq, a lazy seq's count might be arbitrarily expensive to calculate and might not be able to tell if it's empty without realizing its head.

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Timothy Baldridge
Why shouldn't that be the case? A seq is a collection of data. And it's immutable, why would it bein its own category of collections? Timothy On May 13, 2013 3:45 PM, "Philip Potter" wrote: > On 13 May 2013 17:30, Timothy Baldridge wrote: > >>> In fact, the way that count works on ISeqs is rath

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Philip Potter
On 13 May 2013 17:30, Timothy Baldridge wrote: >>> In fact, the way that count works on ISeqs is rather roundabout -- it > only works because all implementations of ISeq in clojure.jar also > happen to implement java.util.List, so count calls Collection.size(). > In theory, some user-provided ISeq

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Timothy Baldridge
>> In fact, the way that count works on ISeqs is rather roundabout -- it only works because all implementations of ISeq in clojure.jar also happen to implement java.util.List, so count calls Collection.size(). In theory, some user-provided ISeq which didn't implement List would not respond to count

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Philip Potter
In fact, the way that count works on ISeqs is rather roundabout -- it only works because all implementations of ISeq in clojure.jar also happen to implement java.util.List, so count calls Collection.size(). In theory, some user-provided ISeq which didn't implement List would not respond to count.

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Herwig Hochleitner
2013/5/13 Meikel Brandmeyer (kotarak) > > You misunderstood my argument. cycle returns a sequence => use seq. count > is the wrong thing to call here. And calling seq without using its return > value (with a name) is a smell. count should not be called in sequences. > (In fact I believe that coun

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Christophe Grand
I second: using seq to test for emptiness is only one half of the idiom, the second half is to bind and to destructure (usually with if-let) the returned value. Christophe On Sat, May 11, 2013 at 12:08 PM, Chris Ford wrote: > IMHO it's a bit subjective, but empty? is defined as (not (seq coll))

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Gary Trakhman
If there is no one-size fits all solution for your use case, it might become idiomatic to use a protocol or some other polymorphism. One could imagine a version of clojure that has protocols for every core function :). Can you ever have too many cakes to eat them, too? On Monday, May 13, 2013, Me

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 13. Mai 2013 16:56:11 UTC+2 schrieb tbc++: > > Let's not forget that allocations on the JVM are super, super cheap. In > the order of something like 10 cycles. So don't worry so much about > throw-away objects. > > seq involves realization of the first step of the sequence which

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Timothy Baldridge
Let's not forget that allocations on the JVM are super, super cheap. In the order of something like 10 cycles. So don't worry so much about throw-away objects. Timothy On Mon, May 13, 2013 at 8:48 AM, Jim wrote: > So the following is not encouraged because we disregard the result of > calling

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 13. Mai 2013 16:48:13 UTC+2 schrieb Jim foo.bar: > > So the following is not encouraged because we disregard the result of > calling seq? > I would prefer (not-any? empty? ...) with empty? being #(zero? (count %)) if all the values are data structures. If there might be sequence

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Jim
So the following is not encouraged because we disregard the result of calling seq? (def dummy {:a [1 2 3] :b [4 5 6] :c [] }) =>(every? seq (vals dummy)) ;make sure all values are non-empty false Jim On 13/05/13 15:08, Meikel Brandmeyer (kotarak) wrote: Hi, Am Montag, 13. Mai 2013

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 13. Mai 2013 16:16:57 UTC+2 schrieb Sean Corfield: > > > So you think (count (map inc [1 2 3])) should be illegal? > > (I'm just trying to understand your logic here) > > In the hardcore version, yes. In the practical version, probably not. I never had to call count on a seq. (Va

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Mark Tomko
Even so, what do you do when you're using someone else's code as a library? On Mon, May 13, 2013 at 10:42 AM, Meikel Brandmeyer (kotarak) wrote: > Hi, > > Am Montag, 13. Mai 2013 16:16:36 UTC+2 schrieb Mark: >> >> That's a fair point, but do you always know that what you've gotten back >> is a s

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 13. Mai 2013 16:16:36 UTC+2 schrieb Mark: > > That's a fair point, but do you always know that what you've gotten back > is a sequence or a data structure, if you aren't looking directly at the > code that you're calling? > Most of my code are either sequence-y things (mostly tra

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Sean Corfield
On Mon, May 13, 2013 at 7:08 AM, Meikel Brandmeyer (kotarak) wrote: > You misunderstood my argument. cycle returns a sequence => use seq. count is > the wrong thing to call here. And calling seq without using its return value > (with a name) is a smell. count should not be called in sequences. (In

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Mark
That's a fair point, but do you always know that what you've gotten back is a sequence or a data structure, if you aren't looking directly at the code that you're calling? On Monday, May 13, 2013 10:08:00 AM UTC-4, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > Am Montag, 13. Mai 2013 13:57:57

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 13. Mai 2013 13:57:57 UTC+2 schrieb Herwig Hochleitner: > > 2013/5/13 Meikel Brandmeyer (kotarak) > > >> seq belongs to seq-land. empty? belongs to data structure land. It should >> actually be implemented as #(zero? (count %)). But unfortunately it is not. >> > > I'd argue it sho

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Herwig Hochleitner
2013/5/13 Meikel Brandmeyer (kotarak) > seq belongs to seq-land. empty? belongs to data structure land. It should > actually be implemented as #(zero? (count %)). But unfortunately it is not. > I'd argue it shouldn't (empty? (cycle [1 2 3])) => false (zero? (count (cycle [1 2 3]))) ... infinite

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Meikel Brandmeyer
2013/5/13 Mike Thvedt > A good implementation of ISeq won't return a new object, and new > short-lived objects are cheap on the JVM anyway. OTOH count can be slow for > some data structures. if you don't like instantiating lots of new objects > only to throw them away, you're missing out on one o

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Mike Thvedt
A good implementation of ISeq won't return a new object, and new short-lived objects are cheap on the JVM anyway. OTOH count can be slow for some data structures. if you don't like instantiating lots of new objects only to throw them away, you're missing out on one of HotSpot's most significant

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-12 Thread Meikel Brandmeyer (kotarak)
Hi, Am Samstag, 11. Mai 2013 21:25:11 UTC+2 schrieb Alex Baranosky: > > Most of the code I see and write at work at Runa uses (not (empty? foo)). > I'll continue to defend the position that it is more obvious code, and > therefore better (imo :) ) > > seq belongs to seq-land. empty? belongs to

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-12 Thread Gavin Grover
Or even define `if-not-empty` or `when-not-empty` without the double `not`. On Sunday, May 12, 2013 9:04:43 AM UTC+8, Jean Niklas L'orange wrote: > > On Saturday, May 11, 2013 11:28:34 PM UTC+2, Sean Corfield wrote: > >> you could just write [...] >> > > In some cases, this is even more readable:

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Jean Niklas L'orange
On Saturday, May 11, 2013 11:28:34 PM UTC+2, Sean Corfield wrote: > you could just write [...] > In some cases, this is even more readable: (if-not (empty? foo) (do-something-to foo) base-expr) which has the same effect, but in some cases, having (do-something-to foo) first may be more

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Rob Lachlan
Doesn't anyone use "not-empty"? http://clojuredocs.org/clojure_core/clojure.core/not-empty On Saturday, May 11, 2013 1:36:57 AM UTC-7, Nico Balestra wrote: > > I'm not sure this question has been asked already, but I really want to > know the "principle" behind (not (empty? coll)) not being idi

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Alex Baranosky
Sean, I'd tend to write things like that, yeah. On Sat, May 11, 2013 at 2:49 PM, AtKaaZ wrote: > I agree > > > On Sat, May 11, 2013 at 10:25 PM, Alex Baranosky < > alexander.barano...@gmail.com> wrote: > >> Most of the code I see and write at work at Runa uses (not (empty? foo)). >> I'll conti

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread AtKaaZ
I agree On Sat, May 11, 2013 at 10:25 PM, Alex Baranosky < alexander.barano...@gmail.com> wrote: > Most of the code I see and write at work at Runa uses (not (empty? foo)). > I'll continue to defend the position that it is more obvious code, and > therefore better (imo :) ) > > Alex > > > On Sa

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Sean Corfield
But then instead of (if (not (empty? foo)) (do-something-to foo) base-expr) you could just write (if (empty? foo) base-expr (do-something-to foo)) which maintains the "idiomatic" approach but is still "more obvious code", yes? Sean On Sat, May 11, 2013 at 2:20 PM, Jonathan Fischer Fr

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Jonathan Fischer Friberg
On Sat, May 11, 2013 at 9:25 PM, Alex Baranosky < alexander.barano...@gmail.com> wrote: > Most of the code I see and write at work at Runa uses (not (empty? foo)). > I'll continue to defend the position that it is more obvious code, and > therefore better (imo :) ) > > Alex > Completely agree. (

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Alex Baranosky
Most of the code I see and write at work at Runa uses (not (empty? foo)). I'll continue to defend the position that it is more obvious code, and therefore better (imo :) ) Alex On Sat, May 11, 2013 at 12:22 PM, Karsten Schmidt wrote: > > What's the "idiom" in (seq coll)? > > Maybe one could s

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Karsten Schmidt
> What's the "idiom" in (seq coll)? Maybe one could say that, generally, in Clojure it's more meaningful to work with truthy values instead of the boolean true... ? -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send emai

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Chris Ford
IMHO it's a bit subjective, but empty? is defined as (not (seq coll)), so using (not (empty? coll)) is really saying (not (not (seq coll))), which feels a bit backwards. Using seq also plays nicely with if-let: (if-let [foo (seq "hey")] (print foo)) (if-let [foo (seq "")] (print foo)) Chris On

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Kelker Ryan
Here's an example. user=> (if (seq []) (println 1)) nil user=> (if (seq [1]) (println 1)) 1 nil 11.05.2013, 18:40, "Kelker Ryan" > (seq coll) will return a true value if the collection isn't empty. It will > also return nil (false) if it is. > > 11.05.2013, 17:37, "Nico Balestra" : > >>  I'm no

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Kelker Ryan
(seq coll) will return a true value if the collection isn't empty. It will also return nil (false) if it is. 11.05.2013, 17:37, "Nico Balestra" : > I'm not sure this question has been asked already, but I really want to know > the "principle" behind (not (empty? coll)) not being idiomatic. > > I

Why is using (not (empty? coll)) not idiomatic?

2013-05-11 Thread Nico Balestra
I'm not sure this question has been asked already, but I really want to know the "principle" behind (not (empty? coll)) not being idiomatic. I find it much more readable than (seq coll) and I don't understand why (empty?) exists if it's not idiomatic. But my real doubt is: What's the "idiom" in (