Last active
December 12, 2015 10:39
-
-
Save ayato-p/4760414 to your computer and use it in GitHub Desktop.
named-letの練習。
空白文字はカウントしない。
This file contains hidden or 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 (str-count str) | |
(let loop ((ls (string->list str)) | |
(count 0)) | |
(let ((c (if (pair? ls) | |
(car ls) | |
ls)) | |
(inc (lambda (x) (+ x 1)))) | |
(cond | |
((null? ls) count) | |
((char-whitespace? c) (loop (cdr ls) count)) | |
(else | |
(loop (cdr ls) (inc count))))))) | |
;; Stringで受け取った数値文字列を数値のリストとして扱いたい | |
(define (string->int-list str) | |
(let loop ((char-list (string->list str)) | |
(acc '())) | |
(cond | |
((null? char-list) (reverse acc)) | |
(else (let ((c (car char-list)) | |
(c2i (lambda (x) (- x 48)))) | |
(loop (cdr char-list) | |
(cons (c2i (char->integer c)) acc))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment