马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
 - ;; CAB 10/15/2005
- ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++
- ;; Return a sub list starting at the nth position and
- ;; with the number of items specified by num
- ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++
- (defun nth+ (idx ; start position 0 = first item
- lst ; list of items
- num ; number of items to return
- ;; 0= all remaining items
- / newlst)
- (and (or (numberp num) ; catch non numbers
- (setq num 0)) ; force all
- (zerop num) ; if zero
- (setq num (length lst)) ; all
- )
- (repeat num
- (setq newlst (cons (nth idx lst) newlst)
- idx (1+ idx))
- )
- (reverse (vl-remove nil newlst))
- )
 - (defun c:tt()
- (print (nth+ 0 '(1 2 3 4 5) 2)) ; |-> (1 2)
- (print (nth+ 3 '(1 2 3 4 5) 2)) ; |-> (4 5)
- (print (nth+ 4 '(1 2 3 4 5) 5)) ; |-> (5)
- (print (nth+ 6 '(1 2 3 4 5) 2)) ; |-> nil
- (print (nth+ 2 '(1 2 3 4 5) 0)) ; |-> (3 4 5)
- (princ)
- )
|