马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- [FONT=courier new]
- ;;; ==================================================================
- (defun txt-remove (x lst)
- (setq lst (txt-list-subtract lst (list x)))
- )
- ;;; ==================================================================
- (defun th-remove-if (pred lst)
- (foreach x lst
- (if (apply
- pred
- (list x)
- )
- (setq lst (txt-list-subtract lst (list x)))
- )
- )
- lst
- )
- ;;; ==================================================================
- (defun th-remove-if-not (pred lst)
- (foreach x lst
- (if (not (apply
- pred
- (list x)
- )
- )
- (setq lst (txt-list-subtract lst (list x)))
- )
- )
- lst
- )
- ;;; ==================================================================
- ;;; 命令: (th-remove-if-not '(lambda(x)(> x 8)) lst)
- ;;; (17 9)
- ;;; 命令: (th-remove-if '(lambda(x)(> x 8)) lst)
- ;;; (1 2 3 3 2 1 6 5 1 5 6 8 1 8 1 6 5 1 4 5 1)
- ;;; 命令: (txt-remove 1 lst)
- ;;; (2 3 3 2 6 5 5 6 17 8 9 8 6 5 4 5)
- ;;; 命令: !lst
- ;;; (1 2 3 3 2 1 6 5 1 5 6 17 8 1 9 8 1 6 5 1 4 5 1)
- ;;; ==================================================================
- (defun txt-list-subtract (lst1 lst2 / lst)
- (setq lst '())
- (if lst1
- (foreach tmp lst1
- (if (not (member tmp lst2))
- (setq lst (cons tmp lst))
- )
- )
- )
- (setq lst (reverse lst))
- lst
- )
- ;;; ==================================================================
- [/FONT]
另外一种写法:
- [FONT=courier new]
- ;;; ==================================================================
- ;;; 命令: (th-remove-if '(lambda(x)(< x 5))lst)
- ;;; (3 1 2 3 4 0 0 4 3 2 1 1 1)
- ;;; 命令: (th-remove-if-not '(lambda(x)(< x 5))lst)
- ;;; (12 5 6 7 8 9 9 8 7 6 5 5 6 6)
- ;;; 命令: (th-remove 1 lst)
- ;;; (12 3 2 3 4 5 6 7 8 9 0 0 9 8 7 6 5 4 3 2 5 6 6)
- ;;; 命令: !lst
- ;;; (12 3 1 2 3 4 5 6 7 8 9 0 0 9 8 7 6 5 4 3 2 1 1 1 5 6 6)
- (defun th-remove (ele lst)
- (apply
- 'append
- (mapcar
- (function (lambda (x)
- (if (/= x ele)
- (list x)
- )
- )
- )
- lst
- )
- )
- )
- (defun th-remove-if-not (pred lst)
- (apply
- 'append
- (mapcar
- (function (lambda (x)
- (if (apply
- pred
- (list x)
- )
- (list x)
- )
- )
- )
- lst
- )
- )
- )
- (defun th-remove-if(pred lst)
- (apply
- 'append
- (mapcar
- (function (lambda (x)
- (if (not (apply
- pred
- (list x)
- )
- )
- (list x)
- )
- )
- )
- lst
- )
- )
- )
- ;;; ==================================================================
- [/FONT]
|