On Wed, Jul 3, 2019 at 10:22 AM Marcus Sackrow <al...@web.de> wrote:

> I use an operator overload(not for constants but inside the code)
> because I'm used to our script engine have the '/' as operator for
> strings as line break.
>

That's certainly a neat use of operator overloading! However, I think that
it is still rather less clean/readable than what would be possible with
"true" unbroken multiline strings.
For really short stuff like your writeln example, also, it's not much
different from just doing the following, which is already supported:

writeln('1st line'#13#10'second line');

or

writeln('1st line'#10'second line');

BTW, doing it with an operator like that introduces quite a bit of
additional overhead, as the concatenation is no longer done at compile time.

Look at the assembler output here to get an idea.
<https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:pascal,source:'unit+output%3B%0A%0A%7B$mode+ObjFPC%7D%7B$H%2B%7D%0A%0Ainterface%0A%0Aoperator/(const+a,+b:+string):+string%3B+inline%3B%0Aprocedure+TestMultiLine%3B%0A%0Aimplementation%0A%0Aoperator/(const+a,+b:+string):+string%3B%0Abegin%0A++Result+:%3D+a+%2B+%2313%2310+%2B+b%3B%0Aend%3B%0A%0Aprocedure+TestMultiLine%3B%0Avar%0A++MultiLineString:+string%3B%0Abegin%0A++MultiLineString+:%3D%0A++++!'this!'/%0A++++!'is!'/%0A++++!'a!'/%0A++++!'multiline!'%3B%0A++//+or+even+shorter:%0A++MultiLineString+:%3D+!'this!'/!'is!'/!'a!'/!'multiline!'%3B%0Aend%3B%0A%0Aend.'),l:'5',n:'0',o:'Pascal+source+%231',t:'0')),k:41.17647058823529,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:fpc304,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'1',trim:'1'),lang:pascal,libs:!(),options:'-O3+-Ci-+-Cr-+-g-+-CX+-XXs',source:1),l:'5',n:'0',o:'x86-64+fpc+3.0.4+(Editor+%231,+Compiler+%231)+Pascal',t:'0')),k:58.82352941176471,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4>

After thinking about it more though I think Michael's backtick suggestion
might actually be the best way to go, because of the fact that backticks
currently have *no *meaning at all in Pascal, and as such, the compiler
could safely directly and immediately assume that any use of them was
specifically either the opening or closing of a multiline string.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to