Skip to end of metadata
Go to start of metadata

Should there be syntactic support for sets and set operations in Groovy? Arguments in favor are:

  • They're very useful (see any CS algorithms textbook for examples).
  • Syntax and semantics would be unambiguous (if I could figure out how to put curly braces in-line without Confluence thinking they're a macro invocation, I'd give some examples (wink)).
  • Java's container classes provide a ready-made implementation.

Arguments against:

  • It's mostly enough to focus on Java Collections. Most usage of sets really treats them as generic collections, so just support collections well. (-- jrose)
  • Small sets can be specified as lists; this is appropiate for anything you might write as a literal in a program. (Note also that Common Lisp successfully represents sets as lists, for most purposes.) (-- jrose)
  • Anything you can do using sets, you can do using a map with don't-care values. But using sets directly is clearer, and eliminates arguments over what do with non-empty values when doing "set union" on dictionaries...
  • Why stop at sets? Why not multi-sets, skip lists, ... Because they aren't used nearly as often, just as multi-dimensional arrays aren't used as often as their one-dimensional brethren.

See the Python Sets PEP for more.

  • Greg Wilson
  • No labels