< Back to IRCAM Forum

Separate integers or letters

Hi,

I would like to know if there’s a lisp native function that would separate individual integers or letters respectively from numbers or words. For instance, if I have the word ‘word’, I want to obtain a list of individual letters such as in ‘(w o r d)’ ; same thing with numbers such as in: ‘156’ => ‘(1 5 6)’.

Many thanks for any help!
Jimmie

I think you can just use MAP:
http://clhs.lisp.se/Body/f_map.htm

(map 'list 'identity “abcd”) => (#\a #\b #\c #\d)
(map 'list 'string “abcd”) => (“a” “b” “c” “d”)

for a number you will first need to convert the number into a string:
(map ‘list #’(lambda (x) (read-from-string (string x))) (write-to-string 1234)) => (1 2 3 4)

Jean