Long literals, with continuations: Difference between revisions
m
→{{header|Phix}}: added syntax colouring the hard way, phix/basics
MaiconSoft (talk | contribs) (Added Delphi example) |
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
||
Line 900:
=={{header|Phix}}==
{{libheader|Phix/basics}}
Back-ticks and triple-quotes permit multi-line strings. We first replace all/any cr/lf/tab characters with spaces, then split (by default on a single space), omitting empty elements. You could use spaced_elements = join(elements) to join them back up into a space-separated single string, if that's really what you want, and you could then, like Go, use rfind(' ',spaced_elements) to re-extract the last one.
You could also, like Julia, use get_file_date(command_line()[2]) instead of the hand-written last_updated constant. Phix code is free-format, indent things however you like, there is no specific maximum line length.
<!--<lang Phix>-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">last_updated</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"March 24th, 2020"</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">elements_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
actinium thorium protactinium uranium
berkelium californium einsteinium fermium▼
neptunium plutonium americium curium
mendelevium nobelium lawrencium rutherfordium▼
▲ berkelium californium einsteinium fermium
▲ mendelevium nobelium lawrencium rutherfordium
meitnerium darmstadtium roentgenium copernicium▼
▲ meitnerium darmstadtium roentgenium copernicium
tennessine oganesson▼
nihonium flerovium moscovium livermorium
▲ tennessine oganesson
`</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">elements</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">elements_text</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n\r\t"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">),</span><span style="color: #000000;">no_empty</span><span style="color: #0000FF;">:=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">),</span>
Last revision: %s▼
<span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Number of elements: %d▼
▲ Last revision: %s
The last of which is: `%s`▼
▲ Number of elements: %d
▲ The last of which is: `%s`
"""</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">last_updated</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">elements</span><span style="color: #0000FF;">),</span><span style="color: #000000;">elements</span><span style="color: #0000FF;">[$]})</span>
<!--</lang>-->
{{out}}
<pre>
|