alex-gutev / generic-cl

Generic function interface to standard Common Lisp functions
https://alex-gutev.github.io/generic-cl/
MIT License
143 stars 8 forks source link

Implement "elt" for hash maps and tables #3

Closed anlsh closed 4 years ago

anlsh commented 4 years ago

This PR implements generic-cl:elt and corresponding setf expanders for generic-cl:hash-map and hash-table, as I suggested in Issue #2.

It also implements appropriate tests, updates the README, and fixes some formatting in generic-cl.asd

I should note that the (setf) elt definitions

https://github.com/anlsh/generic-cl/blob/aa8f2ed2e89d24d15877faabf45c27c8ecef2b33/src/cl-sequences.lisp#L52-L67

Are pretty much copied from the corresponding generic-cl:get definitions

https://github.com/alex-gutev/generic-cl/blob/261f5ca6ace28643d9da8f14f22efac3b6113402/src/hash-tables.lisp#L183-L200

Doing it this way avoids another dynamic dispatch, but if we wanted to we could call those functions directly instead (maybe static-dispatch would even optimize the extra dispatch away for us? I don't have experience with it)

alex-gutev commented 4 years ago

I've reformatted the generic-cl.asd file as the formatting issues seem to be caused by a mixed use of tabs and spaces for indentation. I've replaced all tabs with spaces in that file.

As regards to the implementation of the ELT methods, theoretically this should be a trivial case for static-dispatch to optimize, with an appropriate type declaration, however the current implementations will do. In a future commit I may replace then with statically dispatched calls to the GET methods.