Long literals, with continuations: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) (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 |
|||
hydrogen helium lithium beryllium |
|||
boron carbon nitrogen oxygen |
|||
fluorine neon sodium magnesium |
|||
aluminum silicon phosphorous sulfur |
|||
chlorine argon potassium calcium |
|||
scandium titanium vanadium chromium |
|||
manganese iron cobalt nickel |
|||
copper zinc gallium germanium |
|||
arsenic selenium bromine krypton |
|||
rubidium strontium yttrium zirconium |
|||
niobium molybdenum technetium ruthenium |
|||
rhodium palladium silver cadmium |
|||
indium tin antimony tellurium |
|||
iodine xenon cesium barium |
|||
lanthanum cerium praseodymium neodymium |
|||
promethium samarium europium gadolinium |
|||
terbium dysprosium holmium erbium |
|||
thulium ytterbium lutetium hafnium |
|||
tantalum tungsten rhenium osmium |
|||
iridium platinum gold mercury |
|||
thallium lead bismuth polonium |
|||
astatine radon francium radium |
|||
actinium thorium protactinium uranium |
|||
⚫ | |||
neptunium plutonium americium curium |
|||
⚫ | |||
⚫ | |||
dubnium seaborgium bohrium hassium |
|||
⚫ | |||
⚫ | |||
dubnium seaborgium bohrium hassium |
|||
⚫ | |||
⚫ | |||
nihonium flerovium moscovium livermorium |
|||
`, |
|||
⚫ | |||
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> |
|||
⚫ | |||
<span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""" |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
""" |
|||
⚫ | |||
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> |