马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
安全型NTH函数(可以处理点对)
同时把i值加1使程序更加好理解

- ;;———————————————————————————————————
- ;;#$fildname-> list.lsp
- ;;time-stamp-> 11:03 02-4-22 zjw
- ;;Copyright (C) 2001 by zjw ,WuXi Municipal Enginerring Design Institue. All Rights Reserved.
- ;;-------------------------------------------------
- ;;#$help.begin
- ;;##function.name-> (dd_nth I LST)
- ;;##keyword-> nth 获取 表 元素
- ;;##Description-> 安全获取表元素 不产生错误中断,但修整了参数的含义,比NTH大一
- ;;##Arguments.begin
- ;| |;
- ;;##Arguments.end
- ;;##return-> pointlist <list> 端点表
- ;;##examples.begin
- ;| (dd_nth 1 '( 1 2)) => 1
- ( (dd_nth 3 '( 1 2)) => nil
- ( (dd_nth 2 '( 1 . 2)) => 2 |;
- ;;##examples.end
- ;;##see also->
- ;;#$help.end
- ;;-------------------------------------------------
- ;;##use function->
- ;;##use ddsysvar->
- (defun dd_nth ( i lst / )
- (if (= 'REAL (TYPE I)) (SETQ I (FIX I)))
- (if (and (= 'INT (type i)) (= 'LIST (type lst)))
- (progn
- (if (/= 'LIST (type (cdr lst) ) )
- (setq lst (list (car lst) (cdr lst)))) ;;处理点对,把点对当二个元素的表
- (if (and (> i 0 ) (<= i (length lst)))
- (nth (1- i ) lst)
- )
- )
- )
-
- )
|