Newline in Scheme (Racket)

racket, scheme, string

Solution

If you need a way to add a newline between strings, then this will work:

(define s (string-append "exa " "\n" " mple"))
s
=> "exa \n mple"

(display s)
=> exa
    mple

In the above snippet, I'm using `string-append` for sticking together two strings with a newline in the middle. The resulting string `s` will have a newline in-between when you use it, for example by displaying it.

Obviously it will show up as `"exa \n mple"`, you can't expect the string to jump from one line to the other unless you display it, print it, show it, write it, etc.

Problem

It is possible to have a new line when you write with "display" like ``` (display "exa \n mple") ``` But the problem is that there is no any code to have a new line in strings? Like: ``` "exa \n mple" ``` Expected -> ``` exa mple ``` What I have: ``` exa \n mple ``` I couldn't find any information in racket-documentation or anywhere else.

Original source