Nested templated data: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 36:
 
''Show output on this page.''
 
=={{header|Bracmat}}==
The uninstantiated template and the instantiated template are JSON structures. The payloads are listed in a Bracmat list. The <code>get</code> function is instructed to read input from memory and to parse it as JSON. The output of this call is a Bracmat structure (not shown) that is assigned to <code>template</code>. The <code>instantiate</code> function recursively traverses the template's tree structure. If the current node is a number, then that number is used as the key into the payloads list. The corresponding payload is then returned. If the current node is not a number, then it is assumed that the current node is a binary (sub)tree. The left hand side (called <code>a</code>) and the right hand side (called <code>b</code>) are instantiated and their combination is returned. Finally the instantiated tree is transformed back to JSON format and output.
Line 181 ⟶ 182:
The unused payloads have indices of : [0 6]
</pre>
 
 
=={{header|Julia}}==
Line 434:
<pre>[ [ "Payload#1", "Payload#2" ], [ "Payload#3", "Payload#4", "Payload#1" ], "Payload#5" ]
[ [ "Payload#1", "Payload#2" ], [ "", "Payload#4", "Payload#1" ], "Payload#5" ]</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.04.01}}
Explicitly not using strings, using one data structure to fill in another. Since it ''isn't'' a string, the output format removes the newlines from the template; line feed (white space in general) isn't particularly significant in Perl 6 data structures. It does preserve the nesting though. In the second example, payload "buckets" that don't exist result in an undefined value being inserted; by default: Any.
<lang perl6>say join "\n ", '##PAYLOADS:', |my @payloads = 'Payload#' X~ ^7;
 
for [
(((1, 2),
(3, 4, 1),
5),),
 
(((1, 2),
(10, 4, 1),
5),)
] {
say "\n Template: ", $_.perl;
say "Data structure: { @payloads[|$_].perl }";
}</lang>
{{out}}
<pre>##PAYLOADS:
Payload#0
Payload#1
Payload#2
Payload#3
Payload#4
Payload#5
Payload#6
 
Template: $(((1, 2), (3, 4, 1), 5),)
Data structure: ((("Payload#1", "Payload#2"), ("Payload#3", "Payload#4", "Payload#1"), "Payload#5"),)
 
Template: $(((1, 2), (10, 4, 1), 5),)
Data structure: ((("Payload#1", "Payload#2"), (Any, "Payload#4", "Payload#1"), "Payload#5"),)</pre>
 
=={{header|Phix}}==
Line 656 ⟶ 623:
(parameterize ((current-not-found-handler (λ (idx max) (format "?~a" idx))))
(check-equal? (out-of-bounds-generating-template-substitution p) '("?7"))))</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.04.01}}
Explicitly not using strings, using one data structure to fill in another. Since it ''isn't'' a string, the output format removes the newlines from the template; line feed (white space in general) isn't particularly significant in Perl 6 data structures. It does preserve the nesting though. In the second example, payload "buckets" that don't exist result in an undefined value being inserted; by default: Any.
<lang perl6>say join "\n ", '##PAYLOADS:', |my @payloads = 'Payload#' X~ ^7;
 
for [
(((1, 2),
(3, 4, 1),
5),),
 
(((1, 2),
(10, 4, 1),
5),)
] {
say "\n Template: ", $_.perl;
say "Data structure: { @payloads[|$_].perl }";
}</lang>
{{out}}
<pre>##PAYLOADS:
Payload#0
Payload#1
Payload#2
Payload#3
Payload#4
Payload#5
Payload#6
 
Template: $(((1, 2), (3, 4, 1), 5),)
Data structure: ((("Payload#1", "Payload#2"), ("Payload#3", "Payload#4", "Payload#1"), "Payload#5"),)
 
Template: $(((1, 2), (10, 4, 1), 5),)
Data structure: ((("Payload#1", "Payload#2"), (Any, "Payload#4", "Payload#1"), "Payload#5"),)</pre>
 
=={{header|REXX}}==
Line 942 ⟶ 943:
Payload#0 is not used
Payload#6 is not used</pre>
 
=={{header|zkl}}==
Formatting is lost as zkl is format free. A pretty printer could be written but
10,333

edits