aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-07-15 10:31:57 -0500
committerColin Okay <cbeok@protonmail.com>2020-07-15 10:31:57 -0500
commit2622a909e9277ef1b3eaa193bd53ac5cab152a73 (patch)
tree0301be036219f729ee9dc30e38ea86aed31f931f
parentb072097c20373d0d6d7698b3d5593235ca2e2128 (diff)
added scrambler example
-rw-r--r--README.md30
-rw-r--r--examples.lisp2
2 files changed, 31 insertions, 1 deletions
diff --git a/README.md b/README.md
index 86c9c49..4f455f7 100644
--- a/README.md
+++ b/README.md
@@ -87,6 +87,36 @@ example apears at the end of the document, following the tutorial.
```
+### A Silly Scrambler
+
+``` lisp
+
+;; see examples.lisp for defuns of PAD and CHUNK
+
+> (defun scramble (n str)
+ (assert (< n (length str)))
+ (let ((str (pad str (* n (ceiling (/ (length str) n))))))
+ (concatenate 'string
+ (apply #'nconc
+ (mapcar #'collect
+ (disperse! n (seq str)))))))
+
+> (defun descramble (n str)
+ (concatenate 'string
+ (collect
+ (apply #'intersperse!
+ (mapcar #'seq (chunk n str))))))
+
+
+> (scramble 3 "this will be scrabled, ya dig?")
+
+"tsi rbdyd?h lbsal,ai iwlecme g "
+
+> (descramble 3 *)
+"this will be scrambled, ya dig? "
+
+```
+
## Tutorial
GTWIWTG is a tiny library for creating and using generators.
diff --git a/examples.lisp b/examples.lisp
index df50a23..33ae013 100644
--- a/examples.lisp
+++ b/examples.lisp
@@ -122,7 +122,7 @@ vector VEC, one at a time."
;;; Silly Scrambler ;;;
-(defun pad (str len &optional (pad-char #\Space]))
+(defun pad (str len &optional (pad-char #\Space))
(let ((i 0))
(with-output-to-string (out)
(loop :for c :across str :do (incf i) (princ c out))