Hi all,
assoc-set! either replaces a value in an alist *in-place* or prepends a
new pair if the key isn't present in the alist.
However, I need a function the *appends* the entry if it is created newly.
I came up with swapping the first element to the end if assoc-set! has
modified the length of the list, but somehow this looks unnecessarily
complicated:
\version "2.19.35"
#(define alst '((one . 1) (two . 2)))
#(define (append-alist alst key-name value)
(let ((intermediate (assoc-set! alst key-name value)))
(if (> (length intermediate) (length alst))
(append (cdr intermediate) (list (car intermediate)))
intermediate)))
#(display (append-alist alst 'three 3))
#(newline)
#(display (append-alist alst 'one 4))
#(newline)
Is there a more straightforward way to have the behaviour of assoc-set!
but with appending instead of prepending newly created elements?
TIA
Urs
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user