乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 31|回复: 12

[编程交流] lisp help - while

[复制链接]

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-6 08:42:36 | 显示全部楼层 |阅读模式
Hi guys,
this part of a lisp i want to modify - to use while function.
 
  
  1. (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!
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 08:51:20 | 显示全部楼层
I guess you need to use *cond* function not *while* .
回复

使用道具 举报

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 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?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 09:00:08 | 显示全部楼层
e.g.
 
  1. (cond ((eq nrpct 15.)(progn (setq a ........)(setq b ......... And so on till the end of fifteen points as you have mentioned .
回复

使用道具 举报

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 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...
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 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 .
回复

使用道具 举报

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 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

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-6 09:21:50 | 显示全部楼层
Not sure why you used the operator >=
 
I would write it this way:

[code](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
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 09:26:47 | 显示全部楼层
maybe use repeat if you know howmany
 
  1. (setq x 0 )(repeat nrpct(setq ptans (nth x ptslist))  ; do your car bit here(princ ptans)(setq x (+ x 1)) )
回复

使用道具 举报

0

主题

375

帖子

385

银币

限制会员

铜币
-7
发表于 2022-7-6 09:28:50 | 显示全部楼层
Salut Flo
This is what you're looking for?

[code](setq i 1)(repeat nrpct                           ;sau (while (
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-1 10:40 , Processed in 1.460875 second(s), 73 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表