say my trees are nested lists of integers of varying rank. how would you represent the null tree?
if i choose 0 for null, to test for the existence of a null tree in the forest:
q)(0~')(1 2;0)
01b
then |/ to reduce
q)0 in(1 2;0) /doesn’t work because in is rank sensitive
0b
is there a better value for the null tree?
Why not define a function to recursively find a null tree:
q)ntree:{1b in (,/) $[0>(@)x;0 in x;nt each x]}
q)ntree (1 3;5)
0b
q)ntree ((9;(4 5));0)
1b
q)nt (1 2;4;(2;(4;(0 5 6));4))
1b
Tiago
On my previous post ntree and nt were the same function:
Here is the correct definition:
ntree:{1b in (,/) $[0>(@)x;0 in x;ntree each x]}
Or in an arguably more readable q:
ntree:{1b in raze $[0>type x;0 in x;ntree each x]}