Function Repository Resource:

HoldArguments

Source Notebook

Construct a function from another function that holds certain arguments

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["HoldArguments"][f]

creates a function equivalent to f that holds all its arguments.

ResourceFunction["HoldArguments"][f,i]

creates a function that holds the ith argument.

ResourceFunction["HoldArguments"][f,{i1,i2,,in}]

creates a function that holds arguments i1,i2,,in.

Examples

Basic Examples (3) 

Create a new function from Print that does not evaluate its arguments:

In[1]:=
printHeld = ResourceFunction["HoldArguments"][Print]
Out[1]=
In[2]:=
printHeld[1 + 1, ", ", 2 + 2]

Create a new function from ToString that holds the first argument:

In[3]:=
makeString = ResourceFunction["HoldArguments"][ToString, 1]
Out[3]=
In[4]:=
makeString[1 + 1, InputForm]
Out[4]=

Create a new function from Apply that holds the second argument:

In[5]:=
applyNow = ResourceFunction["HoldArguments"][Apply, 2]
Out[5]=
In[6]:=
applyNow[List, 1 + 2 + 3]
Out[6]=
In[7]:=
applyNow[Print, 1 + 2 + 3]

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 09 January 2019

License Information