Does Common Lisp have a something like java's Set Interface/implementing classes?

前端 未结 8 1035
无人及你
无人及你 2021-01-12 01:58

I need something like this, a collection of elements which contains no duplicates of any element. Does Common Lisp, specifically SBCL, have any thing like this?

8条回答
  •  孤街浪徒
    2021-01-12 02:36

    For a quick solution, just use hash tables, as has been mentioned before.

    However, if you prefer a more principled approach, you can take a look at FSet, which is “a functional set-theoretic collections library”. Among others, it contains classes and operations for sets and bags.

    (EDIT:) The cleanest way would probably be to define your set-oriented operations as generic functions. A set of generic functions is basically equivalent to a Java interface, after all. You can simply implement methods on the standard HASH-TABLE class as a first prototype and allow other implementations as well.

提交回复
热议问题