Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Similar to ArrayQ, except it allows for ragged collections of nested lists
ResourceFunction["TableQ"][expr,patt] requires expr to be a table with a depth that matches the pattern patt. | |
ResourceFunction["TableQ"][expr,patt,test] requires also that test yield True when applied to each of the table elements in expr. |
Test to see if an expression is a table:
In[1]:= | ![]() |
Out[1]= | ![]() |
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
A vector of numbers is a table:
In[5]:= | ![]() |
Out[5]= | ![]() |
At each level, lists and non-lists cannot be mixed:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
A ragged collection of nested lists is a table:
In[8]:= | ![]() |
Out[8]= | ![]() |
Test for a vector:
In[9]:= | ![]() |
Out[9]= | ![]() |
Test for a matrix:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
Test for a ragged table at level 2:
In[12]:= | ![]() |
Out[12]= | ![]() |
In[13]:= | ![]() |
Out[13]= | ![]() |
Test for a vector or a matrix:
In[14]:= | ![]() |
Out[14]= | ![]() |
Test for a numeric vector:
In[15]:= | ![]() |
Out[15]= | ![]() |
Test for an array of any depth with numeric entries:
In[16]:= | ![]() |
Out[16]= | ![]() |
Define a function that only evaluates with tables of strings:
In[17]:= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
VectorQ is a special case of TableQ:
In[20]:= | ![]() |
In[21]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
In[23]:= | ![]() |
Out[23]= | ![]() |
ArrayQ implies TableQ:
In[24]:= | ![]() |
Out[24]= | ![]() |
In[25]:= | ![]() |
Out[25]= | ![]() |
In[26]:= | ![]() |
Out[26]= | ![]() |
In[27]:= | ![]() |
Out[27]= | ![]() |
The converse is not necessarily true:
In[28]:= | ![]() |
Out[28]= | ![]() |
In[29]:= | ![]() |
Out[29]= | ![]() |
In[30]:= | ![]() |
Out[30]= | ![]() |
In[31]:= | ![]() |
Out[31]= | ![]() |
TableQ[expr,_] is equivalent to ListQ[expr]:
In[32]:= | ![]() |
Out[32]= | ![]() |
In[33]:= | ![]() |
Out[33]= | ![]() |
In[34]:= | ![]() |
Out[34]= | ![]() |
In[35]:= | ![]() |
Out[35]= | ![]() |
In TableQ[expr,_,test], the result will be True if test returns True for all elements of any level:
In[36]:= | ![]() |
Out[36]= | ![]() |
This would normally return False due to mixing lists with non-lists:
In[37]:= | ![]() |
Out[37]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License