JJC15433

Join Testing

Nov 29th, 2020 (edited)
421
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. idx = 1
  2. input={"comfy"}
  3. output={}
  4.  
  5. function join(src,dest)
  6.     if src == dest then
  7.         local temp = {}
  8.         join(src,temp)
  9.         join(temp,dest)
  10.     else
  11.         for k,v in pairs(src) do
  12.             -- print("src entry:",k,v)
  13.             -- if #dest > 0 then print("dest@len:", #dest,dest[#dest]) end
  14.             dest[#dest+1] = v
  15.             -- print("dest@new len:", #dest,dest[#dest])
  16.             -- os.sleep(5)
  17.         end
  18.     end
  19. end
  20.  
  21. print("input:\n",textutils.serialize(input),"\n")
  22. print("output:\n",textutils.serialize(output),"\n")
  23. print("joining...")
  24. join(input, output)
  25. print("output:\n",textutils.serialize(output),"\n")
  26.  
  27.  
  28. temp={}
  29. join(output,temp)
  30. print("temp:\n",textutils.serialize(temp),"\n")
  31. print("joining temp to output...")
  32. join(temp,output)
  33. print("output:\n",textutils.serialize(output),"\n")
  34.  
  35. -- with recursion, we ca concatenate a table to itself without infinite looping
  36. print("joining output to output...")
  37. join(output,output)
  38. print("output:\n",textutils.serialize(output),"\n")
  39.  
  40. emptyTest={}
  41. emptyTest2={}
  42.  
  43. print("emptyTest:\n",textutils.serialize(emptyTest),"\n")
  44. print("emptyTest2:\n",textutils.serialize(emptyTest2),"\n")
  45.  
  46. join(emptyTest2,emptyTest)
  47. print("ET after join w/ET2:\n",textutils.serialize(emptyTest),"\n")
  48. join(emptyTest,emptyTest)
  49. print("ET after self-join:\n",textutils.serialize(emptyTest),"\n")
  50.  
RAW Paste Data