You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a faulty rule for (not (empty? coll)). it suggests (seq coll)...
Am I right to say that these two expressions should be referential transparent?
You're correct that these two expressions will return different things. The theory behind this is that in usage, (seq coll) still returns a truthy value like (not (empty? coll)).
The docstring for empty? says:
Returns true if coll has no items - same as (not (seq coll)). Please use the idiom (seq x) rather than (not (empty? x))
I can raise a PR to fix this rule.. this rule only works if the expression is used inside a conditional (e.g. if, when, etc.). but when it is used outside a conditional then it will not be same result..
inside a conditional... (when (not (empty? coll)) "mike") is same as (when (seq coll) "mike")
outside a conditional... (let [is-empty (not (empty? coll))] is-empty) is not same as (let [is-empty (seq coll)] is-empty)
I think this would probably need to be a configurable rule, there are also lots of conditionals to check for (including custom ones). I'm probably more inclined to leave it for now, but do you have a real-world example you could show? That might help give me some more context.
I don't currently have a real world example to show, but I think the example I gave above commonly happen in day to day work. I just found it strange that kibit suggested it. Would replacing line 17 of collections.clj with [(when (not (empty? ?x)) . ?y) (when (seq ?x) . ?y)] be enough?
Activity
danielcompton commentedon Jul 1, 2019
You're correct that these two expressions will return different things. The theory behind this is that in usage,
(seq coll)still returns a truthy value like(not (empty? coll)).The docstring for
empty?says:which is where the rule probably came from.
macalimlim commentedon Jul 2, 2019
I can raise a PR to fix this rule.. this rule only works if the expression is used inside a conditional (e.g. if, when, etc.). but when it is used outside a conditional then it will not be same result..
inside a conditional...
(when (not (empty? coll)) "mike")is same as(when (seq coll) "mike")outside a conditional...
(let [is-empty (not (empty? coll))] is-empty)is not same as(let [is-empty (seq coll)] is-empty)danielcompton commentedon Jul 2, 2019
I think this would probably need to be a configurable rule, there are also lots of conditionals to check for (including custom ones). I'm probably more inclined to leave it for now, but do you have a real-world example you could show? That might help give me some more context.
macalimlim commentedon Jul 3, 2019
I don't currently have a real world example to show, but I think the example I gave above commonly happen in day to day work. I just found it strange that kibit suggested it. Would replacing line 17 of collections.clj with
[(when (not (empty? ?x)) . ?y) (when (seq ?x) . ?y)]be enough?danielcompton commentedon Jul 4, 2019
Maybe? I'm a little bit conflicted here TBH.
macalimlim commentedon Jul 4, 2019
what do the other maintainers think about my suggested change?
macalimlim commentedon Jul 11, 2019
any update on this one?
danielcompton commentedon Jul 14, 2019
I'm going to have put this in the hammock to think about. I don't have a lot of time to put into kibit at the moment.