const x = list(1,list(2, list(3,4),5), list(6,7));
function tree_map(func, tree){
return map(sub_tree=> is_pair(sub_tree)
? tree_map(func, sub_tree)
: func(sub_tree), tree);
}
function suquare_tree(tree){
return tree_map(square,tree);
}
suquare_tree(x)//[1, [[4, [[9, [16, null]], [25, null]]], [[36, [49, null]], null]]];
728x90