文字のリストにするのには string->list が使える。
gosh> (string->list "abc") (#\a #\b #\c)
でも今日欲しいのは文字のリストじゃなくて、文字列(長さ1)のリストだ。例えば Ruby ではこう書ける。
2.1.1 :001 > "abc".split(//) => ["a", "b", "c"]
空(?)の正規表現で分割すると1文字ずつの配列になる。Ruby じゃ定番だね。
で、Scheme。string-split が正規表現も受け付けてくれるというので、上と同じように試したらダメだった。
gosh> (string-split "abc" #//)
*** ERROR: string-split: splitter must not match a null string: #//
Stack Trace:
_______________________________________
0 (error "string-split: splitter must not match a null string:" spli ...
At line 58 of "/usr/share/gauche-0.9/0.9.3.3/lib/gauche/stringutil.scm"
1 scanner
結局こういうのふうに書いてみたけど、なんかスマートじゃない。
gosh> (define string->string-list
(lambda (s)
(map (lambda (c) (list->string (list c))) (string->list s))))
string->string-list
gosh> (string->string-list "abc")
("a" "b" "c")
文字から長さ1の文字列へ変換する手続きが見当たらないんだよな。需要がないのかな。