[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
16/21: gurses: Avoid yet another use of car and cdr.
From: |
John Darrington |
Subject: |
16/21: gurses: Avoid yet another use of car and cdr. |
Date: |
Sun, 29 Jan 2017 07:35:02 +0000 (UTC) |
jmd pushed a commit to branch wip-installer
in repository guix.
commit 8daaa73a47dbee57ecdc72fa8cd2890705b4d62f
Author: John Darrington <address@hidden>
Date: Fri Jan 27 09:07:29 2017 +0100
gurses: Avoid yet another use of car and cdr.
* gurses/stexi.scm (pad-complex-string): Use match instead of car and cdr.
---
gurses/stexi.scm | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/gurses/stexi.scm b/gurses/stexi.scm
index cb383e8..6a0a6a7 100644
--- a/gurses/stexi.scm
+++ b/gurses/stexi.scm
@@ -196,23 +196,25 @@ string of length LEN"
(words 0)
(spaces 0)
(prev-white #t))
- (if (null? in)
- (reverse out)
- (let* ((white (xchar-blank? (car in)))
- (end-of-word (and white (not prev-white)))
- (words-processed (if end-of-word (1+ words) words))
- (spaces-inserted (if end-of-word
- (truncate (- (*
- (/ underflow
inter-word-space-count)
- words-processed)
- spaces))
- 0)))
- (loop (cdr in)
- ;; FIXME: Use a more intelligent algorithm.
- ;; (prefer spaces at sentence endings for example)
- (append
- (make-list spaces-inserted (normal #\space))
- (cons (car in) out))
- words-processed
- (+ spaces spaces-inserted)
- white)))))))))
+ (match
+ in
+ (() (reverse out))
+ ((first . rest)
+ (let* ((white (xchar-blank? first))
+ (end-of-word (and white (not prev-white)))
+ (words-processed (if end-of-word (1+ words) words))
+ (spaces-inserted (if end-of-word
+ (truncate (- (*
+ (/ underflow
inter-word-space-count)
+ words-processed)
+ spaces))
+ 0)))
+ (loop rest
+ ;; FIXME: Use a more intelligent algorithm.
+ ;; (prefer spaces at sentence endings for example)
+ (append
+ (make-list spaces-inserted (normal #\space))
+ (cons first out))
+ words-processed
+ (+ spaces spaces-inserted)
+ white))))))))))
- 05/21: installer: Tolerate an undefined system role in config generation., (continued)
- 05/21: installer: Tolerate an undefined system role in config generation., John Darrington, 2017/01/29
- 09/21: installer: Clear the mount point field for swap file systems., John Darrington, 2017/01/29
- 03/21: installer: Add new procedure to check file system specifications., John Darrington, 2017/01/29
- 01/21: installer: Delete unused procedure "justify"., John Darrington, 2017/01/29
- 20/21: gurses: Add new procedure "word-endings"., John Darrington, 2017/01/29
- 14/21: gurses: Add predicate to test if a complex char is blank., John Darrington, 2017/01/29
- 12/21: gurses: Avoid one usage of car and cdr., John Darrington, 2017/01/29
- 15/21: gurses: Avoid one more use of car and cdr., John Darrington, 2017/01/29
- 13/21: gurses: xchar->char: New procedure., John Darrington, 2017/01/29
- 19/21: installer: Support WEP encrypted wireless., John Darrington, 2017/01/29
- 16/21: gurses: Avoid yet another use of car and cdr.,
John Darrington <=
- 11/21: installer: Fix the key map option., John Darrington, 2017/01/29
- 18/21: gurses: In paragraph-format avoid use of car and cdr., John Darrington, 2017/01/29
- 06/21: installer: Use a "hard" method of rebooting. Do not rely on shepherd., John Darrington, 2017/01/29
- 10/21: installer: Allow file system specifications to be removed., John Darrington, 2017/01/29
- 17/21: gurses: Use match instead of car/cdr in line-split., John Darrington, 2017/01/29
- 21/21: gurses: Reimplement pad-complex-string., John Darrington, 2017/01/29