Multiple distinct objects: Difference between revisions
Content added Content deleted
Line 596: | Line 596: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
This concept is relevant to tables in Lua |
<lang Lua>-- This concept is relevant to tables in Lua |
||
local table1 = {1,2,3} |
|||
The following will create a table of references to table1 |
-- The following will create a table of references to table1 |
||
⚫ | |||
⚫ | |||
for i = 1, 10 do refTab[i] = table1 end |
|||
⚫ | |||
return refTab |
|||
end |
|||
⚫ | |||
local mistake = nRefs(table1, 10)</lang> |
|||
⚫ | |||
⚫ | |||
<lang Lua>function copy (t) |
|||
local new = {} |
local new = {} |
||
for k, v in pairs(t) do new[k] = v end |
for k, v in pairs(t) do new[k] = v end |
||
return new |
return new |
||
end</lang> |
|||
⚫ | |||
<lang Lua>function nCopies (t, n) |
|||
⚫ | |||
for i = 1, 10 do copyTab[i] = copy(table1) end |
|||
return copyTab |
|||
end |
end |
||
⚫ | |||
local tableOfTables = nCopies(table1, 10)</lang> |
|||
local copyTab = {} |
|||
⚫ | |||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |