Nested templated data: Difference between revisions
add SETL
m (→{{header|Wren}}: Minor tidy) |
Not a robot (talk | contribs) (add SETL) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 102:
Undefined_indices : [8]
Unused_Payloads : ["Payload#6", "Payload#7"]</pre>
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">dim p(7)
dim p$(7)
p$[0] = "Payload#0" : p$[1] = "Payload#1"
p$[2] = "Payload#2" : p$[3] = "Payload#3"
p$[4] = "Payload#4" : p$[5] = "Payload#5"
p$[6] = "Payload#6"
dim q(7) fill false
dim t(4, 5)
t[0, 0] = 1: t[0, 1] = 2
t[1, 0] = 3: t[1, 1] = 4: t[1, 2] = 1
t[2, 0] = 5
for i = 0 to t[?][]-1
for j = 0 to t[?][]-1
if t[i, j] <> 0 then
q[t[i, j]] = true
t[i, j] += 1
end if
next j
next i
for i = 0 to t[?][]-1
for j = 0 to t[?][]-1
if t[i, j] <> 0 then print p$[t[i, j] -1]; " ";
next j
print
next i
for i = 0 to q[?]-1
if not q[i] then print p$[i]; " is not used"
next i</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|Chipmunk Basic}}===
{{trans|FreeBASIC}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">100 cls
110 dim i,j,p(6)
120 dim p$(6)
130 p$(0) = "Payload#0" : p$(1) = "Payload#1"
140 p$(2) = "Payload#2" : p$(3) = "Payload#3"
150 p$(4) = "Payload#4" : p$(5) = "Payload#5"
160 p$(6) = "Payload#6"
170 dim q(6)
180 dim t(2,3)
190 t(0,0) = 1 : t(0,1) = 2
200 t(1,0) = 3 : t(1,1) = 4 : t(1,2) = 1
210 t(2,0) = 5
220 for i = 0 to ubound(t)
230 for j = 0 to ubound(t,2)
240 if t(i,j) <> 0 then
250 q(t(i,j)) = true
260 t(i,j) = t(i,j)+1
270 endif
280 next j
290 next i
300 for i = 0 to ubound(t)
310 for j = 0 to ubound(t,2)
320 if t(i,j) <> 0 then print p$(t(i,j)-1);" ";
330 next j
340 print
350 next i
360 for i = 0 to ubound(q)
370 if not q(i) then print p$(i);" is not used"
380 next i
390 end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|FreeBASIC}}===
{{trans|Ring}}
<syntaxhighlight lang="vbnet">Dim As Integer t(2, 3) = {{1,2},{3,4,1},{5}}
Dim As Integer i, j, p(6)
Dim As String pStr(6) = {"Payload#0", "Payload#1", "Payload#2", "Payload#3", "Payload#4", "Payload#5", "Payload#6"}
Dim As Boolean q(6)
For i = Lbound(t) To Ubound(t)
For j = Lbound(t, 2) To Ubound(t, 2)
If t(i, j) <> 0 Then
q(t(i, j)) = True
t(i, j) += 1
End If
Next j
Next i
For i = Lbound(t) To Ubound(t)
For j = Lbound(t, 2) To Ubound(t, 2)
If t(i, j) <> 0 Then Print pStr(t(i, j)-1); " ";
Next j
Print
Next i
For i = Lbound(q) To Ubound(q)
If q(i) = False Then Print pStr(i); " is not used"
Next i
Sleep</syntaxhighlight>
{{out}}
<pre>Payload#1 Payload#2
Payload#3 Payload#4 Payload#1
Payload#5
Payload#0 is not used
Payload#6 is not used</pre>
==={{header|GW-BASIC}}===
{{trans|FreeBASIC}}
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic}}
{{works with|MSX BASIC}}
{{works with|QBasic}}
{{works with|QB64}}
<syntaxhighlight lang="qbasic">110 TRUE = -1
120 FALSE = NOT TRUE
130 DIM I,J,P(6)
140 DIM P$(6)
150 P$(0) = "Payload#0" : P$(1) = "Payload#1"
160 P$(2) = "Payload#2" : P$(3) = "Payload#3"
170 P$(4) = "Payload#4" : P$(5) = "Payload#5"
180 P$(6) = "Payload#6"
190 DIM Q(6)
200 DIM T(2,3)
210 T(0,0) = 1 : T(0,1) = 2
220 T(1,0) = 3 : T(1,1) = 4 : T(1,2) = 1
230 T(2,0) = 5
240 FOR I = 0 TO 2
250 FOR J = 0 TO 3
260 IF T(I,J) <> 0 THEN Q(T(I,J)) = TRUE : T(I,J) = T(I,J)+1
270 NEXT J
280 NEXT I
290 FOR I = 0 TO 2
300 FOR J = 0 TO 3
310 IF T(I,J) <> 0 THEN PRINT P$(T(I,J)-1);" ";
320 NEXT J
330 PRINT
340 NEXT I
350 FOR I = 0 TO 6
360 IF Q(I) = FALSE THEN PRINT P$(I);" is not used"
370 NEXT I
380 END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|QB64}}
<syntaxhighlight lang="qbasic">True = -1: False = NOT True
DIM p(6)
DIM p$(6)
p$(0) = "Payload#0": p$(1) = "Payload#1"
p$(2) = "Payload#2": p$(3) = "Payload#3"
p$(4) = "Payload#4": p$(5) = "Payload#5"
p$(6) = "Payload#6"
DIM q(6)
DIM t(2, 3)
t(0, 0) = 1: t(0, 1) = 2
t(1, 0) = 3: t(1, 1) = 4: t(1, 2) = 1
t(2, 0) = 5
FOR i = LBOUND(t) TO UBOUND(t) '0 To 2
FOR j = LBOUND(t, 2) TO UBOUND(t, 2) '0 To 3
IF t(i, j) <> 0 THEN
q(t(i, j)) = True
t(i, j) = t(i, j) + 1
END IF
NEXT j
NEXT i
FOR i = LBOUND(t) TO UBOUND(t) '0 To 2
FOR j = LBOUND(t, 2) TO UBOUND(t, 2) '0 To 3
IF t(i, j) <> 0 THEN PRINT p$(t(i, j) - 1); " ";
NEXT j
PRINT
NEXT i
FOR i = LBOUND(q) TO UBOUND(q)
IF q(i) = False THEN PRINT p$(i); " is not used"
NEXT i</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|QB64}}===
The [[#QBasic|QBasic]] solution works without any changes.
==={{header|Run BASIC}}===
{{trans|QBasic}}
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
{{works with|QBasic}}
{{works with|QB64}}
<syntaxhighlight lang="qbasic">DIM p(6)
DIM p$(6)
p$(0) = "Payload#0": p$(1) = "Payload#1"
p$(2) = "Payload#2": p$(3) = "Payload#3"
p$(4) = "Payload#4": p$(5) = "Payload#5"
p$(6) = "Payload#6"
DIM q(6)
DIM t(2, 3)
t(0, 0) = 1: t(0, 1) = 2
t(1, 0) = 3: t(1, 1) = 4: t(1, 2) = 1
t(2, 0) = 5
FOR i = 0 TO 2
FOR j = 0 TO 3
IF t(i, j) <> 0 THEN
q(t(i, j)) = -1
t(i, j) = t(i, j) + 1
END IF
NEXT j
NEXT i
FOR i = 0 TO 2
FOR j = 0 TO 3
IF t(i, j) <> 0 THEN PRINT p$(t(i, j) - 1); " ";
NEXT j
PRINT
NEXT i
FOR i = 0 TO 6
IF q(i) = 0 THEN PRINT p$(i); " is not used"
NEXT i</syntaxhighlight>
{{out}}
<pre>Same as QBasic entry.</pre>
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">dim p(6)
dim p$(6)
p$(0) = "Payload#0" : p$(1) = "Payload#1"
p$(2) = "Payload#2" : p$(3) = "Payload#3"
p$(4) = "Payload#4" : p$(5) = "Payload#5"
p$(6) = "Payload#6"
dim q(6)
dim t(2, 3)
t(0, 0) = 1: t(0, 1) = 2
t(1, 0) = 3: t(1, 1) = 4: t(1, 2) = 1
t(2, 0) = 5
for i = 0 to arraysize(t(), 1)
for j = 0 to arraysize(t(), 2)
if t(i, j) <> 0 then
q(t(i, j)) = True
t(i, j) = t(i, j) + 1
fi
next j
next i
for i = 0 to arraysize(t(), 1)
for j = 0 to arraysize(t(), 2)
if t(i, j) <> 0 print p$(t(i, j) -1), " ";
next j
print
next i
for i = 0 to arraysize(q(), 1)
if not q(i) print p$(i), " is not used"
next i</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
=={{header|Bracmat}}==
Line 1,300 ⟶ 1,574:
Data structure: ((("Payload#1", "Payload#2"), (Any, "Payload#4", "Payload#1"), "Payload#5"),)</pre>
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, (((1 2) (3 4 1) 5)): e.Template
, "Payload#0" "Payload#1" "Payload#2" "Payload#3"
"Payload#4" "Payload#5" "Payload#6": e.Payload
= <Prout <Subst (e.Payload) e.Template>>;
};
Subst {
(e.P) = ;
(e.P) s.I e.X = <Item s.I e.P> <Subst (e.P) e.X>;
(e.P) (e.X) e.Y = (<Subst (e.P) e.X>) <Subst (e.P) e.Y>;
};
Item {
0 t.I e.X = t.I;
s.N t.I e.X = <Item <- s.N 1> e.X>;
};</syntaxhighlight>
{{out}}
<pre>(((Payload#1 Payload#2 )(Payload#3 Payload#4 Payload#1 )Payload#5 ))</pre>
=={{header|REXX}}==
===version 1===
Line 1,549 ⟶ 1,843:
Payload 8 is not defined</pre>
=={{header|SETL}}==
<syntaxhighlight lang="setl">program substitution;
template := [[[1,2],[3,4,1],5]];
payload := {
[0,"Payload#0"], [1,"Payload#1"], [2,"Payload#2"], [3,"Payload#3"],
[4,"Payload#4"], [5,"Payload#5"], [6,"Payload#6"]
};
print(subst(template, payload));
proc subst(template, payload);
if not is_tuple(template) then
return(payload(template));
end if;
result := [];
loop for item in template do
result with:= subst(item, payload);
end loop;
return result;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>[[['Payload#1' 'Payload#2'] ['Payload#3' 'Payload#4' 'Payload#1'] 'Payload#5']]</pre>
=={{header|VBA}}==
VBA allows arrays of variant, so the elements of an array can be both scalars as arrays of different sizes.
|