Long literals, with continuations: Difference between revisions

m
→‎{{header|Wren}}: Changed to use a 'raw' string.
No edit summary
m (→‎{{header|Wren}}: Changed to use a 'raw' string.)
 
(23 intermediate revisions by 7 users not shown)
Line 70:
{{Template:Strings}}
<br><br>
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V revdate = ‘2021-11-14’
 
V elements =
‘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 berkelium ’""
‘californium einsteinium fermium mendelevium nobelium lawrencium ’""
‘rutherfordium dubnium seaborgium bohrium hassium meitnerium darmstadtium ’""
‘roentgenium copernicium nihonium flerovium moscovium livermorium ’""
‘tennessine oganesson’
 
V items = elements.split(‘ ’)
 
print(‘Last revision date: ’revdate)
print(‘Number of elements: ’items.len)
print(‘Last element : ’items.last)</syntaxhighlight>
 
{{out}}
<pre>
Last revision date: 2021-11-14
Number of elements: 118
Last element : oganesson
</pre>
 
=={{header|6502 Assembly}}==
There is no need for continuation codes, as the language interprets a contiguous data block as a single entity, whether you intended it to be or not. If you had two consecutive strings embedded in the code and you forgot the null terminator on the first one, trying to print just the first string would print both. For example:
 
<langsyntaxhighlight lang="6502asm">HelloString:
db "Hello World" ;no null terminator
GoodbyeString:
db "Goodbye World!",0
 
PrintString HelloString ;unimplemented macro.</langsyntaxhighlight>
The output would be as follows, assuming the <code>PrintString</code> routine uses a null terminator to know when a string ends:
<pre>
Hello WorldGoodbye World!
</pre>
 
In addition, it makes no difference to the assembler whether each string is on its own line, or each is one after the other on the same line. It's easier to put each on its own line since you can't have a label mid-line.
 
Since each string is of variable length, it is much easier to make a lookup table of the elements ordered by atomic number, with each element in the lookup table being a pointer to the actual string consisting of that element's name.
 
<langsyntaxhighlight lang="6502asm">ElementsElementNull:
dw nullString
dw nullString,hydrogen,helium,lithium,beryllium,boron,carbon,nitrogen,oxygen,fluorine
 
Elements:
; this is typed in a compact manner to save on typing, however putting each on its own line with a
; "dw" directive in front will produce the same result. A comment with the element number on each line will aid in
; adding new elements to the list.
dw hydrogen,helium,lithium,beryllium,boron,carbon,nitrogen,oxygen,fluorine
dw neon,sodium,magnesium,aluminum,silicon,phosphorous,sulfur,chlorine,argon
dw potassium,calcium,scandium,titanium,vanadium,chromium,manganese,iron
Line 105 ⟶ 149:
Elements_End:
 
nullString:
NullString
db 0
hydrogen:
db "hydrogen ",0
helium:
db "helium ",0
lithium:
db "lithium ",0
;etc.
 
RevisionDate:
db "2021-09Sep-2020th",0
 
Finally:
db "elements, the last is ",0
ElementCount equ (Elements_End-Elements)/2 ;a constant value that cannot change at runtime.</lang>
; a constant value that cannot change at runtime.
; This counts the number of bytes between the two labels, and automatically adjusts when the size of the list changes.
; The division by 2 gets the actual element count since each address is 2 bytes long.</syntaxhighlight>
 
The required output can be obtained like so:
<langsyntaxhighlight lang="6502asm">LDA #<RevisionDate ;get the low byte of the address
STA z_L ;store it in z_L, a zero page memory address
LDA #>RevisionDate ;get the high byte
Line 144 ⟶ 191:
JSR PrintString
 
LDA #$20 ;ASCII for spacebar
JSR PrintChar
 
LDA ElementCount
Line 149 ⟶ 198:
TAX ;use as an offset into the lookup table.
 
LDA ElementNull,x ;ElementCount doesn't account for zero-indexing so we'll need to load one word behind.
LDA Elements,x
STA z_L
LDA ElementsElementNull+1,x
STA z_H
JSR PrintString</langsyntaxhighlight>
 
This routine can be expanded as new elements are discovered, but once the 128th element is discovered it will need to be reprogrammed since you can't offset more than x=255. This is actually a very simple fix, and can be accomplished by splitting the table as such:
<syntaxhighlight lang="6502asm">Elements_Lo:
db <hydrogen,<helium,<lithium,<beryllium,<boron,<carbon,<nitrogen,<oxygen,<fluorine,...
Elements_Hi:
db >hydrogen,>helium,>lithium,>beryllium,>boron,>carbon,>nitrogen,>oxygen,>fluorine,...</syntaxhighlight>
 
Note that < and > are unary operators that mean "the low byte of" and "the high byte of", respectively. By storing the halves of each pointer in two separate tables, sharing a common index, we can index up to 256 elements rather than 128, without increasing the total data size of the tables.
 
{{out}}
<pre>
2021-09Sep-2020th
118 elements, the last is oganesson
</pre>
 
=={{header|68000 Assembly}}==
{{trans|6502 Assembly}}
There is no need for continuation codes, as the language interprets a contiguous data block as a single entity, whether you intended it to be or not. If you had two consecutive strings embedded in the code and you forgot the null terminator on the first one, trying to print just the first string would print both. For example:
 
<syntaxhighlight lang="68000devpac">HelloString:
DC.B "Hello World" ;no null terminator
GoodbyeString:
DC.B "Goodbye World!",0
EVEN
 
PrintString HelloString ;unimplemented macro.</syntaxhighlight>
The output would be as follows, assuming the <code>PrintString</code> routine uses a null terminator to know when a string ends:
<pre>
Hello WorldGoodbye World!
</pre>
 
In addition, it makes no difference to the assembler whether each string is on its own line, or each is one after the other on the same line. It's easier to put each on its own line since you can't have a label mid-line.
 
Since each string is of variable length, it is much easier to make a lookup table of the elements ordered by atomic number, with each element in the lookup table being a pointer to the actual string consisting of that element's name.
 
<syntaxhighlight lang="68000devpac">NullElement:
DC.L nullString
Elements:
; this is typed in a compact manner to save on typing, however putting each on its own line with a
; "DC.L" directive in front will produce the same result. A comment with the element number on each line will aid in
; adding new elements to the list.
DC.L hydrogen,helium,lithium,beryllium,boron,carbon,nitrogen,oxygen,fluorine
DC.L neon,sodium,magnesium,aluminum,silicon,phosphorous,sulfur,chlorine,argon
DC.L potassium,calcium,scandium,titanium,vanadium,chromium,manganese,iron
DC.L cobalt,nickel,copper,zinc,gallium,germanium,arsenic,selenium,bromine
DC.L krypton,rubidium,strontium,yttrium,zirconium,niobium,molybdenum
DC.L technetium,ruthenium,rhodium,palladium,silver,cadmium,indium,tin
DC.L antimony,tellurium,iodine,xenon,cesium,barium,lanthanum,cerium
DC.L praseodymium,neodymium,promethium,samarium,europium,gadolinium,terbium
DC.L dysprosium,holmium,erbium,thulium,ytterbium,lutetium,hafnium,tantalum
DC.L tungsten,rhenium,osmium,iridium,platinum,gold,mercury,thallium,lead
DC.L bismuth,polonium,astatine,radon,francium,radium,actinium,thorium
DC.L protactinium,uranium,neptunium,plutonium,americium,curium,berkelium
DC.L californium,einsteinium,fermium,mendelevium,nobelium,lawrencium
DC.L rutherfordium,dubnium,seaborgium,bohrium,hassium,meitnerium,darmstadtium
DC.L roentgenium,copernicium,nihonium,flerovium,moscovium,livermorium
DC.L tennessine,oganesson
Elements_End:
 
nullString:
DC.B 0
EVEN
hydrogen:
DC.B "hydrogen",0
EVEN
helium:
DC.B "helium",0
EVEN
lithium:
DC.B "lithium",0
EVEN
;etc.
 
RevisionDate:
DC.B "2021-Sep-20th",0
EVEN
 
Finally:
DC.B "elements, the last is",0
EVEN
ElementCount equ (Elements_End-Elements)/4
; a constant value that cannot change at runtime.
; This counts the number of bytes between the two labels, and automatically adjusts when the size of the list changes.
; The division by 4 gets the actual element count since each address is 4 bytes long.</syntaxhighlight>
 
The required output can be obtained like so:
<syntaxhighlight lang="68000devpac">LEA RevisionDate,A3 ; the printing routine uses A3 as input
JSR PrintString ; unimplemented printing routine
JSR NewLine ; unimplemented new line routine
 
MOVE.B ElementCount,D0
JSR ConvertHex2BinDec ; converts a hexadecimal value to a trio of BCD digits
JSR PrintBCD ; unimplemented printing routine for numeric values
 
MOVE.B #' ',D0 ; ASCII for spacebar
JSR PrintChar
 
LEA Finally,A3
JSR PrintString
 
MOVE.B #' ',D0 ; ASCII for spacebar
JSR PrintChar
 
MOVE.W ElementCount,D1
LSL.W #2,D1 ; multiply by 4, we are indexing into a table of longs
 
LEA NullElement,A2
; load the base of the lookup table into A2. This is the table's "true base"
; since the "ElementCount" constant doesn't account for zero-indexing
 
MOVEA.L (A2,D1),A3
;dereference the pointer, offsetting by D1. This retrieves the address of the desired element in the list.
JSR PrintString</syntaxhighlight>
 
This routine can easily be expanded for more elements. With a maximum offset of 16,383, it's unlikely that the table will get too large to properly index anytime soon.
{{out}}
<pre>
2021-Sep-20th
118 elements, the last is oganesson
</pre>
 
=={{header|Arturo}}==
Line 170 ⟶ 328:
===Using concatenations===
 
<langsyntaxhighlight lang="rebol">revDate: "2021-02-05"
elementString:
Line 194 ⟶ 352:
print ["Last revision date:" revDate]
print ["Number of elements:" size elements]
print ["Last element in list:" last elements]</langsyntaxhighlight>
 
{{out}}
Line 204 ⟶ 362:
===Using string blocks===
 
<langsyntaxhighlight lang="rebol">revDate: "2021-02-05"
elementString: {
Line 229 ⟶ 387:
print ["Last revision date:" revDate]
print ["Number of elements:" size elements]
print ["Last element in list:" last elements]</langsyntaxhighlight>
 
{{out}}
Line 238 ⟶ 396:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f LONG_LITERALS_WITH_CONTINUATIONS.AWK
BEGIN {
Line 335 ⟶ 493:
revised = "30JUN2020"
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 348 ⟶ 506:
first & last 30 characters: hydrogen helium lithium beryll & ivermorium tennessine oganesson
</pre>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">
ultimaRevision$ = "2021-11-12"
arraybase 1
dim elemento$ = {"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", "berkelium", "californium", "einsteinium", "fermium", "mendelevium", "nobelium", "lawrencium", "rutherfordium", "dubnium", "seaborgium", "bohrium", "hassium", "meitnerium", "darmstadtium", "roentgenium", "copernicium", "nihonium", "flerovium", "moscovium", "livermorium", "tennessine", "oganesson"}
 
print "Last updated : "; ultimaRevision$
print "Number of elements : "; elemento$[?]
print "Last element : "; elemento$[elemento$[?]]
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <chrono>
#include <format>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>
 
const std::string ELEMENTS = R"(
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
berkelium californium einsteinium fermium
mendelevium nobelium lawrencium rutherfordium
dubnium seaborgium bohrium hassium
meitnerium darmstadtium roentgenium copernicium
nihonium flerovium moscovium livermorium
tennessine oganesson
)";
 
const std::string UNNAMED_ELEMENTS = R"(
ununennium unquadnilium triunhexium penthextrium
penthexpentium septhexunium octenntrium ennennbium
)";
 
std::vector<std::string> rawstring_to_vector(const std::string& text, const char& delimiter) {
std::regex regx("\\s+");
std::string delimit(1, delimiter);
std::string elements = std::regex_replace(text, regx, delimit);
elements = elements.substr(1, elements.size() - 2);
 
std::vector<std::string> result;
std::stringstream stream(elements);
std::string item;
while ( getline(stream, item, delimiter) ) {
result.push_back (item);
}
return result;
}
 
int main() {
std::vector<std::string> elements = rawstring_to_vector(ELEMENTS, ' ');
std::vector<std::string> unnamed = rawstring_to_vector(UNNAMED_ELEMENTS, ' ');
 
elements.erase(std::remove_if(elements.begin(), elements.end(),
[unnamed](std::string text){ return std::find(unnamed.begin(), unnamed.end(), text) != unnamed.end(); }),
elements.end());
 
const std::string zone = "Asia/Shanghai";
const std::chrono::zoned_time zoned_time { zone, std::chrono::system_clock::now() };
 
std::cout << "Last revision Date: " << std::format("{:%Y-%m-%d Time %H:%M}", zoned_time)
<< " " << zone << std::endl;
std::cout << "Number of elements: " << elements.size() << std::endl;
std::cout << "Last element : " << elements[elements.size() - 1] << std::endl;
}
</syntaxhighlight>
{{ out }}
<pre>
Last revision Date: 2023-08-04 Time 00:18 Asia/Shanghai
Number of elements: 118
Last element : oganesson
</pre>
 
=={{header|Crystal}}==
Crystal's <code>%w</code> literals create a whitespace-delimited array of strings at compile time
<langsyntaxhighlight lang="ruby">require "time"
 
last_revision = Time.utc year: 2021, month: 2, day: 25
Line 391 ⟶ 653:
puts last_revision.to_s "last revised %B %e, %Y"
puts "number of elements: #{element_list.size}"
puts "highest element: #{element_list.last}"</langsyntaxhighlight>
 
=={{header|Delphi}}==
Line 397 ⟶ 659:
{{libheader| System.StrUtils}}
{{Trans|Free Pascal}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Long_literals_with_continuations;
 
Line 436 ⟶ 698:
writeln(words[high(words)]);
readln;
end.</langsyntaxhighlight>
{{out}}
<pre>Last update: 2020-11-11
Line 449 ⟶ 711:
The convention in Factor is to limit lines to 64 characters wide if possible. This constraint is sometimes waived for large literals, but it was easy enough to accommodate here.
{{works with|Factor|0.99 2020-03-02}}
<langsyntaxhighlight lang="factor">USING: formatting kernel qw sequences ;
 
qw{
Line 488 ⟶ 750:
"Last revision: %s\n" printf
[ length ] [ last ] bi
"Number of elements: %d\nLast element: %s\n" printf</langsyntaxhighlight>
{{out}}
<pre>
Line 500 ⟶ 762:
ANSI strings are pointers to sequences of characters.
The data type includes a reference count and a (4-Byte long) <tt>length</tt> field.
<langsyntaxhighlight lang="pascal">
program longStringLiteralDemo(output);
 
Line 539 ⟶ 801:
elementString, stdWordDelims));
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 546 ⟶ 808:
oganesson
</pre>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
Dim As String ultimaRevision = "2021-11-12"
Dim As String elemento(0 to ...) => { _
"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", "berkelium", _
"californium", "einsteinium", "fermium", "mendelevium", "nobelium", _
"lawrencium", "rutherfordium", "dubnium", "seaborgium", "bohrium", "hassium", _
"meitnerium", "darmstadtium", "roentgenium", "copernicium", "nihonium", _
"flerovium", "moscovium", "livermorium", "tennessine", "oganesson"}
 
Print "Last updated : "; ultimaRevision
Print "Number of elements : "; Ubound(elemento) - Lbound(elemento) + 1
Print "Last element : "; elemento(Ubound(elemento))
Sleep
</syntaxhighlight>
{{out}}
<pre>
Last updated : 2021-11-12
Number of elements : 118
Last element : oganesson
</pre>
 
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 606 ⟶ 906:
lix := strings.LastIndex(elements2, " ") // get index of last space
fmt.Println("Last element : ", elements2[lix+1:])
}</langsyntaxhighlight>
 
{{out}}
Line 614 ⟶ 914:
Last element : oganesson
</pre>
 
=={{header|Haskell}}==
 
<syntaxhighlight lang="haskell">elements = words "hydrogen \
\ 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 \
\ berkelium californium einsteinium fermium \
\ mendelevium nobelium lawrencium rutherfordium \
\ dubnium seaborgium bohrium hassium \
\ meitnerium darmstadtium roentgenium copernicium \
\ nihonium flerovium moscovium livermorium \
\ tennessine oganesson"</syntaxhighlight>
 
<pre>*Main> length elements
111
 
*Main> take 5 elements
["hydrogen","fluorine","neon","sodium","magnesium"]
 
*Main> filter (('a' ==) . head) elements
["aluminum","argon","arsenic","antimony","astatine","actinium","americium"]</pre>
 
 
=={{header|J}}==
Line 672 ⟶ 1,014:
│hydrogen helium lithium beryll│vermorium tennessine oganesson│
└──────────────────────────────┴──────────────────────────────┘</pre>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
 
public final class LongLiteralsWithContinuations {
 
public static void main(String[] aArgs) {
ZoneId zoneID = ZoneId.of("Asia/Shanghai");
ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneID);
String dateTime = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss a"));
List<String> elements = splitToList(ELEMENTS).stream().
filter( s -> ! splitToList(UNNAMED_ELEMENTS).contains(s) ).toList();
System.out.println("Last revision Date: " + dateTime + " " + zoneID);
System.out.println("Number of elements: " + elements.size());
System.out.println("Last element : " + elements.get(elements.size() - 1));
}
private static List<String> splitToList(String aText) {
String excessWhiteSpaceRemoved = aText.trim().replaceAll("\\s+", " ");
return Arrays.stream(excessWhiteSpaceRemoved.split(" ")).toList();
}
private static final String ELEMENTS = """
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
berkelium californium einsteinium fermium
mendelevium nobelium lawrencium rutherfordium
dubnium seaborgium bohrium hassium
meitnerium darmstadtium roentgenium copernicium
nihonium flerovium moscovium livermorium
tennessine oganesson
""";
private static final String UNNAMED_ELEMENTS = """
ununennium unquadnilium triunhexium penthextrium
penthexpentium septhexunium octenntrium ennennbium
""";
}
</syntaxhighlight>
{{ out }}
<pre>
Last revision Date: 2023-08-03 19:19:48 pm Asia/Shanghai
Number of elements: 118
Last element : oganesson
</pre>
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq"># FOR FUTURE EDITORS:
# To add chemical elements, modify the CHEMICAL_ELEMENTS function,
# ensuring that the date is updated properly and that there is at least one
Line 715 ⟶ 1,132:
"Last element in list: \($a[-1])";
report</langsyntaxhighlight>
Invocation: jq -nrf program.jq
{{out}}
Line 726 ⟶ 1,143:
The task does not as of the current revision mention lower versus upper case, but the below is corrected per a request anyway.
The task does ask to comment on which column code may start. The start column for code does not matter to Julia, or to most modern computer language compilers, other than in some cases (not string data) Python.
<langsyntaxhighlight lang="julia">using Dates
 
# FOR FUTURE EDITORS:
Line 779 ⟶ 1,196:
 
report()
</langsyntaxhighlight> {{out}}
<pre>
File last revised (formatted as dateTtime): 2020-03-24T02:48:55.421 GMT
Line 789 ⟶ 1,206:
Kotlin has raw string literals with <code>"""</code>. It does not (yet) have a native date/time library, so we use Java’s here.
 
<langsyntaxhighlight lang="kotlin">import java.time.Instant
 
const val elementsChunk = """
Line 838 ⟶ 1,255:
println("Last element : ${elementsList.last()}")
println("The elements are : ${elementsList.joinToString(" ", limit = 5)}")
}</langsyntaxhighlight>
 
{{out}}
Line 850 ⟶ 1,267:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">revised = "February 2, 2021"
-- the long literal string is delimited by double square brackets: [[...]]
-- each word must be separated by at least one whitespace character
Line 899 ⟶ 1,316:
 
-- then, if still required, produce a single-space-between string version:
--finallist = table.concat(elements," ")</langsyntaxhighlight>
{{out}}
<pre>revised date: February 2, 2021
Line 908 ⟶ 1,325:
 
===Using concatenations===
<langsyntaxhighlight Nimlang="nim">import strutils
 
const RevDate = "2021-02-05"
Line 938 ⟶ 1,355:
echo "Last revision date: ", RevDate
echo "Number of elements: ", ElementList.len
echo "Last element in list: ", ElementList[^1]</langsyntaxhighlight>
 
{{out}}
Line 946 ⟶ 1,363:
 
===Using a long literal string===
<langsyntaxhighlight Nimlang="nim">import strutils
 
const RevDate = "2021-02-05"
Line 994 ⟶ 1,411:
echo "Last revision date: ", RevDate
echo "Number of elements: ", ElementList.len
echo "Last element in list: ", ElementList[^1]</langsyntaxhighlight>
 
{{out}}
Line 1,006 ⟶ 1,423:
=={{header|Perl}}==
Mostly pointless...
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Long_literals,_with_continuations
Line 1,036 ⟶ 1,453:
element count: $count
last element: $last
END</langsyntaxhighlight>
{{out}}
<pre>
Line 1,049 ⟶ 1,466:
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.
 
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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;">`
Line 1,090 ⟶ 1,507:
"""</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>
<!--</langsyntaxhighlight>-->
 
{{out}}
Line 1,100 ⟶ 1,517:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">elements$= "hydrogen helium lithium beryllium boron carbon " +
"nitrogen oxygen fluorine neon sodium magnesium " +
"aluminum silicon phosphorous sulfur chlorine argon " +
Line 1,128 ⟶ 1,545:
~"\nLast element: "+result$(nbf-1))
Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre>Last revision: 2020-11-11
Line 1,136 ⟶ 1,553:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">"""Long string literal. Requires Python 3.6+ for f-strings."""
 
revision = "October 13th 2020"
Line 1,174 ⟶ 1,591:
if __name__ == "__main__":
report()
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,185 ⟶ 1,602:
=={{header|Quackery}}==
 
<syntaxhighlight lang="quackery">
<lang Quackery>
[ stack ] is last-revision ( --> $ )
$ "6 Jun 2021" last-revision put
Line 1,239 ⟶ 1,656:
say "Number of elements: " elementcount echo cr
say "Last element: " finalelement echo$ cr
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,256 ⟶ 1,673:
Not really sure I understand the point of this task. Seems to be load some list into memory and manipulate it somehow. Exceptionally boring to just read it in and then read it back out again. Perform some more interesting manipulations. Use < > quoting construct for literal string; unlimited (memory limited) characters, spaces don't matter, new-lines don't matter, blank lines don't matter.
 
<syntaxhighlight lang="raku" perl6line>my %periodic;
%periodic<revision-date> = Date.new(2020,3,23);
%periodic<table> = |<
Line 1,330 ⟶ 1,747:
put 'Symbols for elements whose name starts with "P": ', %periodic<table>.grep( *.<name>.starts-with('P') )».<symbol>;
put "Elements with molecular weight between 20 & 40:\n ",%periodic<table>.grep( {+.<weight> ~~ Numeric and 20 < .<weight> < 40} )».<name>;
put "SCRN: ", %periodic<table>[87,17,92]».<symbol>.join.tclc;</langsyntaxhighlight>
{{out}}
<pre>Revision date: 2020-03-23
Line 1,351 ⟶ 1,768:
 
Most modern REXXes have no practical limit for a clause length.
<langsyntaxhighlight lang="rexx">/*REXX pgm illustrates how to code a list of words (named chemical elements */
/*──────────────────────── ordered by their atomic number) in a list format. */
 
Line 1,382 ⟶ 1,799:
#= words(elements) /*the number of elements " " " */
say 'number of elements in the list: ' # /*show " " " " " " */
say 'the last element is: ' word($, #) /*stick a fork in it, we're all done*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,400 ⟶ 1,817:
 
The REXX version uses concatenation (also called abutment) to build the list.
<langsyntaxhighlight lang="rexx">/*REXX pgm illustrates how to code a list of words (named chemical elements */
/*──────────────────────── ordered by their atomic number) in a list format. */
 
Line 1,431 ⟶ 1,848:
#= words(elements) /*the number of elements " " " */
say 'number of elements in the list: ' # /*show " " " " " " */
say 'the last element is: ' word($, #) /*stick a fork in it, we're all done*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,437 ⟶ 1,854:
number of elements in the list: 118
the last element is: oganesson
</pre>
 
=={{header|RPL}}==
≪ { "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" "berkelium" "californium" "einsteinium" "fermium" "mendelevium" "nobelium" "lawrencium" "rutherfordium" "dubnium" "seaborgium" "bohrium" "hassium" "meitnerium" "darmstadtium" "roentgenium" "copernicium" "nihonium" "flerovium" "moscovium" "livermorium" "tennessine" "oganesson" } "23/02/05" → elements updated
≪ "Updated: " updated +
"# items: " elements SIZE →STR +
"Last : " elements DUP SIZE GET +
≫ ≫ 'ELMTS' STO
 
ELMTS
{{out}}
<pre>
3: "Updated: 23/02/05"
2: "# items: 118"
1: "Last : oganesson"
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">elements = %w(
hydrogen helium lithium beryllium
boron carbon nitrogen oxygen
Line 1,475 ⟶ 1,907:
number of elements: #{elements.size}
last element: #{elements.last}"
</syntaxhighlight>
</lang>
{{out}}
<pre>Last mutation 2021-08-30 17:14:16 +0200
Line 1,483 ⟶ 1,915:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">(* space in \ .. \ is ignored *)
 
val elements = "\
Line 1,507 ⟶ 1,939:
\last element:\t" ^ List.last lst ^ "\n")
 
val () = report (String.fields (fn c => c = #" ") elements)</langsyntaxhighlight>
{{out}}
<pre>revision date: 2021-02-25
Line 1,515 ⟶ 1,947:
=={{header|Tcl}}==
Using the neatly formatted table from other languages (can be reformatted easily using the non-standard utility column with option -t).
<langsyntaxhighlight lang="tcl">set mtime "2021-05-10 16:11:50"
set elements {
hydrogen helium lithium beryllium
Line 1,552 ⟶ 1,984:
puts "Last modification time: $mtime"
puts "Number of elements: [llength $elements]"
puts "Last element: [lindex $elements end]"</langsyntaxhighlight>
{{out}}
<pre>Last modification time: 2021-05-10 16:11:50
Line 1,567 ⟶ 1,999:
are sufficient to extend it across as many lines as needed:
 
<syntaxhighlight lang="sh">
<lang sh>
main() {
elements=(
Line 1,597 ⟶ 2,029:
printf 'Latest element: %s\n' "${elements[-1]}"
}
main "$@"</langsyntaxhighlight>
 
{{Out}}
Line 1,604 ⟶ 2,036:
=={{header|Wren}}==
{{libheader|Wren-pattern}}
We use a 'raw' string for this task.
Wren doesn't have raw strings nor continuations and so we concatenate rows of strings instead.
<syntaxhighlight lang="wren">import "./pattern" for Pattern
 
The rows can begin in any column though, for a tidy display, we begin them all here in column 5.
<lang ecmascript>import "/pattern" for Pattern
 
var elementStr =
"""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 " +
"berkelium californium einsteinium fermium mendelevium nobelium " +
"lawrencium rutherfordium dubnium seaborgium bohrium hassium " +
"meitnerium darmstadtium roentgenium copernicium nihonium flerovium " +
"moscovium livermorium tennessine oganesson"""
 
var p = Pattern.new("+1/s") // matches 1 or more whitespace characters
var elements = p.splitAll(elementStr) // get a list of elements
elementStr = elements.join(" ") // recombine using a single space as separator
var lastUpdate = "20202023-0812-0317"
System.print("Last updated : %(lastUpdate)")
System.print("Number of elements : %(elements.count)")
System.print("Last element : %(elements[-1])")</langsyntaxhighlight>
 
{{out}}
<pre>
Last updated : 20202023-0812-0317
Number of elements : 118
Last element : oganesson
Line 1,654 ⟶ 2,084:
(by default). To turn that into one string with one space between each item,
use: elements.concat(" ")
<langsyntaxhighlight lang="zkl">revisionDate:="2020-03-23";
elements:=
#<<<"
Line 1,680 ⟶ 2,110:
#<<<
println("Revision date: ",revisionDate);
println(elements.len()," elements, the last being \"",elements[-1],"\"");</langsyntaxhighlight>
{{out}}
<pre>
9,485

edits