Function Repository Resource:

SetTo

Source Notebook

Use as an operator form of Set

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["SetTo"][expr][value]

is equivalent to expr = value.

ResourceFunction["SetTo"][{e1,e2,}][{v2,v2,}]

sets the value of each ei to vi.

Examples

Basic Examples (3) 

Use an operator form of Set:

In[1]:=
ResourceFunction["SetTo"][x][1 + 1]
Out[1]=

The value of x has changed:

In[2]:=
x
Out[2]=

Set a value with postfix notation:

In[3]:=
Range[10] // Reverse // Most // ResourceFunction["SetTo"][x]
Out[3]=
In[4]:=
x
Out[4]=

Set multiple values:

In[5]:=
Range[3] // ResourceFunction["SetTo"][{x, y, z}]
Out[5]=
In[6]:=
x + y^2 + z^3
Out[6]=

Scope (2) 

The expr doesn’t need to be a symbol:

In[7]:=
{HoldFirst, Listable} // ResourceFunction["SetTo"][Attributes[f]]
Out[7]=
In[8]:=
Attributes[f]
Out[8]=

Use Unevaluated to delay evaluation:

In[9]:=
Print[Now] // Unevaluated // ResourceFunction["SetTo"][$currentTime]
In[10]:=
Pause[3]; $currentTime
In[11]:=
Definition[$currentTime]
Out[11]=

Applications (2) 

Use as a callback function:

In[12]:=
URLSubmit["http://www.wolfram.com", HandlerFunctions -> <|
   "BodyReceived" -> ResourceFunction["SetTo"][result]|>, HandlerFunctionsKeys -> {"BodyByteArray"}]
Out[12]=

Check the value:

In[13]:=
result
Out[13]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 08 February 2019

License Information