Group Admins

  • Profile picture of Karim
  • Profile picture of Jean

OpenMusic

Public Group active 6 hours, 5 minutes ago

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

Separate integers or letters

Author 2 Subscribed Users |
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

August 10, 2018 at 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

August 10, 2018 at 15:08 #27426

You must be logged in to reply to this topic.

Log in now