Nested templated data: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|M2000 Interpreter}}: Second version) |
||
Line 163: | Line 163: | ||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
We can use ? as undefined value. Is an object of internal type VarItem. So we have two big tuples, the second one has two "unused" places, with type of Varitem. |
|||
<lang M2000 Interpreter> |
<lang M2000 Interpreter> |
||
Font "Courier New" |
Font "Courier New" |
||
Line 168: | Line 170: | ||
Module Checkit { |
Module Checkit { |
||
t=(((1,2), (3,4,1),5),) ' use (1,) for one item tuple |
t=(((1,2), (3,4,1),5),) ' use (1,) for one item tuple |
||
⚫ | |||
Payload = lambda (a)->{ |
Payload = lambda (a)->{ |
||
unused=list |
|||
inner=lambda unused, p=0 (a)-> { |
|||
k=each(a) |
|||
res=(,) |
|||
link a to a() |
|||
⚫ | |||
select case type$(a(k^)) |
|||
⚫ | |||
Append res, (Lambda(array(a, k^)),) |
Append res, (Lambda(array(a, k^)),) |
||
Case "VarItem" ' for more than one line need to place in a block |
|||
⚫ | |||
⚫ | |||
Append res, ("Unused#pos"+trim$(str$(p)),) ' one item tuple append to res |
|||
⚫ | |||
append unused, p |
|||
p++ |
|||
} |
|||
else case |
|||
{ |
|||
⚫ | |||
p++ |
|||
} |
|||
end select |
|||
} |
|||
=res |
|||
} |
} |
||
= |
=inner(a), unused |
||
} |
} |
||
Expand$ = |
Expand$ =lambda$ -> { |
||
\\ we can pass a tuple of two arguments or two arguments |
|||
⚫ | |||
Read a as array |
|||
if empty then Data!a : Read a as array, unused as list else read unused as list |
|||
⚫ | |||
inner$= lambda$ (a, feed$=" ")->{ |
|||
k=each(a) |
|||
lim=len(a)-1 |
|||
res$="[" |
|||
link a to a() ' to use type$() |
|||
while k { |
|||
if type$(a(k^))="mArray" then |
|||
res$+=Lambda$(array(a, k^),feed$+" ") |
|||
if k^<lim then |
|||
res$+={, |
|||
}+feed$ |
|||
end if |
|||
else |
|||
res$+= "'"+array$(k)+"'" |
|||
if k^<lim then res$+=", " |
|||
end if |
end if |
||
} |
|||
=res$+"]" |
|||
} |
|||
if len(unused)>1 then |
|||
un=each(unused) |
|||
lim=len(unused)-1 |
|||
document unused$="Unused: " |
|||
while un { |
|||
unused$="pos"+str$(eval(un)) |
|||
if un^<lim then unused$=", " |
|||
} |
|||
=inner$(a)+{ |
|||
}+unused$ |
|||
Else |
|||
=inner$(a)+{ |
|||
⚫ | |||
End if |
|||
} |
} |
||
result$=Expand$(Payload(t)) |
|||
m=Payload((((1,?), (3,4,?),5),)) |
|||
clipboard result$+Expand$(array(m,0), array(m,1)) |
|||
} |
} |
||
Checkit |
Checkit |
||
report Clipboard$ |
report Clipboard$ |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
Line 211: | Line 251: | ||
['Payload#3', 'Payload#4', 'Payload#1'], |
['Payload#3', 'Payload#4', 'Payload#1'], |
||
'Payload#5']] |
'Payload#5']] |
||
[[['Payload#1', 'Unused#pos1'], |
|||
['Payload#3', 'Payload#4', 'Unused#pos4'], |
|||
'Payload#5']] |
|||
Unused: pos 1, pos 4 |
|||
</pre > |
</pre > |
||
1 |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |