前一阵我要用的时候,就是写不好,
可能我提的要求和我上次的问题不一样.
不要求from和to一定是数值,因为用的时候自然会注意的.比如(+ "A"1)自然不给你算的
我的:

- (defun nth-n(lst from to / is-max is-min j)
- (or from(setq from 0))
- (or to (setq to(1-(length lst))))
- (setq is-max(max from to)
- is-min(min from to)
- j -1)
- (setq lst(apply 'append
- (mapcar '(lambda(##)(if(<= is-min(setq j(1+ j))is-max)(list ##)))lst)
- ))
- (if(> from to)(reverse lst)lst)
- )
命令: (nth-n a 6 3)
(6 5 4 3)
命令: (nth-n a 60 3)
(9 8 7 6 5 4 3)
命令: (nth-n a 60 -3)
(9 8 7 6 5 4 3 2 1 0)
命令: (nth-n a nil -3)
(0)
命令: (nth-n a nil nil)
(0 1 2 3 4 5 6 7 8 9)
命令: (nth-n a nil 10)
(0 1 2 3 4 5 6 7 8 9)
命令: (nth-n a 1 nil)
(1 2 3 4 5 6 7 8 9)
命令: (nth-n a 1 6)
(1 2 3 4 5 6)
命令: !a
(0 1 2 3 4 5 6 7 8 9)
命令: (nth-n a -3 -2)
nil
反映很热烈,下次我还出题目:) |