;;;; string-utils.scm -*- Hen -*- ;;;; Kon Lovett, Aug '10 (module string-utils (;export make-string*) (import scheme chicken (only data-structures alist-ref alist-update!) lookup-table miscmacros (only type-checks check-integer check-char)) (require-library data-structures miscmacros lookup-table type-checks) (declare (bound-to-procedure ##sys#make-string)) ;; Memeoized `make-string' (define make-string* (let ((+strings+ (make-dict eqv?))) (lambda (len #!optional (ch #\space)) (if* (dict-ref +strings+ ch) (or (dict-ref it len) (let ((str (##sys#make-string len ch))) (dict-set! it len str) ; dict `it' already member of +strings+ str ) ) (begin (dict-update-dict! +strings+ ch) (make-string* len ch) ) ) ) ) ) ) ;module string-utils