-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First pass in inlining the necessary bits from a.el #29
Conversation
Somewhat frustrating that (map-insert '((:node-type . :symbol) (:position . 14) (:form . "bar") (:value . bar)) :form "123")
;;=>
((:form . "123") (:node-type . :symbol) (:position . 14) (:form . "bar") (:value . bar)) |
Perhaps @NicolasPetton can help with this?
That's fine, as now |
AFAICT the docstring explicitly allows for duplicates in the case of alists, since
Note in particular the alist specialiser's docstring. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just a few tiny notes from me in passing :).
parseclj.el
Outdated
(defun parseclj-alist (&rest kvs) | ||
"Create an association list from the given keys and values KVS. | ||
Arguments are simply provided in sequence, rather than as lists or cons cells. | ||
For example: (a-alist :foo 123 :bar 456)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the example mention parseclj-alist
instead of a-alist
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixed!
"Create an association list from the given keys and values KVS. | ||
Arguments are simply provided in sequence, rather than as lists or cons cells. | ||
For example: (a-alist :foo 123 :bar 456)" | ||
(mapcar (lambda (kv) (cons (car kv) (cadr kv))) (seq-partition kvs 2))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, since map.el
version 2.0, which can be installed from GNU ELPA and comes bundled with Emacs 27, one can also say (map-into kvs 'alist)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good suggestion. I've added them as a comment for now. Would it be enough to declare (map "2")
as a Package-Requires
for this to generally work out of the box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's enough.
parseclj.el
Outdated
hash table is created without extra storage space, so with a size | ||
equal to amount of key-value pairs, since it is assumed to be | ||
treated as immutable. | ||
For example: (a-hash-table :foo 123 :bar 456)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto re: a-hash-table
/parseclj-hash-table
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
(let* ((kv-pairs (seq-partition kvs 2)) | ||
(hash-map (make-hash-table :test 'equal :size (length kv-pairs)))) | ||
(seq-do (lambda (pair) | ||
(puthash (car pair) (cadr pair) hash-map)) | ||
kv-pairs) | ||
hash-map)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto re: (map-into kvs 'hash-table)
.
parseclj.el
Outdated
hash-map)) | ||
|
||
(defun parseclj-alist-assoc (coll k v) | ||
"Like parseclj-alist-assoc but actually works as advertised, not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recursive docstring? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing a search-and-replace gone wrong. I've rewritten the docstring.
(if (map-contains-key coll k) | ||
(mapcar (lambda (entry) | ||
(if (equal (car entry) k) | ||
(cons k v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is desirable, but FWIW that (cons k v)
will replace all equal
duplicates of k
with eq
duplicates of k
.
If that is undesirable, one can write (cons (car entry) v)
instead, thus preserving the original key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not something I thought about much since the whole point of value semantics is that these would be indistinguishable, but in case they are not I do think it's more useful for the newer k
to replace the old.
I've incorporated the feedback, and also actually dropped the I hope that's good, let me know if folks needs anything more from me. |
Thanks, Arne! I think we're good to go here, although I also think 1.0 reflects better the state of the project at this point.
We need the similar changes done for |
Necessary for inclusing in ELPA. See also clojure-emacs/parseclj#29
I think we're good to go here. Arne would you like to merge this or you're fine with me doing it and cutting the new release? |
Please feel free to do the honors! |
Necessary for inclusing in ELPA. See also clojure-emacs/parseclj#29
At this point only the tests still contain two invocations of
a-equal
. Unfortunately inlining that one would mean copying over much of a.el, and there is no close equivalent immediately available in Emacs.