Wolfram Research

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

Use an operator form of Set:

In[1]:=
ResourceFunction["d68a3a1b-9180-4c93-bb0c-89bf58c8ac32"][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["d68a3a1b-9180-4c93-bb0c-89bf58c8ac32"][x]
Out[3]=
In[4]:=
x
Out[4]=

Set multiple values:

In[5]:=
Range[3] // ResourceFunction["d68a3a1b-9180-4c93-bb0c-89bf58c8ac32"][{x, y, z}]
Out[5]=
In[6]:=
x + y^2 + z^3
Out[6]=

Scope

The expr doesn’t need to be a symbol:

In[7]:=
{HoldFirst, Listable} // ResourceFunction["d68a3a1b-9180-4c93-bb0c-89bf58c8ac32"][
  Attributes[f]]
Out[7]=
In[8]:=
Attributes[f]
Out[8]=

Use Unevaluated to delay evaluation:

In[9]:=
Print[Now] // Unevaluated // ResourceFunction[
  "d68a3a1b-9180-4c93-bb0c-89bf58c8ac32"][$currentTime]
In[10]:=
Pause[3]; $currentTime
In[11]:=
Definition[$currentTime]
Out[11]=

Applications

Use as a callback function:

In[12]:=
URLSubmit["http://www.wolfram.com", HandlerFunctions -> <|
   "BodyReceived" -> ResourceFunction["d68a3a1b-9180-4c93-bb0c-89bf58c8ac32"][
     result]|>, HandlerFunctionsKeys -> {"BodyByteArray"}]
Out[12]=

Check the value:

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

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information