I want to know how this works:
(setf (car x) 42)
Does (car x) return an assignable reference to setf? Or is it all just macro magic? How does setf or car work?
I know passing by reference would be a terrible sin in functional programming, but I want to know how the above is done.
It’s macro magic. The form (setf place value) is nothing but a specialised macro expansion. For example, (setf (car x) 42) would be translated into something like this: (rplaca x 42).
You can see how your Lisp implementation expands a SETF form using MACROEXPAND, like so (my example is using SBCL, other implementations may have completely different expansions):
You can also define your own expansions: