Created
August 7, 2018 14:26
-
-
Save kuuote/7f6a4b4c742b12a0eebe34acc82f5698 to your computer and use it in GitHub Desktop.
言語処理100本ノックの円周率のやつ
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 (split str delim) | |
(define (skip-delimiter s) | |
(if (and (pair? s) (memv (car s) delim)) | |
(skip-delimiter (cdr s)) | |
s)) | |
;string -> token remainder | |
(define (get-token s acc) | |
(if (or (null? s) (memv (car s) delim)) | |
(values (reverse acc) s) | |
(get-token (cdr s) (cons (car s) acc)))) | |
(define (collect-token s acc) | |
(let ((skipped (skip-delimiter s))) | |
(if (pair? skipped) | |
(receive (token rem) (get-token skipped '()) | |
(collect-token rem (cons token acc))) | |
(reverse acc)))) | |
(map list->string (collect-token (string->list str) '()))) | |
(define (main args) | |
(print (map string-length (split "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics." '(#\space #\, #\.))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment