Skip to content

Instantly share code, notes, and snippets.

@kuuote
Created August 7, 2018 14:26
Show Gist options
  • Save kuuote/7f6a4b4c742b12a0eebe34acc82f5698 to your computer and use it in GitHub Desktop.
Save kuuote/7f6a4b4c742b12a0eebe34acc82f5698 to your computer and use it in GitHub Desktop.
言語処理100本ノックの円周率のやつ
(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