Skip to content
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

Merged
merged 5 commits into from
Sep 27, 2021
Merged

Conversation

plexus
Copy link
Collaborator

@plexus plexus commented Aug 12, 2021

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.

@plexus
Copy link
Collaborator Author

plexus commented Aug 12, 2021

Somewhat frustrating that map-insert introduces duplicates, even though the docstring claims it doesn't

(map-insert '((:node-type . :symbol) (:position . 14) (:form . "bar") (:value . bar)) :form "123")
;;=>
((:form . "123") (:node-type . :symbol) (:position . 14) (:form . "bar") (:value . bar))

@bbatsov
Copy link
Member

bbatsov commented Aug 13, 2021

Perhaps @NicolasPetton can help with this?

At this point only the tests still contain two invocations of a-equal.

That's fine, as now a.el can be a dev dep, instead of a runtime dep.

@basil-conto
Copy link

Somewhat frustrating that map-insert introduces duplicates, even though the docstring claims it doesn't

AFAICT the docstring explicitly allows for duplicates in the case of alists, since map-insert is non-destructive and alist lookup order is well-defined, with earlier elements shadowing later ones:

map-insert is a compiled Lisp function in `map.el'.

(map-insert MAP KEY VALUE)

  Probably introduced at or before Emacs version 27.1.

Return a new map like MAP except that it associates KEY with VALUE.
This does not modify MAP.
If you want to insert an element in place, use `map-put!'.
The default implementation defaults to `map-copy' and `map-put!'.

This is a generic function.

Implementations:

((map list) key value) in `map.el'.

Cons KEY and VALUE to the front of MAP.

Note in particular the alist specialiser's docstring.

Copy link

@basil-conto basil-conto left a 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)"

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?

Copy link
Collaborator Author

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)))

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).

Copy link
Collaborator Author

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?

Copy link
Member

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)"

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Comment on lines +51 to +56
(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))

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recursive docstring? :)

Copy link
Collaborator Author

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)

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.

Copy link
Collaborator Author

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.

@plexus
Copy link
Collaborator Author

plexus commented Aug 30, 2021

I've incorporated the feedback, and also actually dropped the a.el from the Package-Requires and bumped the Version from 0.1.0 to 0.2.0 (although maybe it should just be 1.0).

I hope that's good, let me know if folks needs anything more from me.

@bbatsov
Copy link
Member

bbatsov commented Aug 30, 2021

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.

I hope that's good, let me know if folks needs anything more from me.

We need the similar changes done for parseedn, but I guess there it should be simpler as the project is smaller.

plexus added a commit to plexus/parseedn that referenced this pull request Sep 2, 2021
Necessary for inclusing in ELPA.

See also clojure-emacs/parseclj#29
@bbatsov
Copy link
Member

bbatsov commented Sep 22, 2021

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?

@plexus
Copy link
Collaborator Author

plexus commented Sep 22, 2021

Please feel free to do the honors!

@bbatsov bbatsov merged commit 089160a into master Sep 27, 2021
@bbatsov bbatsov deleted the remove-a-dep branch September 27, 2021 06:20
bbatsov pushed a commit to clojure-emacs/parseedn that referenced this pull request Sep 27, 2021
Necessary for inclusing in ELPA.

See also clojure-emacs/parseclj#29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants