Here's a LOOP version of an index constructor.
(defun make-index-list (obj seq &key (test #'eql))
(loop for p = (position obj seq :test test :start (if p (1+ p) 0))
while p
collect p))
(compile *)
CL-USER 18 >
(make-index-list
'(0 1)
'(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar)
:test #'equal)
(2 5)
Carl Taylor wrote:
Here's a LOOP version of an index constructor.
(defun make-index-list (obj seq &key (test #'eql))
(loop for p = (position obj seq :test test :start (if p (1+ p) 0))
while p
collect p))
(compile *)
CL-USER 18 >
(make-index-list
'(0 1)
'(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar)
:test #'equal)
(2 5)
Gauche Scheme
(define (make-index-list obj seq :optional (test equal?))
(filter-map
(lambda(x i) (and (test obj x) i))
seq
(lrange 0)))
(make-index-list
'(0 1)
'(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar))
(2 5)
(where (op equal '(0 1)) '(a (6 2 z) (0 1) (1 2 3 4)(q w e r t y) (0 1) (foo) bar))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 388 |
Nodes: | 16 (2 / 14) |
Uptime: | 10:02:29 |
Calls: | 8,221 |
Files: | 13,122 |
Messages: | 5,872,631 |