Task

Write a function to flatten the nesting in an arbitrary list of values.

Your program should work on the equivalent of this list:

  [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]

Where the correct result would be the list:

   [1, 2, 3, 4, 5, 6, 7, 8]

Related task

   Tree traversal


to flatten :l
  if not list? :l [output :l]
  if empty? :l [output []]
  output sentence flatten first :l flatten butfirst :l
end
 
; using a template iterator (map combining results into a sentence)
to flatten :l
  output map.se [ifelse or not list? ? empty? ? [?] [flatten ?]] :l
end
 
make "a [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]
show flatten :a