Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CONCATENATE #432

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sequence.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,19 @@
(funcall result-collector (apply function args))
(apply function args)))))

(defun check-sequence-type-specifier (specifier)
(unless (member specifier '(vector string list))
(error "Not a valid sequence type specifier")))

(defun concatenate (result-type &rest sequences)
(check-sequence-type-specifier result-type)
(let ((iterators (mapcar #'make-iterator sequences))
(result-collector (make-collector result-type)))
(dolist (it iterators)
(do ((arg (funcall it) (funcall it)))
((eq *iterator-done* arg))
(funcall result-collector arg)))
(funcall result-collector)))

;;; remove duplicates
(defun %remove-duplicates (seq from-end test test-not key start end)
Expand Down
18 changes: 18 additions & 0 deletions tests/seq.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@
(list acc result))
'((3 2 1) t))

;;; CONCATENATE
(test-equal
(concatenate 'string "all" " " "together" " " "now")
"all together now")

(test-equal
(concatenate 'list "ABC" '(d e f) #(1 2 3) "1011")
'(#\A #\B #\C D E F 1 2 3 #\1 #\0 #\1 #\1))

(test-equal
(concatenate 'list)
nil)

(test-equal
(handler-case
(concatenate '(vector * 2) "a" "bc")
(error () :signalled))
:signalled)


;;; REMOVE-DUPLICATES
Expand Down