(push x list)
expands to
(setq list (cons x list))
What expands to the following:
(setq list (app
Joshua Taylor mentioned how to do it in Common Lisp. I will answer how in Emacs Lisp:
(require 'cl-lib)
(defmacro appendf (place &rest lists)
`(cl-callf append ,place ,@lists))
(defmacro prependf (list place)
`(cl-callf2 append ,list ,place))
And some test:
(let ((to-prepend '(the good))
(acc '(the bad))
(to-append-1 '(the weird))
(to-append-2 '(pew pew)))
(prependf to-prepend acc)
(appendf acc to-append-1 to-append-2)
(list :acc acc
:to-prepend to-prepend
:to-append-1 to-append-1
:to-append-2 to-append-2))
; ⇒ (:acc (the good the bad the weird pew pew) :to-prepend (the good) :to-append-1 (the weird) :to-append-2 (pew pew))
Macro expansion test:
(let ((print-gensym t))
(print
(macroexpand '(prependf y (cddr x)))))
; prints (let* ((#:a1 y) (#:v x)) (setcdr (cdr #:v) (append #:a1 (cddr #:v))))
For macroexpand-1 and pretty printing, use the macrostep package.