flopo 发表于 2022-7-6 08:42:36

lisp help - while

Hi guys,
this part of a lisp i want to modify - to use while function.
 

(if ( >= nrpct 7) (setq pz7 (rtos(+ cota (- (cadr p7) (cadr pcota)))2 2 )))      (if ( >= nrpct(setq pz8 (rtos(+ cota (- (cadr p8 (cadr pcota)))2 2 )))      (if ( >= nrpct 9) (setq pz9 (rtos(+ cota (- (cadr p9) (cadr pcota)))2 2 )))      (if ( >= nrpct 10) (setq pz10 (rtos(+ cota (- (cadr p10) (cadr pcota)))2 2 )))    (if ( >= nrpct 11) (setq pz11 (rtos(+ cota (- (cadr p11) (cadr pcota)))2 2 )))    (if ( >= nrpct 12) (setq pz12 (rtos(+ cota (- (cadr p12) (cadr pcota)))2 2 )))    (if ( >= nrpct 13) (setq pz13 (rtos(+ cota (- (cadr p13) (cadr pcota)))2 2 )))    (if ( >= nrpct 14) (setq pz14 (rtos(+ cota (- (cadr p14) (cadr pcota)))2 2 )))      (if ( >= nrpct 15) (setq pz15 (rtos(+ cota (- (cadr p15) (cadr pcota)))2 2 )))      (if ( >= nrpct 16) (setq pz16 (rtos(+ cota (- (cadr p16) (cadr pcota)))2 2 )))      (if ( >= nrpct 17) (setq pz17 (rtos(+ cota (- (cadr p17) (cadr pcota)))2 2 )))      (if ( >= nrpct 18) (setq pz18 (rtos(+ cota (- (cadr p18 (cadr pcota)))2 2 )))      (if ( >= nrpct 19) (setq pz19 (rtos(+ cota (- (cadr p19) (cadr pcota)))2 2 )))      (if ( >= nrpct 20) (setq pz20 (rtos(+ cota (- (cadr p20) (cadr pcota)))2 2 )))
 
 
Any help? Thanks!

Tharwat 发表于 2022-7-6 08:51:20

I guess you need to use *cond* function not *while* .

flopo 发表于 2022-7-6 08:55:52

I don't know if is ok with cond. I have a variable, nrpct, and i want to set some points this way : if nrpct=15 (for example), i want to set 15 points - point1, point2...point15 - in my case pz1, pz2 ...pz17. How to do it?

Tharwat 发表于 2022-7-6 09:00:08

e.g.
 

(cond ((eq nrpct 15.)(progn (setq a ........)(setq b ......... And so on till the end of fifteen points as you have mentioned .

flopo 发表于 2022-7-6 09:02:49

In my lisp, nrpct can be between 7 and 100 ... should i write this way? not too much? maybe some shorter...

Tharwat 发表于 2022-7-6 09:08:53

What are trying to accomplish ?
 
Maybe we could find any other shorter way instead of your long way of doing it .

flopo 发表于 2022-7-6 09:13:12

I want to set let's say 90 points, if nrpct=90. So, if nrpct=90, i want to set point1, point2 ....point90 -this is what i want to do.

pBe 发表于 2022-7-6 09:21:50

Not sure why you used the operator >=
 
I would write it this way:

(defun MakeVar (numtest TTl lst num2add / this nmlst n suf) (setq i    6nmlst '(1) ) (if (setq this   (member numtest      (repeat TTl      (setq nmlst (append nmlst       (list (setq i (1+ i)))      )      )      )   )   )   (set (setq n (read (strcat "pZ" (setq suf (itoa (car this)))))) (rtos (+ num2add   (- (cadr (eval (read (strcat "p" suf)))) (cadr lst))       )       2       2 )   ) );;; This lines will show you the Variable name and its value ;;;;; Remove hte princ/print lines to give you the value;;; (princ (strcat "\nValue for " (vl-symbol-name n))) (print (eval n)) (princ);;;         ;;;;;; (eval n);   23</p>p23 ----> not nil

BIGAL 发表于 2022-7-6 09:26:47

maybe use repeat if you know howmany
 

(setq x 0 )(repeat nrpct(setq ptans (nth x ptslist)); do your car bit here(princ ptans)(setq x (+ x 1)) )

Stefan BMR 发表于 2022-7-6 09:28:50

Salut Flo
This is what you're looking for?

(setq i 1)(repeat nrpct                           ;sau (while (
页: [1] 2
查看完整版本: lisp help - while