Converting numbers to strings and strings to lists

A couple of simple but useful functions.
Hopefully this will save someone several hours of scouring Google.

To test the code, copy and paste it into the Nyquist Prompt effect and press the DEBUG button to see the output.
[cc lang=”lisp”]
; function to convert a number to a string
(defun number-to-string (number)
(format nil “~a” number))

; function to convert a string into a list
(defun string-to-list (string)
(read (make-string-input-stream (format nil “(~a)” string))))

; TEST THE FUNCTIONS:
; first make a string
(setq mystring (strcat “1 2 3 ” (number-to-string 4)))

; then turn it into a list
(setq mylist (string-to-list mystring))

; then print it out in the debug window
(dotimes (i (length mylist))
(print (nth i mylist)))

(format nil “I hope you clicked the Debug button…\n\n :=)”)
[/cc]

Audacity Forum • View topic – Converting numbers to strings and strings to lists.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.