< Back to IRCAM Forum

How to convert String to integer / float in OpenMusic

Dear Community,
I need a little bit of help.
I’m frustrating I can not find the right Function.
I have to read a .txt File into my OpenMusic Patch to take some calculations.
But it seams that the File reader from:
takes the line as a String.
And I need a float or a integer.
But I can not found any Functions for Conversion.

Can anybody help me a little bit

Dear Creco,

Since you didn’t specify in which context you need oto do this, here is the most general way to convert strings into integer/floats. However if in your string there is a non integer/float it still works…



But I have;
(“123” “234” “345”)
and I need
(123 234 345 )
In which way I can have the first translate to the Second

I have found a Solution.
But I think is a little bit complicated.
I have interrupted the Connection between the Line-Reader (“file-read-line”) and the Collector.
Then I have set a Funcall object and a String Object [parse-float].
So it works.
But is there any better Idea.

Ok now here it is:

this is now clear,
a big thanks.

I’m a bit late… but here’s another way.

best regards,

! correct !
string-to-number a custom OM function!
however, will not work with characters like “toto”

Great, thx rc



Another alternative would be to use the LISP function read-from-string, for any given string its first output is the desired element (e.g., from “c4” or “flow” read-from-string ouputs [c4 2] and [flow 4], respectively.)

All the best,


I’ve attached a LISP file with two alternative ways of doing it, which may be useful in different contexts:

  1. The first one is called string-to-atom, and transforms a string as follows: “string-content” --> string-content;
  2. The second one is string-to-list, and transforms a string as follows: “string-content” --> (string-content).

The code:

(defmethod string-to-atom ((box string))
	 (car (list (read-from-string box))))

(defmethod string-to-atom ((box list))
	 (loop for item in box
         collect (string-to-atom item)))

(defmethod string-to-list ((box string))
	 (list (read-from-string box)))

(defmethod string-to-list ((box list))
	 (loop for item in box
         collect (string-to-list item)))

The file, which you can put in your workspace’s “user” sub-folder: string-utils.lisp (445 Bytes)

Hope this helps.

All the best,

1 Like