Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do a line break (line continuation) in Elixir?

Tags:

syntax

elixir

In Python, for example, one can break line with '\' character (yeah, necessary evil). Is it possible to break lines in Elixir?

like image 590
avli Avatar asked Mar 13 '15 10:03

avli


People also ask

What is a line continuation?

Sentences, entries, phrases, and clauses that continue in Area B of subsequent lines are called continuation lines. A hyphen in a line's indicator area causes the first nonblank character in Area B to be the immediate successor of the last nonblank character of the preceding line.

How do you add a line break in string?

Inserting a newline code \n , \r\n into a string will result in a line break at that location. On Unix, including Mac, \n (LF) is often used, and on Windows, \r\n (CR + LF) is often used as a newline code.

How do you break a code line?

The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.

How can I do a line break line continuation in Python?

You cannot split a statement into multiple lines in Python by pressing Enter . Instead, use the backslash ( \ ) to indicate that a statement is continued on the next line. In the revised version of the script, a blank space and an underscore indicate that the statement that was started on line 1 is continued on line 2.


2 Answers

Elixir is not as whitespace-sensitive as Python, so you can do things like:

a =
  2 + 4 +
 3
# a is bound to 9

If you want to break strings, probably your best shot is to concatenate one string per line:

"this is a very long string that " <>
  "spans multiple lines because man, " <>
  "is it long"
like image 158
whatyouhide Avatar answered Oct 04 '22 21:10

whatyouhide


Based on Jose Valim comment.

iex(1)> "hello\
...(1)> world"
"helloworld"
iex(2)> 
like image 27
2 revs Avatar answered Oct 04 '22 20:10

2 revs