Created
October 24, 2015 14:28
-
-
Save jovaneyck/9b97dda57ea08c4ec188 to your computer and use it in GitHub Desktop.
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
(define lorem | |
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." | |
) | |
;; tests | |
;; (equal? (split (list 1 2 3) 0) (list () (list 1 2 3)) ) | |
;; (equal? (split () 5) (list () ()) ) | |
;; (equal? (split (list 1 2 3) 4) (list (list 1 2 3) ()) ) | |
;; (equal? (split (list 1 2 3 4) 2) (list (list 1 2) (list 3 4)) ) | |
(define (split xs pos) | |
(cond | |
((equal? pos 0) | |
(list () xs)) | |
((null? xs) | |
(list () ())) | |
((< (length xs) pos) | |
(list xs ())) | |
(else | |
(let ((acc (split (cdr xs) (- pos 1)))) | |
(list | |
(cons (car xs) (car acc)) | |
(car (cdr acc)) | |
) | |
) | |
) | |
) | |
) | |
(define (take xs n) | |
(cond | |
((equal? n 0) | |
()) | |
((null? xs) | |
(list)) | |
((< (length xs) n) | |
xs) | |
(else | |
(cons (car xs) (take (cdr xs) (- n 1)))) | |
) | |
) | |
(define (join first remaining) | |
) | |
;; (equal? (wrap "" 70) "") | |
;; (equal? (wrap "socrates" 20) "socrates") | |
;; (equal? (wrap "Looong" 5) "Looon\ng") | |
(define (wrap text limit) | |
(let ( | |
(chars (string->list text)) | |
) | |
(cond | |
( | |
(> (length chars) limit) | |
(let | |
((splitresult (split chars limit))) | |
;; splitresult[0] + \n + splitresult[1] | |
(list->string (car splitresult)) | |
) | |
) | |
;;(> (length chars) limit) (cons (take chars limit)) | |
(else text) | |
) | |
) | |
) | |
(define lll (list 1 2 3 4 5 6)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment