Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying a property list

I have a property list:

(setf *star* '(:points 5))

I'd like to modify this plist. Sometimes the better choice is to do mutation, and sometimes the better choice is to use an immutable update.

How to modify the plist using mutation?

(mutate *star* :points 6)
*star* ; '(:points 6)

And how to modify the plist using an immutable update?

(update *star* :points 6) ; '(:points 6)
*star*                    ; '(:points 5)
like image 427
Azeirah Avatar asked Apr 10 '26 04:04

Azeirah


1 Answers

What you are looking for are getf and maybe get-properties. To modify the plist non-destructively, use list*:

(setq *star* (list* :points 6 *star*))

If your plist is associated with a symbol, you should use get and remprop.

NB: it is a much better idea to use association lists (see assoc and acons) because they are more flexible (e.g., it is easier to switch from associating multiple objects with a key using alists).

like image 151
sds Avatar answered Apr 13 '26 16:04

sds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!