Skip to content

Instantly share code, notes, and snippets.

@Floofies
Last active March 9, 2023 07:28
Show Gist options
  • Save Floofies/d81f4d13dc47a49c234c277a624ac12c to your computer and use it in GitHub Desktop.
Save Floofies/d81f4d13dc47a49c234c277a624ac12c to your computer and use it in GitHub Desktop.
Return string representation of every value in the given list. Traverses sub-lists to provide every reachable value.
/// Return string representation of every value in the given list.
/// Traverses sub-lists to provide every reachable value.
/proc/list2string(root)
var/str = "Travsersal Tree for `[root]`:\n"
var/list/seen_lists = list("\ref[root]")
var/list/runqueue = list()
var/list/waitqueue = list()
waitqueue[root] = list("root", " ")
while(length(waitqueue))
runqueue = waitqueue.Copy()
waitqueue.Cut()
for(var/node in runqueue)
var/node_accessor = runqueue[node][1]
var/indent = runqueue[node][2]
runqueue -= node
if(!length(node))
str += ">[indent][node_accessor]: (empty list)\n"
continue
str += ">[indent][node_accessor]:\n"
for(var/accessor as anything in node)
var/value = node[accessor]
if(islist(value))
var/hash = "\ref[value]"
if(hash in seen_lists)
continue
waitqueue[value] = list(accessor, "[indent] ")
seen_lists += hash
else
str += " [indent][accessor]: [isnull(value) ? "null" : value]\n"
return str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment