samifox 发表于 2022-7-6 06:45:51

无限循环

你好
 
调用此函数后:
 

(defun getLowest ()
(setq val (list 309.011 120.605 200.445 670.225))
(while (vl-list-length val) <= i)
(princ "Enter loop")
(setq i (+ i 1))
) ;_defun

Lee Mac 发表于 2022-7-6 06:59:43

检索排序列表第一项的y值(查看c*r函数);或者,由于您只需要最低的y值,因此不需要对整个列表进行排序,只需使用foreach函数逐步遍历原始列表中的每个项目,并将每个项目的y值与之前存储的最低y值进行比较。

samifox 发表于 2022-7-6 07:05:45

Lee Mac 发表于 2022-7-6 07:18:41

 
The correct syntax would be:

(while (

samifox 发表于 2022-7-6 07:23:42

 
what is the right syntax to advance i by 1 so the while loop will stop when it get to the last item of the list?

Lee Mac 发表于 2022-7-6 07:35:16

 
You would need to assign a numerical value to the symbol i before the while loop expression; however, to simply iterate over every item in a list, the foreach function is more suitable.

samifox 发表于 2022-7-6 07:41:26

i get this code to sort coordinates by thier Y value, now how can i return the lowest Y value?
 

(defun main () (vl-sort '((1 3) (2 2) (3 1) (3 1)) (function (lambda (e1 e2) (< (cadr e1) (cadr e2)))))) ;_defun

Lee Mac 发表于 2022-7-6 07:51:03

Retrieve the y-value of the first item of the sorted list (look into the c*r functions); alternatively, since you only require the lowest y-value, you needn't sort the entire list, but simply step through each item in the original list using the foreach function, and compare the y-value of each item with a previously stored lowest y-value.
页: [1]
查看完整版本: 无限循环