After quite a while of studying CL and practising as a hobby in different small projects, I still have some blank areas on my personal CL map. Recently, I had a number of functions using all the same let construct and I thought of writing a macro which makes the code more concise:
(defmacro with-context (&body body)
`(let ((context (make-array 4 :element-type 'fixnum
:initial-contents '(0 1 2 3))))
,@body))
So that I can later define functions like (just as a minimal example):
(defun test-a ()
(with-context
(setf (aref context 3)
(+ (aref context 0) (aref context 1)))
context))
Now I was wondering if I could shorten the (aref context n) expressions with a macro/function like (context n).
(defun context (n)
(aref context n))
But the variable context is unknown at compile time, of course. I just don't know if I have a case of basic misunderstanding here or how I could tell lisp what I actually want. So, my question is basically if it is possible and if it is a good idea.