Long literals, with continuations: Difference between revisions

Content added Content deleted
(Added Delphi example)
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
Line 900: Line 900:


=={{header|Phix}}==
=={{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.
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.
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>constant last_updated = "March 24th, 2020",
<!--<lang Phix>-->
elements_text = `
<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>
hydrogen helium lithium beryllium
<span style="color: #000000;">elements_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
boron carbon nitrogen oxygen
fluorine neon sodium magnesium
hydrogen helium lithium beryllium
aluminum silicon phosphorous sulfur
boron carbon nitrogen oxygen
chlorine argon potassium calcium
fluorine neon sodium magnesium
scandium titanium vanadium chromium
aluminum silicon phosphorous sulfur
manganese iron cobalt nickel
chlorine argon potassium calcium
copper zinc gallium germanium
scandium titanium vanadium chromium
arsenic selenium bromine krypton
manganese iron cobalt nickel
rubidium strontium yttrium zirconium
copper zinc gallium germanium
niobium molybdenum technetium ruthenium
arsenic selenium bromine krypton
rhodium palladium silver cadmium
rubidium strontium yttrium zirconium
indium tin antimony tellurium
niobium molybdenum technetium ruthenium
iodine xenon cesium barium
rhodium palladium silver cadmium
lanthanum cerium praseodymium neodymium
indium tin antimony tellurium
promethium samarium europium gadolinium
iodine xenon cesium barium
terbium dysprosium holmium erbium
lanthanum cerium praseodymium neodymium
thulium ytterbium lutetium hafnium
promethium samarium europium gadolinium
tantalum tungsten rhenium osmium
terbium dysprosium holmium erbium
iridium platinum gold mercury
thulium ytterbium lutetium hafnium
thallium lead bismuth polonium
tantalum tungsten rhenium osmium
astatine radon francium radium
iridium platinum gold mercury
actinium thorium protactinium uranium
thallium lead bismuth polonium
neptunium plutonium americium curium
astatine radon francium radium
actinium thorium protactinium uranium
berkelium californium einsteinium fermium
neptunium plutonium americium curium
mendelevium nobelium lawrencium rutherfordium
berkelium californium einsteinium fermium
dubnium seaborgium bohrium hassium
mendelevium nobelium lawrencium rutherfordium
meitnerium darmstadtium roentgenium copernicium
nihonium flerovium moscovium livermorium
dubnium seaborgium bohrium hassium
meitnerium darmstadtium roentgenium copernicium
tennessine oganesson
nihonium flerovium moscovium livermorium
`,
tennessine oganesson
elements = split(substitute_all(elements_text,"\n\r\t"," "),no_empty:=true),
`</span><span style="color: #0000FF;">,</span>
fmt = """
<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`
printf(1,fmt,{last_updated,length(elements),elements[$]})</lang>
"""</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}}
{{out}}
<pre>
<pre>