Re: Indentation and line breaks in string literals

Lex Spoon <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
>

The one thing I'd watch out for in the listings you give is that you  
*do* want to include *some* amount of initial whitespace on  
subsequent lines.  So there must be some way to mark the real  
beginning of the line, versus whitespace that should be ignored

Anyway, to round out your list some, the usual way in Scala is to use  
a multi-line string literal and then use a utility method to strip  
out the unwanted indentation.  The real beginnings of the lines are  
marked by |, and the stripMargin method removes everything up to and  
including that mark on each line.


    """|{
       |  foo
       |  bar
       |}""".stripMargin


The idea is that the | gives a visual cue where the beginning of the  
line is.  There is still noise on the first and last line, though,  
unfortunately.


Also, the C-ish version works fine in Scala and many other languages,  
if you are willing to add a + mark at the end of each line.  I also  
like to add parens around the whole thing, though they shouldn't be  
necessary in this case in Scala source code.  (They are necessary in  
the repl.)

   ("{\n"+
    "  foo\n"+
    "  bar\n"+
    "}")


-Lex

_______________________________________________
e-lang mailing list
[email protected]
http://www.eros-os.org/mailman/listinfo/e-lang
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.