Skip to content

Commit

Permalink
Issue #205 - Redefine string-fill! as a function
Browse files Browse the repository at this point in the history
  • Loading branch information
justinethier committed Mar 2, 2016
1 parent e46857c commit 92504c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ New Features:
Bug Fixes:

- Fixed `rational?` to properly handle floating-point numbers.
- Migrated `string-fill!` from a macro to a function. This makes it easier to redefine, for example per SRFI 13.

v3.19.1
--------
Expand Down
16 changes: 11 additions & 5 deletions lib/core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,17 @@
; End delayed evaluation section

; String Section
(define-syntax string-fill!
(syntax-rules ()
((_ _str _chr)
(set! _str
(make-string (string-length _str) _chr)))))
(define (string-fill! str fill . opts)
(letrec* ((len (string-length str))
(start (if (> (length opts) 0) (car opts) 0))
(end (if (> (length opts) 1) (cadr opts) len))
(loop (lambda (i)
(cond
((= i end) str)
(else
(string-set! str i fill)
(loop (+ i 1)))))))
(loop start)))

(define (string-concatenate l)
(apply string-append l))
Expand Down

0 comments on commit 92504c3

Please sign in to comment.