flopo Posted November 7, 2011 Posted November 7, 2011 (edited) 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! Edited November 8, 2011 by SLW210 Added Code Tags!!!! Quote
Tharwat Posted November 7, 2011 Posted November 7, 2011 I guess you need to use *cond* function not *while* . Quote
flopo Posted November 7, 2011 Author Posted November 7, 2011 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? Quote
Tharwat Posted November 7, 2011 Posted November 7, 2011 e.g. (cond ((eq nrpct 15.) (progn (setq a ........) (setq b ......... And so on till the end of fifteen points as you have mentioned . Quote
flopo Posted November 7, 2011 Author Posted November 7, 2011 In my lisp, nrpct can be between 7 and 100 ... should i write this way? not too much? maybe some shorter... Quote
Tharwat Posted November 7, 2011 Posted November 7, 2011 What are trying to accomplish ? Maybe we could find any other shorter way instead of your long way of doing it . Quote
flopo Posted November 7, 2011 Author Posted November 7, 2011 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. Quote
pBe Posted November 7, 2011 Posted November 7, 2011 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 6 nmlst '(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); <------ activate this one to give you the value ;;; ) command: (MAKEVAR nrpct 99 pcota cota ) Value for PZ23 "-31.00" Granting the point value equivalent for nrpct exists i.e. nrpct---> 23 p23 ----> not nil Quote
BIGAL Posted November 8, 2011 Posted November 8, 2011 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)) ) Quote
Stefan BMR Posted November 8, 2011 Posted November 8, 2011 ... if nrpct=15 (for example), i want to set 15 points - point1, point2...point15 - in my case pz1, pz2 ...pz17. How to do it? Salut Flo This is what you're looking for? (setq i 1) (repeat nrpct ;sau (while (<= i nrpct)... (set (read (strcat "pz" (itoa i))) (rtos (+ cota (- (cadr (eval (read (strcat "p" (itoa i)) ) ) ) (cadr pcota) ) ) 2 2 ) ) (setq i (1+ i)) ) But I think is better to use something like (setq lista_cote (mapcar '(lambda (x) (rtos(+ cota (- (cadr x) (cadr pcota))) 2 2 ))) (list p1 p2 ... ))) Quote
flopo Posted November 8, 2011 Author Posted November 8, 2011 Thanks guys! Stefan, i think your first variant is exactly what i was asking for. But i will try both solutions you gave me. Quote
alanjt Posted November 8, 2011 Posted November 8, 2011 Thanks guys!Stefan, i think your first variant is exactly what i was asking for. But i will try both solutions you gave me. That's a lot of variables you won't be able to localize. Use this list; much cleaner and faster. Quote
pBe Posted November 9, 2011 Posted November 9, 2011 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) ...... Any help? Thanks! The way i read your code is you already have p1,p2,p3... variables and you need to create a new variable based on whats already defined. p1...p99 cota pcota A sub like the one i posted will create a new variable, and with the proper code you localized that 1 varaible, as a matter of fact you dont even need to assigned it to an unknown variable name. (setq NewVal (MakeVar ....)) I used a list as the argument for member (the variable this), i would suggest testing number of pt* variables (which by my understanding are already defined) and use that as the TTL arg, where lst is pcota num2add as cota I dont know your reason for creating points but take Alanjts advice and use a list as the the final result rather than unknown number of variables: ((1.0 2.0. 3.0)(2.0 4.0 5.0)(2.0 4.0 5.0)) instead of p1 p2 p3 but this: (setq pz8 (rtos(+ cota (- (cadr p8 (cadr pcota))) 2 2 ))).. is not creating a point value but a string value Anyway. Hope this helps.. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.