Another newbie (Common) LISP question:
Basically in most programming languages there's a mean for functions to receive references to variables instead of just values, that is, passing by reference instead of passing by value. Let's say, for the sake of simplicity, I want to write a LISP function that receives a variable and increases the value of the variable by one:
(defun increase-by-one (var)
(setf var (+ var 1)))
Now obviously the problem is that this function only increases the value of the copy of the variable on the stack, not the actual original variable. I've also tried to achieve the effect by using macros without much success, although I have this feeling that using macros is the right way to go.
I hit this wall all the time in LISP and I'm sure there must be a way around it or maybe there's a completely different approach to this problem in LISP I haven't thought about? How are things like this are done in LISP?
EDIT: Multiple people has suggested using incf
. I only used this example to demonstrate the problem in a simple way, I wasn't actually looking for reimplementing incf. But thanks for the suggestions anyway.