Skip to content

Commit

Permalink
Fixes in ZIP family.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseloved committed Feb 10, 2014
1 parent 7b3920e commit 6af77d2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
28 changes: 16 additions & 12 deletions core/list.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -206,33 +206,37 @@ argument.")
"Return a single list whose elements are lists
of the consecutive elements of LISTS,
until one of the LISTS ends."
(apply #'zip-with #'list lists))
(when lists
(apply #'zip-with #'list lists)))

(defun zip-with (fn &rest lists)
"Return a single list whose elements are the results
of applying FN to groups of the consecutive elements of LISTS,
until one of the LISTS ends."
(let (rez)
(do ((tails lists (mapcar #'cdr tails)))
((some #'null tails))
(push (apply fn (mapcar #'car tails)) rez))
(reverse rez)))
(when lists
(let (rez)
(do ((tails lists (mapcar #'cdr tails)))
((some #'null tails))
(push (apply fn (mapcar #'car tails)) rez))
(reverse rez))))

(defun zip* (&rest lists)
"Return a single list whose elements are lists
of the consecutive elements of LISTS,
until all of the LISTS end."
(apply #'zip*-with #'list lists))
(when lists
(apply #'zip*-with #'list lists)))

(defun zip*-with (fn &rest lists)
"Return a single list whose elements are the results
of applying FN to groups of the consecutive elements of LISTS,
until all of the LISTS end."
(let (rez)
(do ((tails lists (mapcar #'cdr tails)))
((every #'null tails))
(push (apply fn (mapcar #'car tails)) rez))
(reverse rez)))
(when lists
(let (rez)
(do ((tails lists (mapcar #'cdr tails)))
((every #'null tails))
(push (apply fn (mapcar #'car tails)) rez))
(reverse rez))))

(defun maptimes (times fn)
"Map FN with number range from 0 to TIMES (exclusive)."
Expand Down
2 changes: 1 addition & 1 deletion rutils-test.asd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(asdf:defsystem #:rutils-test
:name "Radical utilities test suite."
:version "1.1.0"
:version "1.1.1"
:author "Vsevolod Dyomkin <vseloved@gmail.com>"
:maintainer "Vsevolod Dyomkin <vseloved@gmail.com>"
:licence "3-clause MIT licence"
Expand Down
2 changes: 1 addition & 1 deletion rutils.asd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

(asdf:defsystem #:rutils
:name "Radical utilities"
:version "3.1.2";(:read-file-line "version.txt")
:version "3.1.3";(:read-file-line "version.txt")
:author "Vsevolod Dyomkin <vseloved@gmail.com>"
:maintainer "Vsevolod Dyomkin <vseloved@gmail.com>"
:licence "3-clause MIT licence"
Expand Down
8 changes: 8 additions & 0 deletions test/list-test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
(set-equal '(:foo :bar) '(:foo :bar :baz))))

(deftest zip ()
(should be null
(zip))
(should be equal '((:foo :baz) (:bar 42))
(zip '(:foo :bar) '(:baz 42)))
(should be equal '((:foo :baz))
Expand All @@ -170,10 +172,14 @@
(zip '(:foo :bar) ())))

(deftest zip-with ()
(should be null
(zip-with 'identity))
(should be equal '((:foo . :baz) (:bar . 42))
(zip-with 'cons '(:foo :bar) '(:baz 42))))

(deftest zip* ()
(should be null
(zip*))
(should be equal '((:foo :baz) (:bar 42))
(zip* '(:foo :bar) '(:baz 42)))
(should be equal '((:foo :baz) (:bar nil))
Expand All @@ -182,6 +188,8 @@
(zip* '(:foo :bar) ())))

(deftest zip*-with ()
(should be null
(zip*-with 'identity))
(should be equal '((:foo . 41) (:bar . 42) (:baz))
(zip*-with 'cons '(:foo :bar :baz) '(41 42))))

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
3.1.2
3.1.3
1.1.0

0 comments on commit 6af77d2

Please sign in to comment.