Open sirherrbatka opened 7 years ago
It would be also beneficial for us to not only provide generic function find, but also expect every structure to supply function named (for instance) hash-table-find that will do exactly same thing as find does, but without dynamic dispatch.
Unfortunately symbol FIND is already taken by CL package.
In cl-trie, I have used #'lookup instead, but the name might be subject to change.
I also think that so-called find should also be setf-able; i.e. one should also define (setf find). Find should return two values, the value that was found(or NIL if none was found), and T if we ineed found something(key exists in the structure), or NIL otherwise.
I also think that we need some kind of remove function(but #'remove and #'delete are both taken; maybe #'erase ?), mapkeys, mapvalues, all-keys and all-values (these are trivial, but useful).
Another one is #'size - size of dictionary.
I agree with providing a simple function.
Well, those were examples. We just need to have those in place…
Anyway. Can we agree to use (defgeneric at (container location)), (defgeneric erase (container location)) and (defgeneric erase! (container location))? We can also say (defgeneric without ...) instead of erase if we really don't like scheme style.
I think that erase is a good idea.
The core should be at least:
(defgeneric at (container location))
(defgeneric (setf at) (new-value container location))
(defgeneric erase (container location))
(defgeneric erase! (container location))
(defgeneric size (container))
I suggest to add at least some of the
(defgeneric mapdict (function &rest containers))
(defgeneric mapkeys (function container))
(defgeneric mapvalues (function container))
(defgeneric insert (container location value))
(defgeneric insert! (container location value))
Ok, i agree with the least. I don't agree with with mapdict (we should be able to map everything, not just dicts) nor the mapkeys. In fact, I would consider adding generators instead… Ok, anyway: I will add another package API that will define basic interface. I will also add some trait classes there (see functional vs mutable topic). BTW, we probabbly should think about range/iterator API as well.
I agree with general mapping construct, but MAP is already taken and I couldn't come up fast with some good name. Generators/iterators are probably good idea.
I will stick with core, we can consider adding everything else later.
We need to have set of generic functions that structures are expected to implement. For instance, all sorts of dictionary structures should have some sort of find method that will return value under key.