Bug with clojure.set/intersection, clojure.set/difference etc.

35 views
Skip to first unread message

ntu...@googlemail.com

unread,
Jan 29, 2009, 9:42:48 AM1/29/09
to clo...@googlegroups.com
If its left argument is nil, "intersection" throws a NPE (Clojure rev. 1235):

user=> (set/intersection nil #{1})
java.lang.NullPointerException (NO_SOURCE_FILE:0)
user=> (.printStackTrace *e)
java.lang.NullPointerException (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4186)
at clojure.core$eval__3830.invoke(core.clj:1647)
at clojure.main$repl__5568$fn__5586.invoke(main.clj:148)
at clojure.main$repl__5568.doInvoke(main.clj:145)
at clojure.lang.RestFn.invoke(RestFn.java:426)
at clojure.main$repl_opt__5610.invoke(main.clj:208)
at clojure.main$main__5645$fn__5647.invoke(main.clj:295)
at clojure.main$main__5645.doInvoke(main.clj:289)
at clojure.lang.RestFn.invoke(RestFn.java:402)
at clojure.lang.Var.invoke(Var.java:332)
at clojure.lang.AFn.applyToHelper(AFn.java:172)
at clojure.lang.Var.applyTo(Var.java:453)
at clojure.main.main(main.java:39)
Caused by: java.lang.NullPointerException
at clojure.core$disj__3445.invoke(core.clj:915)
at clojure.core$reduce__3173$fn__3176.invoke(core.clj:549)
at clojure.core$reduce__3173.invoke(core.clj:547)
at clojure.set$difference__5658.invoke(set.clj:19)
at clojure.set$intersection__5661.invoke(set.clj:24)
at user$eval__259.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:4175)
... 12 more
nil
user=> (msg/select-messages msgs nil "OR" nil)
nil
user=> (set/intersection #{} nil)
#{}

The same is true for clojure.set/difference and everything else that
uses clojure.disj with nil for the first parameter.

Cheers,
nt

Jason Wolfe

unread,
Jan 29, 2009, 1:10:01 PM1/29/09
to Clojure
I think this is not a bug in disj. disj takes a *set* and an element
as input. nil is the empty seq, which is different from the empty set
#{}. The fact that clojure.set functions work at all on things other
than bona fide sets is, in Rich's words, "an implementation artifact
and not a promise of the interface".

-Jason

Meikel Brandmeyer

unread,
Jan 29, 2009, 1:27:35 PM1/29/09
to clo...@googlegroups.com
Hi,

Am 29.01.2009 um 15:42 schrieb ntu...@googlemail.com:

> If its left argument is nil, "intersection" throws a NPE (Clojure
> rev. 1235):

> The same is true for clojure.set/difference and everything else that
> uses clojure.disj with nil for the first parameter.

IMHO, this is not a bug. nil is not a set, in particular not the empty
set.
Much in the same sense, that nil is not the empty list.

But one could argue, that accepting nil as empty set is a convenience.
Or that the bug is, that nil is accepted as second parameter for
intersection,
where a set is expected.

Sincerely
Meikel

ntu...@googlemail.com

unread,
Jan 30, 2009, 2:38:54 AM1/30/09
to Clojure
On Jan 29, 7:10 pm, Jason Wolfe <jawo...@berkeley.edu> wrote:
> I think this is not a bug in disj.  disj takes a *set* and an element
> as input.  nil is the empty seq, which is different from the empty set
> #{}.

Well, then forget my remark about disj and let's concentrate on the
set functions. Those operate on sets *but* it is highly inconsistent
to allow nil as a second argument but not as a first if both
parameters should accept the same type.

> The fact that clojure.set functions work at all on things other
> than bona fide sets is, in Rich's words, "an implementation artifact
> and not a promise of the interface".

Hm. Maybe these weakly typed languages are not made for me.

- nt
Reply all
Reply to author
Forward
0 new messages