Notifications
Clear all
[Closed] recursive function?
Jul 11, 2013 4:15 pm
Written a very simple recursive function to test with:
fn funcion_print_child obj =
(
for child in obj.children do
(
funcion_print_child child
print obj
)
)
funcion_print_child (selection[1])
How can I limit how deep the recursion can go? Instead letting it complete to its natural end.
2 Replies
Jul 11, 2013 4:15 pm
pass the depth to every next recursion:
fn getDescendants node descendants:#() descent:0 lastDescent:3 =
(
if (descent += 1) <= lastDescent do
(
join descendants node.children
for child in node.children do getDescendants child descendants:descendants descent:descent lastDescent:lastDescent
)
descendants
)
/*
delete objects
d =
(
in (d = dummy name:"root")
(
in (dummy()) in (dummy()) in (dummy()) in (dummy()) dummy()
)
d
)
getDescendants d lastDescent:3
getDescendants d lastDescent:4
*/