10

Common-lisp でテキスト文字列の文字をループするにはどうすればよいですか?

これが私がやりたいことですが、Rubyでは:

string = "bacon"

string.each_char do |c|

    putc c

end
4

2 に答える 2

3

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")
于 2013-08-05T19:20:03.937 に答える