Lisp »Tips 'n Tricks 
»Come incrementare un parametro 
Ecco come fare per passare ad una funzione un parametro incrementato in modo regolare: 
(defun funz ( i j / str)
 (setq str (strcat "\nTest[" (itoa i) "]=" (rtos j 2 3)))
 (princ str)
)
(defun c:test ( / stepMx stepMn stepMm frame
                  rapp clock str i
 )
 (setvar "cmdecho" 0)
 (setq stepMx 100 stepMn 30 frame 100)
 (setq stepMm (- stepMx stepMn)) ; 70 passi
 (setq rapp (/ 1 (* 1.0 frame)))
 (setq clock 0)
 (setq i 0)
 (while (< i frame)
  (setq clock (+ clock rapp))
  (funz i (* stepMm clock))
  (setq i (1+ i))
 )
 (setvar "cmdecho" 1)
 (princ)
)
 |   
Test del Lisp 
Command: test
 Test[0]=0.7
 Test[1]=1.4
 Test[2]=2.1
 ...
 Test[97]=68.6
 Test[98]=69.3
 Test[99]=70 
Con (setq stepMx 1000 stepMn 121 frame 444)
 Command: test
 ...
 Test[441]=875.041
 Test[442]=877.02
 Test[443]=879 
Talvolta il parametro 'x' varia all'interno di un intervallo definito da una formula, ad esempio x>0 e x<n-k+2: 
(defun funz ( i j / str)
 (setq str (strcat "\nTest[" (itoa i) "]=" (rtos j 2 3)))
 (princ str)
)
(defun c:test (/ k steps n incr inter i )
 (setvar "cmdecho" 0)
 (setq steps 100)
 (initget (+ 1 2 4)) ; k>0  
 (setq k (getint "\nk? "))
 (while 
  (progn
   (initget (+ 1 2 4)) ; n>0 
   (setq n (getint "\nn? "))
   (if (>= n k) nil T)
  )
 )
 (setq incr (/ (+ (- n k) 2)(- (* 1.0 steps) 1)))
 (setq inter 0)
 (setq i 0)
 (while (< i steps)
  (funz i inter)
  (setq inter (+ inter incr))
  (setq i (1+ i))
 )
 (setvar "cmdecho" 1)
 (princ)
)
 
 |   
Test del Lisp 
Command: test
 k? 3
 n? 2
 n? 5
 
 Test[0]=0
 Test[1]=0.04
 Test[2]=0.081
 ...
 Test[97]=3.919
 Test[98]=3.96
 Test[99]=4 
Lisp »Tips 'n Tricks 
Ultimo Aggiornamento_Last Update: 24 Giugno 2005 
 |