86d92162dc1f

Update to latest cl-losh
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 14 Dec 2021 19:10:46 -0500
parents e3aefcbf364c
children de8dff345414
branches/tags (none)
files src/package.lisp src/problems/grph.lisp src/problems/lcsm.lisp src/problems/mprt.lisp src/problems/orf.lisp src/problems/perm.lisp src/problems/sign.lisp src/problems/sseq.lisp src/problems/subs.lisp src/utils.lisp

Changes

--- a/src/package.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/package.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -27,6 +27,7 @@
     :hamming
 
     :string-empty-p
+    :strjoin
     :first-char
 
     :Σ :Π :binomial-coefficient
--- a/src/problems/grph.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/grph.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -49,10 +49,10 @@
              data)
     ;; (ql:quickload :cl-digraph.dot)
     ;; (digraph.dot:draw graph)
-    (-<> (iterate (for (l . r) :in (digraph:edges graph))
+    (_ (iterate (for (l . r) :in (digraph:edges graph))
                   (collect (format nil "~A ~A~%" l r)))
-      (sort <> #'string<)
-      (str:join nil <>))))
+      (sort _ #'string<)
+      (str:join "" _))))
 
 
 
--- a/src/problems/lcsm.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/lcsm.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -65,15 +65,15 @@
 
 (defun longest-common-substrings-of-any (substrings string)
   "Return the longest common substrings of `string` and any one of `substrings`."
-  (-<> (iterate
+  (_ (iterate
          (for substring :in substrings)
          (appending (longest-common-substrings substring string)))
     longest
-    (remove-duplicates <> :test #'string=)))
+    (remove-duplicates _ :test #'string=)))
 
 (define-problem lcsm (data stream) *input* *output*
   (let ((lines (mapcar #'cdr (u:read-fasta-into-alist data))))
-    (-<> (reduce #'longest-common-substrings-of-any (rest lines)
+    (_ (reduce #'longest-common-substrings-of-any (rest lines)
                  :initial-value (list (first lines)))
-      (sort <> #'string<) ; tests
+      (sort _ #'string<) ; tests
       first)))
--- a/src/problems/mprt.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/mprt.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -25,10 +25,10 @@
 
 (defun motif-to-regex (motif)
   "Turn a protein motif shorthand into a PPCRE scanner."
-  (-<> motif
+  (_ motif
     ;; All we have to do is turn {X} into [^X] and compile.
-    (ppcre:regex-replace-all "[{]" <> "[^")
-    (substitute #\] #\} <>)
+    (ppcre:regex-replace-all "[{]" _ "[^")
+    (substitute #\] #\} _)
     ppcre:create-scanner))
 
 (defun all-matches-dammit (regex target-string)
--- a/src/problems/orf.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/orf.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -24,10 +24,10 @@
   (let* ((dna (cdr (first (u:read-fasta-into-alist data))))
          (rna1 (u:transcribe dna))
          (rna2 (u:transcribe (u:reverse-complement dna))))
-    (-<> (append (translate-all rna1)
+    (_ (append (translate-all rna1)
                  (translate-all rna2))
-      (remove-duplicates <> :test #'string=)
-      (sort <> #'< :key #'length)
-      (format nil "~{~A~^~%~}" <>))))
+      (remove-duplicates _ :test #'string=)
+      (sort _ #'< :key #'length)
+      (format nil "~{~A~^~%~}" _))))
 
 
--- a/src/problems/perm.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/perm.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -19,4 +19,4 @@
     (format nil "~D~%~{~A~^~%~}"
             count
             ;; sort to ensure consistent output for the unit test
-            (sort (mapcar (u:curry #'str:join " ") perms) #'string<))))
+            (sort (mapcar (u:curry #'u:strjoin " ") perms) #'string<))))
--- a/src/problems/sign.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/sign.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -30,4 +30,4 @@
     ;; sort to ensure consistent output for the unit test
     (format nil "~D~%~{~A~^~%~}"
             count
-            (sort (mapcar (u:curry #'str:join " ") perms) #'string<))))
+            (sort (mapcar (u:curry #'u:strjoin " ") perms) #'string<))))
--- a/src/problems/sseq.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/sseq.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -30,6 +30,6 @@
 (define-problem sseq (data stream) *input* *output*
   (let* ((haystack (nth-value 1 (u:read-fasta data)))
          (needle (nth-value 1 (u:read-fasta data))))
-    (-<> (subsequence-positions needle haystack :test #'char=)
-      (mapcar #'1+ <>)
-      (format nil "~{~D~^ ~}" <>))))
+    (_ (subsequence-positions needle haystack :test #'char=)
+      (mapcar #'1+ _)
+      (format nil "~{~D~^ ~}" _))))
--- a/src/problems/subs.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/problems/subs.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -14,5 +14,5 @@
       (for pos :seed -1 :then (search needle haystack :start2 (1+ pos)))
       (while pos)
       (collect (1+ pos) :into result)
-      (finally (return (str:join " " result))))))
+      (finally (return (u:strjoin " " result))))))
 
--- a/src/utils.lisp	Fri Jan 24 23:05:16 2020 -0500
+++ b/src/utils.lisp	Tue Dec 14 19:10:46 2021 -0500
@@ -100,9 +100,9 @@
                        (iterate (for (head body) :in clauses)
                                 (collect (list (subseq head 1) body)))))
                    (split (clauses)
-                     (-<> clauses
-                       (group-by (rcurry #'aref 0) <> :key #'first)
-                       (iterate (for (k v) :in-hashtable <>)
+                     (_ clauses
+                       (group-by (rcurry #'aref 0) _ :key #'first)
+                       (iterate (for (k v) :in-hashtable _)
                                 (collect (list k (strip v)))))))
             (recursively ((clauses (split clauses))
                           (codons (list x y z))
@@ -170,6 +170,11 @@
     nil
     (char string 0)))
 
+(defun strjoin (sep seq)
+  (iterate (for el :in-whatever seq)
+           (concatenating (if (stringp el) el (aesthetic-string el))
+                          :separator sep)))
+
 
 ;;;; Math ---------------------------------------------------------------------
 (defun factorial (x)