Comments (3)
CDR-2 covers it. genhash
is an available library for this.
from cl-cookbook.
https://www.reddit.com/r/Common_Lisp/comments/es7wso/the_best_way_to_use_clos_objects_as_keys_for/
Recently I've (re-)discovered that you cannot (successfully) use CLOS objects as keys for hash-tables.
This is due to the fact that hash-tables only allow standard comparators (eq/eql/equal(p)). These do not work for CLOS objects and you cannot provide your own comparator. There is a genhash library that I am going to use now, but I don't like using external libraries for such simple problems.
i recently had a pleasant experience with generic-cl. i didn't want to use the whole thing (or rather, i saw some weird errors when i passed (:mix :some-package-that-shadows-a-cl-symbol :generic-cl) to uiop:define-package and got scared off), so i just did (:shadowing-import-from :generic-cl :equalp :hash-map :make-hash-map :get :hash). then i defined equalp and hash methods. for a class named -> with slots input and output, i have:
(defmethod equalp ((lhs ->) (rhs ->))
(and (equalp (->-input lhs) (->-input rhs))
(equalp (->-output lhs) (->-output rhs))))
(defmethod hash ((obj ->))
(logand (+ (hash (->-input obj))
(hash (->-output obj)))
most-positive-fixnum))
from there, i just find & replace'd hash-table => hash-map and gethash => get.
from cl-cookbook.
But it's too uncommon isn't it?
from cl-cookbook.
Related Issues (20)
- Invitation Expired HOT 1
- Feature Request: Improve Search HOT 1
- Unit test example does not work HOT 2
- May I translate Cookbook on Russian? HOT 4
- Change "Threads" page name to "Concurrency and parallelism" HOT 1
- advise and watch really exist in sbcl? HOT 2
- Sockets tutorial goes on tangents, used `unwind-protect` instead of macros
- PDF version code snippets truncated HOT 2
- Actually Show An Example Of The Interpol Syntactic Sugar HOT 3
- Show an Example of The PPCRE SEXPS Syntax HOT 1
- Add do Example
- http signatures, (+ digest header) HOT 1
- where does "slime-setup" code from editors.md go in .emacs? HOT 5
- sbcl-librarian: easy build of shared libraries callable from C and Python (SBCL-only) HOT 1
- Improve the section on the different arguments to make-array
- Use uiop:define-package in package section HOT 3
- Fix typos, grammar, etc HOT 7
- Feature Request: Chapter on streams HOT 4
- Functions -> setf Functions needs better example HOT 3
- request: equality page HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cl-cookbook.