How can I iterate over a plist, prompt for each key a value and fill in said value into the plist?
I have 'the skeleton' of a list of properties for my projects
(defconst project-properties
'(:number nil
:place nil
:location nil))
I copy this list and fill in the values so I keep a skeleton list and have the filled in list to process it further.
I managed to do it for an alist, but am unable to change the functionality to let it work with plists.
(defun project-prompt-properties-alist ()
"Prompt for project properties and return them"
(let ((properties (copy-alist project-properties)))
(cl-loop for (prop . val) in properties
do (setf (alist-get prop properties) (read-string (format "Geef %s: " prop))))
properties))
Both Common Lisp and Elisp allow you to loop over a list using
onwhich iterates on successive tails of the list, instead ofinwhich iterates on successive elements of the list. For example:You can further use the
bykeyword to reduce the input list by two elements instead of one on each iteration:You can use destructuring to take the first two elements of each tail:
These features work the same in Elisp. You should be able to write
project-prompt-properties-plistfor Elisp like this: