I am trying to do a simple task of appending a number to a string multiple times, and hoping that this will build a string.
But it is not working, each call to (string-append ....) seems to do nothing at all.
Here is my code:
(define myString "")
(string-append (number->string 4) myString)
(string-append (number->string 5) myString)
(string-append (number->string 6) myString)
(string-append (number->string 7) myString)
(display myString)
this displays:
“4”
“5”
“6”
“7”
and a blank line for (display myString)
What am I doing wrong?
also if I do it the other way like so it doesn’t work either:
(define myString "")
(string-append myString (number->string 4))
(string-append myString (number->string 5))
(string-append myString (number->string 6))
(string-append myString (number->string 7))
(display myString)
Thanks for any help
string-appenddoes not alter an existing string; it returns a new string that is the result of the operation.If this seems unusual, consider the addition operator,
+. When I write3+4I’m not changing
3into7, just returning the result of the operation.So, in your case, if you write
You should see
To advise you further, it might help to know where you’re heading with this.