-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.lisp
More file actions
44 lines (37 loc) · 1.37 KB
/
list.lisp
File metadata and controls
44 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;; (c) Дмитрий Пинский <demetrius@neverblued.info>
;; Допускаю использование и распространение согласно
;; LLGPL -> http://opensource.franz.com/preamble.html
(in-package #:cl-blackjack)
(defun average-length (&rest sequences)
(aif sequences
(/ (apply #'+ (mapcar #'length it))
(length it))
0))
(defun any (&rest items)
(random-elt items))
(defun badjoin (item list &key key (test #'eql))
(reverse (adjoin item (reverse list) :key key :test test)))
(defun find-assoc (needle assoc-pairs &key (test #'eql) (fetch #'second))
(funcall fetch
(find needle
assoc-pairs
:test test
:key #'first)))
(defun group (source n)
(if (zerop n) (error "Zero length."))
(labels ((rec (source acc)
(let ((rest (nthcdr n source)))
(if (consp rest)
(rec rest (cons
(subseq source 0 n)
acc))
(nreverse
(cons source acc))))))
(if source (rec source nil) nil)))
(defmacro make-revolver-magazine (source)
(let ((g-source (gensym)))
`(let ((,g-source ,source))
(lambda ()
(let ((item (first ,g-source)))
(setf ,g-source (append (rest ,g-source) (list item)))
item)))))