# HG changeset patch # User Steve Losh # Date 1542988535 18000 # Node ID f2f853a0d29e98b8a3426ab33effc00f435e476d # Parent edbdc9c9cb0a7471a92dfc5a792d203fff5c8e9b Add string-join diff -r edbdc9c9cb0a -r f2f853a0d29e losh.asd --- a/losh.asd Sat Nov 10 19:35:46 2018 -0500 +++ b/losh.asd Fri Nov 23 10:55:35 2018 -0500 @@ -47,6 +47,7 @@ "chili-dogs")) (:file "sequences" :depends-on ("chili-dogs" "hash-tables" + "functions" "mutation")) (:file "debugging" :depends-on ("control-flow" "math" diff -r edbdc9c9cb0a -r f2f853a0d29e package.lisp --- a/package.lisp Sat Nov 10 19:35:46 2018 -0500 +++ b/package.lisp Fri Nov 23 10:55:35 2018 -0500 @@ -253,6 +253,7 @@ (defpackage :losh.sequences (:use :cl :iterate :losh.quickutils :losh.chili-dogs + :losh.functions :losh.hash-tables :losh.iterate-pre :losh.mutation) @@ -270,7 +271,8 @@ :drop-while :summation :product - :doseq)) + :doseq + :string-join)) (defpackage :losh.debugging (:use :cl :iterate :losh.quickutils diff -r edbdc9c9cb0a -r f2f853a0d29e src/sequences.lisp --- a/src/sequences.lisp Sat Nov 10 19:35:46 2018 -0500 +++ b/src/sequences.lisp Fri Nov 23 10:55:35 2018 -0500 @@ -355,3 +355,18 @@ result)) +(defun string-join (separator sequence) + "Join a `sequence` of objects into a string, separated by `separator`. + + All objects in `sequence` (and `separator`) will be `princ-to-string`ed before + joining. + + This is implemented simply, not efficiently, so consider implementing your own + if you're joining a lot of stuff. + + " + (unless (stringp separator) + (callf separator #'princ-to-string)) + (flet ((concat (current next) + (concatenate 'string current separator next))) + (reduce (nullary #'concat "") sequence :key #'princ-to-string)))