Questions on Rank of a List/Atom

Can someone point me to a formal definition of how rank is defined on a list.  I believe I understand how it’s defined, I just want to make sure I’m clear one it.

Now is the rank of an atom by definition 0 or undefined?  Since an atom has no structure I have heard arguments that it is undefined, because it cannot have a rank or shape, though it’s also possible in other situations to say it has a rank of 0 and a shape of `long$().

Any insight or references would be appreciated.

Is rank equivalent to the number of levels of recursion of the struct in the C client library?

http://code.kx.com/wiki/Cookbook/InterfacingWithC
http://code.kx.com/wsvn/code/kx/kdb%2B/c/c/k.h

Because a list can be arbitrarily nested, it’s possible to refer to both its minimum depth (the depth of it shallowest atom) and maximum depth (the depth of its deepest atom).  I believe rank is equal to the minimum depth of a list, but I was hoping to see a definition somewhere in the official documentation.  I have not been able to find anything yet.

E.g.,

(1; (2; (3; 4 5))) has a minimum depth of 1 and a maximum depth of 4.

I would refer to it as a rank-1 list with a depth of 4, and a shape of ,2.

http://www.jsoftware.com/papers/j4apl1.htm#items

Please consider rank=max depth of the recursive array. I think rank would be same as the dimensions of a C-style multi-dimensional array, assuming it is rectangular at every level.

http://www.jsoftware.com/papers/tot1.htm#1.3

Actually I believe I’m wrong on the minimum depth defining rank as I have seen empirically that:

(1 2; 3) is considered to be rank 2 whereas,

(1; 2 3) is rank 1.

It’s obviously got something to do with the first item, but I have no been able to figure out the formal rule yet.

Maybe it just recurse into the first element of each level to get the depth. Full depth-first search is quite expensive.

Very good Yan Yan!  This is the same conclusion I came to last night while trying to figure this out.  Thanks for your help with this!