1

I probably just used the wrong search phrases, but I didn't find it in the docs. I'd like to know if there is a way to divide long content into multiple lines in an Erlang module.

E.g. If I have to assign a long string literal in a C source file, I can split it over multiple lines by appending a "\" at the end of each line.

My current workaround for strings is to split the string into multiple strings and concatenate them with "++" like so:

string() -> "Some text ...." ++
"more text to be appended" ++
"even more text".

That works fine for strings, but it's not a general solution when lines get longer than I would like them to for some reason.

1
  • 1
    Can you show an example of a long line you can't split? Commented Jul 3, 2024 at 9:53

1 Answer 1

3

Although the use of ++ works in this case, it is not mandatory since adjacent strings will be concatenated:

string() -> "Some text ...."
"more text to be appended"
"even more text".

If you are using the latest erlang version (OTP27) and if you want new lines to translate as \n, you could use the newly introduced triple-quoted strings:

string() -> """
Some text ....
more text to be appended
even more text
""".
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.