If I have a list of numbers
(setq numbers '(10 11 12))
and I want to increment, say, the third number, I can do this:
(setf (nth 2 numbers) (1+ (nth 2 numbers)))
But I don't like having to repeat the "(nth 2 numbers)". Is there some way I can write this but only have one reference to "(nth 2 numbers)"?
There's a macro for exactly that:
(incf (nth 2 numbers))
You can supply the value to add as an additional argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With