小编ink*_*pen的帖子

用于对整数排序列表进行分组的惯用法?

我有一个整数的排序列表,(1 2 4 5 6 6 7 8 10 10 10).我想将它们分组,以便我得到((1) (2) (4) (5) (6 6) (7) (8) (10 10 10)).

到目前为止,我有这个,它有效:

(let ((current-group (list)) (groups (list)))
  (dolist (n *sorted*)
    (when (and (not (null current-group)) (not (eql (first current-group) n)))
      (push current-group groups)
      (setf current-group (list)))
    (push n current-group))
  (push current-group groups)
  (nreverse groups))
Run Code Online (Sandbox Code Playgroud)

但我确信必须有更多的LISPy方法来做到这一点.有任何想法吗?

lisp common-lisp

3
推荐指数
1
解决办法
237
查看次数

标签 统计

common-lisp ×1

lisp ×1