Add string-split to common.scm
This commit is contained in:
parent
8afc823916
commit
828f123cd8
1 changed files with 22 additions and 0 deletions
22
common.scm
22
common.scm
|
|
@ -1,6 +1,28 @@
|
||||||
|
;; Shitty print for convenience
|
||||||
(define (print . args)
|
(define (print . args)
|
||||||
(display (apply string-append args))
|
(display (apply string-append args))
|
||||||
(newline))
|
(newline))
|
||||||
|
|
||||||
|
;; Chicken command-line-arguments for no reason at all
|
||||||
(define (command-line-arguments)
|
(define (command-line-arguments)
|
||||||
(cdr (command-line)))
|
(cdr (command-line)))
|
||||||
|
|
||||||
|
;; Guile string-split
|
||||||
|
(define (string-split str delim?)
|
||||||
|
(let ((in (open-input-string str)))
|
||||||
|
(let loop ((acc '())
|
||||||
|
(out (open-output-string)))
|
||||||
|
(let ((c (read-char in)))
|
||||||
|
(cond
|
||||||
|
((eof-object? c)
|
||||||
|
(reverse (cons (get-output-string out) acc)))
|
||||||
|
((delim? c)
|
||||||
|
(loop (cons (get-output-string out) acc)
|
||||||
|
(open-output-string)))
|
||||||
|
(else
|
||||||
|
(write-char c out)
|
||||||
|
(loop acc out)))))))
|
||||||
|
|
||||||
|
;; Reverse for-each, for convenience
|
||||||
|
(define (xfor-each1 lst fn)
|
||||||
|
(for-each fn lst))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue