Re: Pattern of Succinctness

2012-08-13 Thread dmirylenka
Using threading operators + anonymous functions sometimes yields more 
succinct code than using HOF,
especially because 'partial' and 'comp' are such long names:

(comp count (partial filter nil?) (partial map foo))

#(->> %  (map foo)  (filter nil?) count)

On Sunday, August 12, 2012 7:35:16 PM UTC+2, Takahiro Hozumi wrote:
>
> Hi,
> I would like to know common technics that make code succinct.
>
> For example:
> (or (:b {:a 1}) 0)
> (:b {:a 1} 0)
>
> (if-not x 1 2)
> (if x 2 1)
>
> (filter #(not (nil? %)) coll)
> (filter identity coll) ;; nearly equal
>
> Please let me know any tips you found.
>
> Cheers,
> Takahiro.
>

-- 
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: Pattern of Succinctness

2012-08-13 Thread dmirylenka
Should be (filter (comp not nil?) coll)

On Sunday, August 12, 2012 9:44:11 PM UTC+2, Pierre-Henry Perret wrote:
>
> I prefer  (filter (partial not nil?) coll)  as a HOF
>
> Le dimanche 12 août 2012 20:46:59 UTC+2, rmarianski a écrit :
>>
>> On Sun, Aug 12, 2012 at 11:22:55AM -0700, Takahiro Hozumi wrote: 
>> > > (filter (partial not nil?) coll) 
>> > You mean (filter (comp not nil?) coll). 
>> > I'm not sure which is more readable, but thanks for Meikel and Alex, I 
>> now 
>> > prefer (remove nil? coll). 
>>
>> remove is better in this case, but for posterity (comp not nil?) can be 
>> spelled as (complement nil?) 
>>
>> Robert 
>>
>

-- 
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: Pattern of Succinctness

2012-08-12 Thread Alan Malloy
This doesn't work.

On Sunday, August 12, 2012 12:44:11 PM UTC-7, Pierre-Henry Perret wrote:
>
> I prefer  (filter (partial not nil?) coll)  as a HOF
>
> Le dimanche 12 août 2012 20:46:59 UTC+2, rmarianski a écrit :
>>
>> On Sun, Aug 12, 2012 at 11:22:55AM -0700, Takahiro Hozumi wrote: 
>> > > (filter (partial not nil?) coll) 
>> > You mean (filter (comp not nil?) coll). 
>> > I'm not sure which is more readable, but thanks for Meikel and Alex, I 
>> now 
>> > prefer (remove nil? coll). 
>>
>> remove is better in this case, but for posterity (comp not nil?) can be 
>> spelled as (complement nil?) 
>>
>> Robert 
>>
>

-- 
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: Pattern of Succinctness

2012-08-12 Thread Pierre-Henry Perret
I prefer  (filter (partial not nil?) coll)  as a HOF

Le dimanche 12 août 2012 20:46:59 UTC+2, rmarianski a écrit :
>
> On Sun, Aug 12, 2012 at 11:22:55AM -0700, Takahiro Hozumi wrote: 
> > > (filter (partial not nil?) coll) 
> > You mean (filter (comp not nil?) coll). 
> > I'm not sure which is more readable, but thanks for Meikel and Alex, I 
> now 
> > prefer (remove nil? coll). 
>
> remove is better in this case, but for posterity (comp not nil?) can be 
> spelled as (complement nil?) 
>
> Robert 
>

-- 
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: Pattern of Succinctness

2012-08-12 Thread Robert Marianski
On Sun, Aug 12, 2012 at 11:22:55AM -0700, Takahiro Hozumi wrote:
> > (filter (partial not nil?) coll)
> You mean (filter (comp not nil?) coll).
> I'm not sure which is more readable, but thanks for Meikel and Alex, I now 
> prefer (remove nil? coll).

remove is better in this case, but for posterity (comp not nil?) can be
spelled as (complement nil?)

Robert

-- 
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: Pattern of Succinctness

2012-08-12 Thread Takahiro Hozumi
> (filter (partial not nil?) coll)
You mean (filter (comp not nil?) coll).
I'm not sure which is more readable, but thanks for Meikel and Alex, I now 
prefer (remove nil? coll).

Thanks.

On Monday, August 13, 2012 2:38:23 AM UTC+9, Tamreen Khan (Scriptor) wrote:
>
> Is the last one considered generally more readable? I think the following 
> is clearer while still not having as much noise as the first filter example:
>
> (filter (partial not nil?) coll)
>
> On Sun, Aug 12, 2012 at 1:35 PM, Takahiro Hozumi 
> 
> > wrote:
>
>> Hi,
>> I would like to know common technics that make code succinct.
>>
>> For example:
>> (or (:b {:a 1}) 0)
>> (:b {:a 1} 0)
>>
>> (if-not x 1 2)
>> (if x 2 1)
>>
>> (filter #(not (nil? %)) coll)
>> (filter identity coll) ;; nearly equal
>>
>> Please let me know any tips you found.
>>
>> Cheers,
>> Takahiro.
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>
On Monday, August 13, 2012 2:38:23 AM UTC+9, Tamreen Khan (Scriptor) wrote:
>
> Is the last one considered generally more readable? I think the following 
> is clearer while still not having as much noise as the first filter example:
>
> (filter (partial not nil?) coll)
>
> On Sun, Aug 12, 2012 at 1:35 PM, Takahiro Hozumi 
> 
> > wrote:
>
>> Hi,
>> I would like to know common technics that make code succinct.
>>
>> For example:
>> (or (:b {:a 1}) 0)
>> (:b {:a 1} 0)
>>
>> (if-not x 1 2)
>> (if x 2 1)
>>
>> (filter #(not (nil? %)) coll)
>> (filter identity coll) ;; nearly equal
>>
>> Please let me know any tips you found.
>>
>> Cheers,
>> Takahiro.
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>
On Monday, August 13, 2012 2:38:23 AM UTC+9, Tamreen Khan (Scriptor) wrote:
>
> Is the last one considered generally more readable? I think the following 
> is clearer while still not having as much noise as the first filter example:
>
> (filter (partial not nil?) coll)
>
> On Sun, Aug 12, 2012 at 1:35 PM, Takahiro Hozumi 
> 
> > wrote:
>
>> Hi,
>> I would like to know common technics that make code succinct.
>>
>> For example:
>> (or (:b {:a 1}) 0)
>> (:b {:a 1} 0)
>>
>> (if-not x 1 2)
>> (if x 2 1)
>>
>> (filter #(not (nil? %)) coll)
>> (filter identity coll) ;; nearly equal
>>
>> Please let me know any tips you found.
>>
>> Cheers,
>> Takahiro.
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>
On Monday, August 13, 2012 2:38:23 AM UTC+9, Tamreen Khan (Scriptor) wrote:
>
> Is the last one considered generally more readable? I think the following 
> is clearer while still not having as much noise as the first filter example:
>
> (filter (partial not nil?) coll)
>
> On Sun, Aug 12, 2012 at 1:35 PM, Takahiro Hozumi 
> 
> > wrote:
>
>> Hi,
>> I would like to know common technics that make code succinct.
>>
>> For example:
>> (or (:b {:a 1}) 0)
>> (:b {:a 1} 0)
>>
>> (if-not x 1 2)
>> (if x 2 1)
>>
>> (filter #(not (nil? %)) coll)
>> (filter identity coll) ;; nearly equal
>>
>> Please let me know any tips you found.
>>
>> Cheers,
>> Takahiro.
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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

AW: Pattern of Succinctness

2012-08-12 Thread Meikel Brandmeyer
Hi,

pay attention:
(or (:a {:a false}) 0)
(:a {:a false} 0)

Same holds in case false is nil.

Using these "transformations" can easily introduce bugs, depending on the 
context.

Kind regards
Meikel

-Ursprüngliche Nachricht-
Von: Takahiro Hozumi 
An: clojure@googlegroups.com
Gesendet: So, 12 Aug 2012, 19:35:16 MESZ
Betreff: Pattern of Succinctness

Hi,
I would like to know common technics that make code succinct.

For example:
(or (:b {:a 1}) 0)
(:b {:a 1} 0)

(if-not x 1 2)
(if x 2 1)

(filter #(not (nil? %)) coll)
(filter identity coll) ;; nearly equal

Please let me know any tips you found.

Cheers,
Takahiro.

-- 
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: Pattern of Succinctness

2012-08-12 Thread Alex Baranosky
(filter identity foos) and (filter #(not (nil? %)) foos) aren't equivalent.

I prefer (remove nil? foos)  Succint and direct.

On Sun, Aug 12, 2012 at 11:13 PM, Bill Caputo  wrote:

>
> On Aug 12, 2012, at 12:38 PM, Tamreen Khan wrote:
>
> (filter #(not (nil? %)) coll)
>> (filter identity coll) ;; nearly equal
>>
>
> Is the last one considered generally more readable? I think the following
> is clearer while still not having as much noise as the first filter example:
>
> (filter (partial not nil?) coll)
>
>
> To me it is. I read/heard somewhere that the identity check was idiomatic,
> and started using it to the point where I find myself saying "filter
> identity" as slang for keeping only the valid things.
>
> but that's just me (maybe)... don't know that it is generally considered
> more readable (but I think so).
>
>
> bill
>
>  --
> 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

AW: Re: Pattern of Succinctness

2012-08-12 Thread Meikel Brandmeyer
Hi,

in case you really want only nils filtered out:

(filter (complement nil?) coll)
or
(remove nil? coll)

Kind regards
Meikel

-Ursprüngliche Nachricht-
Von: Bill Caputo 
An: Tamreen Khan 
Cc: clojure@googlegroups.com
Gesendet: So, 12 Aug 2012, 19:43:58 MESZ
Betreff: Re: Pattern of Succinctness


On Aug 12, 2012, at 12:38 PM, Tamreen Khan wrote:
> (filter #(not (nil? %)) coll)
> (filter identity coll) ;; nearly equal

> Is the last one considered generally more readable? I think the following is 
> clearer while still not having as much noise as the first filter example:
> 
> (filter (partial not nil?) coll)

To me it is. I read/heard somewhere that the identity check was idiomatic, and 
started using it to the point where I find myself saying "filter identity" as 
slang for keeping only the valid things.

but that's just me (maybe)... don't know that it is generally considered more 
readable (but I think so).


bill

-- 
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: Pattern of Succinctness

2012-08-12 Thread Bill Caputo

On Aug 12, 2012, at 12:38 PM, Tamreen Khan wrote:
> (filter #(not (nil? %)) coll)
> (filter identity coll) ;; nearly equal

> Is the last one considered generally more readable? I think the following is 
> clearer while still not having as much noise as the first filter example:
> 
> (filter (partial not nil?) coll)

To me it is. I read/heard somewhere that the identity check was idiomatic, and 
started using it to the point where I find myself saying "filter identity" as 
slang for keeping only the valid things.

but that's just me (maybe)... don't know that it is generally considered more 
readable (but I think so).


bill

-- 
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: Pattern of Succinctness

2012-08-12 Thread Tamreen Khan
Is the last one considered generally more readable? I think the following
is clearer while still not having as much noise as the first filter example:

(filter (partial not nil?) coll)

On Sun, Aug 12, 2012 at 1:35 PM, Takahiro Hozumi wrote:

> Hi,
> I would like to know common technics that make code succinct.
>
> For example:
> (or (:b {:a 1}) 0)
> (:b {:a 1} 0)
>
> (if-not x 1 2)
> (if x 2 1)
>
> (filter #(not (nil? %)) coll)
> (filter identity coll) ;; nearly equal
>
> Please let me know any tips you found.
>
> Cheers,
> Takahiro.
>
> --
> 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

Pattern of Succinctness

2012-08-12 Thread Takahiro Hozumi
Hi,
I would like to know common technics that make code succinct.

For example:
(or (:b {:a 1}) 0)
(:b {:a 1} 0)

(if-not x 1 2)
(if x 2 1)

(filter #(not (nil? %)) coll)
(filter identity coll) ;; nearly equal

Please let me know any tips you found.

Cheers,
Takahiro.

-- 
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