33 lines
581 B
Text
33 lines
581 B
Text
1) Let's create this function
|
|
|
|
{def A.flatten
|
|
{def A.flatten.r
|
|
{lambda {:a}
|
|
{if {A.empty? :a}
|
|
then
|
|
else {let { {:b {A.first :a}}
|
|
} {if {A.array? :b}
|
|
then {A.flatten.r :b}
|
|
else :b} }
|
|
{A.flatten.r {A.rest :a}} }}}
|
|
{lambda {:a}
|
|
{A.new {A.flatten.r :a}}}}
|
|
-> A.flatten
|
|
|
|
and test it
|
|
|
|
{def list
|
|
{A.new
|
|
{A.new 1}
|
|
2
|
|
{A.new {A.new 3 4} 5}
|
|
{A.new {A.new {A.new }}}
|
|
{A.new {A.new {A.new 6}}}
|
|
7
|
|
8
|
|
{A.new}
|
|
}}
|
|
-> [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
|
|
|
|
{A.flatten {list}}
|
|
-> [1,2,3,4,5,6,7,8]
|