logo       

Re: looping over characters in a string in elisp?: msg#00915

emacs.help

Subject: Re: looping over characters in a string in elisp?


>> (while char in string (do stuff) )

Kai> Why does it have to be a while loop? Why is a map-like look not
Kai> enough?

Kai> (mapcar (lambda (c) (char-to-string c)) "foobar")

Kai> This calls the lambda expression on each character and collects
Kai> the results in a list. You can throw the result away if you
Kai> don't like it...

I can remember the time(s) when I had forgotten enough about Emacs
Lisp that I wanted to ask this question. I always checked myself in
time and found the answer, but I think this is (a little bit of)
evidence that TFM needs a simple improvement.

Just put "STRINGS ARE ARRAYS" in big fat font at the beginning of the
Strings section (which precedes the Sequences Arrays Vectors section).

--
Ian Zimmerman, Oakland, California, U.S.A.
if (sizeof(signed) > sizeof(unsigned) + 4) { delete this; }
GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise