Common Lisp functions.
Hello,
I have written 2 functions, this way :
(let ((sum 10))
(defun ACC10 (x) (setf sum (+ sum x))))
(let ((sum 50))
(defun ACC50 (x) (setf sum (+ sum x))))
I don't know if I am following good Lisp practices here; but the 2 functions do what I want.
Each of them keeps track of an internal value and I can make calls like :
(ACC10 5)
(ACC10 4)
(ACC10 -3)
(ACC50 -15)
(ACC50 22)
(ACC10 7)
(ACC50 13)
... etc ... each function is doing its book-keeping job.
My first question is :
To write say ACC97; could I start like ?
(defun ACC97 (x)
(let ((sum 97)) ....
instead of like before :
(let ((sum 97))
(defun ACC97 (x) ....
If yes what is the proper syntax ? Since what I tried did not work.
My second question is :
Would it be possible to write a function make-ACC that I could use to genarate my ACC functions above ?
For example in order to make ACC97 I would use something like :
(make-ACC 97)
and in the same way to make ACC50 I would use :
(make-ACC 50)
Here also what I tried did not quite work.
Thanks for any tip.
|