Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Hold an expression and make its content inaccessible to other functions
ResourceFunction["NoEntry"][expr] returns a Hold object that maintains expr in an unevaluated form and prevents access even from functions like ReplaceAll and Part. |
NoEntry returns a special Hold object:
In[1]:= |
Out[1]= |
NoEntry prevents its contents from being modified by ReplaceAll, unlike normal Hold:
In[2]:= |
Out[2]= |
NoEntry objects cannot be accessed by Part:
In[3]:= |
Out[3]= |
Remove the Hold wrapper again to access the contents:
In[4]:= |
In[5]:= |
Out[5]= |
The FullForm is the same as a regular Hold object:
In[6]:= |
Out[6]= |
Use Evaluate to evaluate the contents of NoEntry before making them inaccessible:
In[7]:= |
Out[7]= |
NoEntry can be used in ragged expressions to make it easy to find the lowest-level elements if those elements still have some internal structure. Consider the following linked list of symbolic numbers:
In[8]:= |
Out[8]= |
Mapping a function to the numbers inside the linked list can be difficult because the {-1} level specification doesn't correspond to the list elements:
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
NoEntry hides the internal structure of the elements:
In[11]:= |
Out[11]= |
In[12]:= |
Out[12]= |
Map the function to the numbers:
In[13]:= |
Out[13]= |
Use a Listable Function to apply NoEntry at the bottom of ragged arrays:
In[14]:= |
Out[14]= |
NoEntry objects are atoms:
In[15]:= |
Out[15]= |
The contents of NoEntry objects are accessible by pattern matching the whole Hold object:
In[16]:= |
Out[16]= |
In[17]:= |
In[18]:= |
Out[18]= |
ReleaseHold doesn't work on objects created by NoEntry:
In[19]:= |
Out[19]= |
NoEntry needs to evaluate before it becomes inaccessible, so it doesn't work directly when placed inside another inert wrapper like Hold:
In[20]:= |
Out[20]= |
The following replacement rule can be used to force all NoEntry objects to evaluate inside an expression:
In[21]:= |
Out[21]= |
Now the contents of NoEntry are inaccessible:
In[22]:= |
Out[22]= |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License