Common-lisp でテキスト文字列の文字をループするにはどうすればよいですか?
これが私がやりたいことですが、Rubyでは:
string = "bacon"
string.each_char do |c|
putc c
end
Common-lisp でテキスト文字列の文字をループするにはどうすればよいですか?
これが私がやりたいことですが、Rubyでは:
string = "bacon"
string.each_char do |c|
putc c
end
loop
文字列のループは、次のように使用して実行できます。
(let ((string "bacon"))
(loop for idex from 0 to (- (length string)) 1)
do
(princ (string (aref string idex)) ) ))
;=> bacon
;=> NIL
文字をstring
リストとしてまとめるcollect
には、代わりにループで使用しますdo
。
(let ((string "bacon"))
(loop for idex from 0 to (- (length string)) 1)
collect
(princ (string (aref string idex)) ) ))
;=> bacon
;=> ("b" "a" "c" "o" "n")