clojure

Jim Newton 2025-11-19T12:39:04.336959Z

grumble grumble grumble, there’s no 0-ary version of distinct? so (apply distinct? some-list) fails if some-list is empty.

raspasov 2025-11-21T09:12:59.630999Z

What should a hypothetical 0-arity distinct? return?

p-himik 2025-11-21T14:08:46.843709Z

> arguments are not distinct if there is a repetition. there is no duplicate in an empty list So true I assume.

πŸ‘ 1
πŸ‘πŸ» 1
p-himik 2025-11-19T12:41:08.470629Z

Yeah, plenty of such cases. But it makes sense, there's no identity element for distinct?. (+) returns 0 because it's its identity element, same for (*) and 1. Or (and) and true, or (or) and nil.

Jim Newton 2025-11-19T12:44:35.356539Z

hmmm. not sure it makes sense. arguments are not distinct if there is a repetition. there is no duplicate in an empty list.

βž• 1
Jim Newton 2025-11-19T12:45:06.401029Z

functions like every behave correctly on an empty sequence

Jim Newton 2025-11-19T12:45:25.725049Z

i’m only using this for debugging so no great harm done.

Jim Newton 2025-11-19T12:52:48.065309Z

on the other hand = cannot be called with 0 arguments

Jim Newton 2025-11-19T12:53:01.713769Z

at least according to the documentation

p-himik 2025-11-19T13:06:08.495709Z

I guess it could be argued any way. Maybe I'm wrong and identity values are completely irrelevant since distinct? is not an algebraic operation but a relational predicate, similar to =. In any case, if you'd like to see (distinct?) working, the best thing to do would be to create a post at https://ask.clojure.org. > functions like every behave correctly on an empty sequence every? is a sequence-function, not an item-based function, it doesn't require apply. And it's almost the same as (apply and (map pred coll)), and and has an identity value which is also true. Same with some - it works with empty colls and returns nil.

2025-11-19T14:03:41.883439Z

you probably have an alternative, but just in case, (if-let [l (seq some-list)] (apply distinct? l) true)

Pavel Filipenco 2025-11-19T15:13:20.158749Z

why request a core feature instead of just writing a helper fn

p-himik 2025-11-19T15:14:32.943459Z

β€’ If it makes sense from the language design perspective, the language will become better β€’ If others need it, nobody will have to write the helper function anymore

πŸ‘ 3
cgrand 2025-11-19T22:11:27.365429Z

Or (apply distinct? (or (seq some-list) [1]))

☝️ 1
2025-11-19T23:20:19.465779Z

I'd go with

((some-fn empty? (partial apply distinct?)) [])
true