Administrateur

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Groupe Public active 1 day et 14 hours ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

Separate integers or letters

Auteur 2 Utilisateurs souscrits |
Profile photo of Jimmie
Jimmie

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

Août 10, 2018 à 13:59 #27424
Profile photo of Jean
Jean

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

Août 10, 2018 à 15:08 #27426

Vous devez être connecté pour répondre à ce sujet.

Log in now