我已经基于Ellis Dee的vb6版本在Autolisp中完成了MergeSort算法的实现:http://www.vbforums.com/showpost.php?p=2909257&postcount=12
问题是我需要替换lisp数组中的第n个原子,目前唯一可以实现这一点的方法是迭代整个列表。这需要一个壮观的排序算法,并通过对列表进行第n次(log)迭代来破坏其效率。我会尽量不让水太浑浊,但这是我的第n个替换函数,基于Michels第n个移除函数。。。
- (defun nth-replace (n_atom f_list f_n / ) ;replaced the nth element of a list
- ;n_atom is new atom
- ;f_list is list to be operated on
- ;f_n is the index that will be replaced
- (if (and (numberp f_n) (listp f_list))
- (if (and (>= f_n 0) (< f_n (length f_list)) n_atom)
- (progn
- (repeat f_n
- (setq f_list (append (cdr f_list) (list (car f_list))))
- )
- (setq f_list (append (cdr f_list) (list n_atom)))
- (repeat (- (length f_list) f_n 1)
- (setq f_list (append (cdr f_list) (list (car f_list))))
- )
- )
- )
- )
- f_list
- );defun
我对autolisp并不完全陌生,但我希望有一个我忽略的基本函数,可以在某个级别替换原子,或者可以将列表返回到某个原子(第n个实例),然后我可以附加我的更改,然后是列表的后半部分。 |