What's a good Common Lisp function to convert a number into a string?
I wish to convert a number to string, as in: 42 -> "42"
Ultimately I want to concatenate a string and a set of numbers together into a set of symbols, like:
(loop for i upto 3
collect (concatenate 'string "foo" (some-conversion-function i)) into stngs
finally (return (mapcar #'read-from-strings stngs)))
-> foo0 foo1 foo2 foo3
All numbers are integers.
I've got everything working using (read-from-string (concatenate 'string …)) except that I'm missing a function that'll convert the number into a string or other sequence that'll concatenate into a string.
Alternatively, of course it'd be great if I could skip the strings altogether and just concatenate a symbol and a number into a symbol, as in: foo 0 -> foo0 …if someone could name a Common Lisp function that'd concatenate symbols directly.
(intern (format nil "~a~a" "FOO" 42) "WHAT-EVER-PACKAGE-YOU-WANT")
Grr, despite all my searching of Stack Overflow for various combinations of "lisp" "number" and "string" before I posted my question I didn't find write-to-string or similar until Stack Overflow decided to show me what's "Related" to my question. >|O
Anyway, write-to-strings works nicely for converting numbers to strings: converting number to string in lisp
But it'd still be better to concatenate symbols and numbers directly to symbols.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With