cl-gserver icon indicating copy to clipboard operation
cl-gserver copied to clipboard

Provide pre-configured agent for alists and plists

Open Ambrevar opened this issue 4 years ago • 7 comments

As for #34, it would make sense to unify the 2 data structure agents considering how similar they are.

But the CL standard uses different APIs for the two: assoc for alists and getf for plists.

If we are going to follow CL, then we can make serarate agents. If not, we can unify the interfaces. But then, why not unify the plist/alist interface with that of hash-tables?

Ambrevar avatar Jul 10 '21 10:07 Ambrevar

The agent for those two could be generic. Both functions assoc and getf could be supported depending on whether the user uses the agent for a plist or alist. I don't actually know, how are values removed from a/plist. Is there something like remhash or even clrhash?

mdbergmann avatar Jul 10 '21 13:07 mdbergmann

For plist, you can use remf:

(let ((p '(:foo 17 :bar 18))) (remf p :bar) p)

For alist, I don't know if there is something better then delete:

(let ((a '((foo . 17) (bar 18)))) (setf a (delete 'foo a :key #'first)) a)

Or, with Alexandria:

(let ((a '((foo . 17) (bar 18)))) (alexandria:deletef a 'foo :key #'first) a)

Ambrevar avatar Jul 10 '21 15:07 Ambrevar

I think an acceptable interface would be to allow agent-assoc and agent-getf with setf but only do a agent-dolist with a lambda where the user can arbitrarily use remf of remove-if, or delete or however we wants to delete or filter entries.

mdbergmann avatar Jul 11 '21 10:07 mdbergmann

Can you explain your rationale?

Ambrevar avatar Jul 11 '21 10:07 Ambrevar

What I mean is that the removal (mostly delete) of entries in at least the alist seems combersome and I thought it should be done by the user that can choose between delete and deletef, etc. But maybe it should still be considered and pre-configured for a simpler use.

mdbergmann avatar Jul 11 '21 14:07 mdbergmann

remf could be abstracted to handle plists and alists the same way.

generic-cl has erase.

Ambrevar avatar Jul 11 '21 16:07 Ambrevar

remf could be abstracted to handle plists and alists the same way.

Yeah. I think that would make sense here.

mdbergmann avatar Jul 11 '21 17:07 mdbergmann