Skip to content

Instantly share code, notes, and snippets.

@twinkfrag
Created February 15, 2014 15:40
Show Gist options
  • Save twinkfrag/9020981 to your computer and use it in GitHub Desktop.
Save twinkfrag/9020981 to your computer and use it in GitHub Desktop.
Scheme練習 : string-split
(define
(string-split string splitter)
(let loop
(
(ls (string->list string))
(is-splitting #t)
(ret-ls '())
)
(if (null? ls)
(map (lambda(x) (list->string (reverse x))) (reverse ret-ls)) ; last return
(let
(
(c (car ls))
)
(loop
(cdr ls)
(char=? c splitter)
(if is-splitting
(cons (list c) ret-ls)
(cons (cons c (car ret-ls)) (cdr ret-ls))
)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment