Nested templated data: Difference between revisions

Content added Content deleted
m (→‎{{header|zkl}}: having trouble today)
(added Factor)
Line 36: Line 36:


''Show output on this page.''
''Show output on this page.''

=={{header|Factor}}==
Words for traversing nested sequences can be found in the <code>sequences.deep</code> vocabulary. Factor's prettyprinter attempts to print structures on a single line (64 characters by default, though this can be changed) if they will fit. Otherwise, the prettyprinter will break them up into multiple lines, preferring to show one member per line if possible. <code>f</code>, Factor's false/nil value, is used to indicate a missing payload.
<lang factor>USING: formatting kernel math qw sequences sequences.deep ;
IN: rosetta-code.nested-template-data

CONSTANT: payloads qw{
Payload#0
Payload#1
Payload#2
Payload#3
Payload#4
Payload#5
Payload#6
}

: insert-payloads ( template -- data-structure )
[ dup fixnum? [ payloads ?nth ] when ] deep-map ;
{ { { 1 2 }
{ 3 4 1 }
5 } }
{ { { 1 2 }
{ 10 4 1 }
5 } }
[
dup insert-payloads "Template: %u\nData Structure: %u\n"
printf
] bi@</lang>
{{out}}
<pre>
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" }
{ f "Payload#4" "Payload#1" }
"Payload#5"
}
}
</pre>


=={{header|Perl 6}}==
=={{header|Perl 6}}==