LispMechanics / cl-data-structures

MIT License
4 stars 11 forks source link

Design: we need a reasonable generic api #1

Open sirherrbatka opened 7 years ago

sirherrbatka commented 7 years ago

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.

sirherrbatka commented 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.

MatthewRock commented 7 years ago

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.

sirherrbatka commented 7 years ago

Well, those were examples. We just need to have those in place…

sirherrbatka commented 7 years ago

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.

MatthewRock commented 7 years ago

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))
sirherrbatka commented 7 years ago

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.

MatthewRock commented 7 years ago

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.

sirherrbatka commented 7 years ago

I will stick with core, we can consider adding everything else later.