Last active
August 22, 2016 14:57
-
-
Save Lifelovinglight/456335a3328e696c4c357ab91b6cb889 to your computer and use it in GitHub Desktop.
Improved implementation of space intercalation for chatbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (srfi srfi-1)) | |
(define (ae string) | |
(if (string-null? string) | |
string | |
(let loop ((result (make-string (1- (* 2 (string-length string))))) | |
(index 0) | |
(len (string-length string)) | |
(blank-line #t)) | |
(if (= index len) | |
(if blank-line | |
(make-string 0) | |
result) | |
(let ((char (string-ref string index))) | |
(string-set! result (* 2 index) char) | |
(when (< index (1- len)) | |
(string-set! result (1+ (* 2 index)) #\space)) | |
(loop result (1+ index) len (not (or (not blank-line) | |
(not (char-whitespace? char)))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment