Update: If I have a few functions that I want to mutate a global variable that is passed as a function argument, some can do this by passing just the symbol of the global (as in the case of pushing something onto part of a list), but other functions will require that the symbol be quoted when it is passed so I can access the symbol-value and mutate the outside variable, required for using setq in a function. This question is basically about creating a consistent interface for a user of these functions without confusing them that sometimes you pass the symbol, othertimes you pass the quoted symbol
Example way to streamline the interface for a bunch of functions, by using a helper that has the same usage reqardless of how the mutating function works:
Here are 2 basic examples of my technique:
(defun push-something (global something)
(push something global)
global) ;; not necessary to return it here since the
;; preceding line already does, but doing so
;; for consistency with other functions and clarity
(defun push-cdr (global something)
(push something (cdr global))
global) ;; must return it if I am going to set the
;; dynamic var to the result of this function,
;; because the preceding line doesn't return the
;; entire new result of the variable
;;; "dirty" function for mutating global variable using "clean" functions above:
(defun set-global (fn global &rest values)
(setf (symbol-value global) (apply fn (copy-list (eval global)) values)))
In this last one, I must eval the global since it is quoted for use with symbol-value and then I copy-list so that global isn't directly mutated accidentally by whatever fn I choose (as would be the case with push-cdr which might be non-trivial in more complicated functions).
Output:
CL-USER> (defparameter *g2* nil)
*G2*
CL-USER> (set-global #'push-something '*g2* 5)
(5)
CL-USER> *g2*
(5)
CL-USER> (set-global #'push-cdr '*g2* 99)
(5 99)
CL-USER> *g2*
(5 99)
...and the same functions could be used with *g1* or *g3* etc all through the access function set-global.
Is this good or bad style, or am I missing a much better way to achieve this functionality?