# [CM] lisp loop iteration in cm

**Juan I Reyes
**
juanig@ccrma.Stanford.EDU

*Thu, 14 Sep 2006 19:40:27 -0400*

Hi Rick,
I have been trying to implement the following Lisp function for the
Henon map in CM with no success. Perhaps I am missing something in the
way loops are implemented in CM and therefore I thought may be you could
guide me a little o bit or give some clues on how would be the best way
to deal with this sort of Lisp loops in CM. I just want to output a MIDI
note after each Iteration inside a dotimes Lisp loop and update present
and past values.
Thanks a lot!
--* Juan
;;;
;;; normalize output from Henon function
;;;
(defun midinormz (x)
(let ((offset 1.0)
(maxinput 2.0)
(slope 1.25)
(maxoutput 127.0)
(c 0.75)
(lowbound 15))
(floor (+ (* (/ (+ x offset) (* maxinput slope))
(+ maxoutput c))
lowbound)) ))
;;;
;;; Henon map function with initial conditions:
;;;
(defun henon (cycl &key
(a -1.85039) ;; a=-1.56693 b= -0.011811
(b 0.003937)
(x 0.63135448)
(y 0.18940634) )
(dotimes (i cycl)
(let ((newx (+ (* a (expt x 2)) (* b y) 1))
(newy x))
(setf x newx)
(setf y newy))
(format t ";;; henon values: X: ~f Y: ~f ~%" (midinormz x)
(midinormz y))
))
;;; (henon 12)