---
title: "UpSetDelayed"
language: "en"
type: "Symbol"
summary: "lhs ^:= rhs assigns rhs to be the delayed value of lhs, and associates the assignment with symbols that occur at level one in lhs."
keywords: 
- associated assignment
- associated definition
- delayed assignment
- generic programming
- type based programming
- object programming
canonical_url: "https://reference.wolfram.com/language/ref/UpSetDelayed.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Assignments"
    link: "https://reference.wolfram.com/language/guide/Assignments.en.md"
related_workflows: 
  - 
    title: "Clear Definitions for Symbols and Functions"
    link: "https://reference.wolfram.com/language/workflow/ClearDefinitionsForSymbolsAndFunctions.en.md"
  - 
    title: "Find All Defined Functions"
    link: "https://reference.wolfram.com/language/workflow/FindAllDefinedFunctions.en.md"
related_functions: 
  - 
    title: "UpSet"
    link: "https://reference.wolfram.com/language/ref/UpSet.en.md"
  - 
    title: "TagSetDelayed"
    link: "https://reference.wolfram.com/language/ref/TagSetDelayed.en.md"
  - 
    title: "SetDelayed"
    link: "https://reference.wolfram.com/language/ref/SetDelayed.en.md"
  - 
    title: "UpValues"
    link: "https://reference.wolfram.com/language/ref/UpValues.en.md"
  - 
    title: "Unset"
    link: "https://reference.wolfram.com/language/ref/Unset.en.md"
  - 
    title: "ClearAll"
    link: "https://reference.wolfram.com/language/ref/ClearAll.en.md"
related_tutorials: 
  - 
    title: "Associating Definitions with Different Symbols"
    link: "https://reference.wolfram.com/language/tutorial/TransformationRulesAndDefinitions.en.md#6972"
---
# UpSetDelayed (^:=)

lhs ^:= rhs assigns rhs to be the delayed value of lhs, and associates the assignment with symbols that occur at level one in lhs.

---

## Examples (13)

### Basic Examples (1)

```wl
In[1]:= f[g[x_]] ^:= fg[x]

In[2]:= {f[g[2]], f[h[2]]}

Out[2]= {fg[2], f[h[2]]}
```

### Scope (6)

#### Left-Hand Sides (5)

An expression with a delayed definition is evaluated every time it is used:

```wl
In[1]:= rand[int] ^:= RandomInteger[]

In[2]:= Table[rand[int], {5}]

Out[2]= {0, 1, 0, 0, 0}
```

---

Make definitions for special and general cases using immediate and delayed assignments:

```wl
In[1]:=
f[h[0]] ^= h0;
f[h[x_]] ^:= 2f[h[x - 1]]

In[2]:= f[h[10]]

Out[2]= 1024 h0
```

---

The definition can be associated with a symbol appearing as an argument of the left side:

```wl
In[1]:= area[sq, s_] ^:= s ^ 2

In[2]:= area[sq, 2]

Out[2]= 4
```

---

The definition can be associated with the head of an argument of the left side:

```wl
In[1]:= area[sq[s_]] ^:= s ^ 2

In[2]:= area[sq[3]]

Out[2]= 9
```

---

If several symbols appear in the left-hand side, upvalues for all of them are defined:

```wl
In[1]:= method[g[x_], h[y_]] ^:= fgh[x, y]

In[2]:= Definition[g]

Out[2]= g/:method[g[x_], h[y_]] := fgh[x, y]

In[3]:= Definition[h]

Out[3]= h/:method[g[x_], h[y_]] := fgh[x, y]
```

#### Different Kinds of Values (1)

^:= defines upvalues:

```wl
In[1]:=
f[g[x_]] ^:= f1[x]
f[h[x_]] := f2[x]

In[2]:= {UpValues[g], DownValues[f]}

Out[2]= {{HoldPattern[f[g[x_]]] :> f1[x]}, {HoldPattern[f[h[x_]]] :> f2[x]}}
```

### Properties & Relations (6)

`` ^:= `` defines upvalues in the same way as using a tag does:

```wl
In[1]:= g/:f[g[x_]] := f1[x]

In[2]:= f[h[x_]] ^:= f2[x]

In[3]:= {UpValues[g], UpValues[h]}

Out[3]= {{HoldPattern[f[g[x_]]] :> f1[x]}, {HoldPattern[f[h[x_]]] :> f2[x]}}
```

---

A tag defines only one upvalue; `` ^:= `` makes definitions for all symbols:

```wl
In[1]:= g/:f1[g[x_], h[y_]] := gh[x y]

In[2]:= f2[g[x_], h[y_]] ^:= gh[x y]

In[3]:= {UpValues[g], UpValues[h]}

Out[3]= {{HoldPattern[f1[g[x_], h[y_]]] :> gh[x y], HoldPattern[f2[g[x_], h[y_]]] :> gh[x y]}, {HoldPattern[f2[g[x_], h[y_]]] :> gh[x y]}}
```

---

The right side of an immediate definition is evaluated when the definition is made:

```wl
In[1]:= rand[int] ^= RandomInteger[];

In[2]:= {rand[int], rand[int]}

Out[2]= {0, 0}
```

The right side of a delayed definition is evaluated each time the definition is used:

```wl
In[3]:= rand[real] ^:= RandomReal[]

In[4]:= {rand[real], rand[real]}

Out[4]= {0.409393, 0.730688}
```

---

Definitions with the same left side overwrite earlier ones:

```wl
In[1]:= f[h[x_]] ^:= f1[x]

In[2]:= f[h[x_]] ^:= f2[x]

In[3]:= Definition[h]

Out[3]= f[h[x_]] ^:= f2[x]
```

---

``Definition`` prints definitions associated with a symbol:

```wl
In[1]:= a_mod + b_mod ^:= modPlus[a, b]

In[2]:= Definition[mod]

Out[2]= a_mod + b_mod ^:= modPlus[a, b]
```

``Information`` prints various information about a symbol, including any definitions:

```wl
In[3]:= ? mod

Cell$$4157`mod

a_mod + b_mod ^:= modPlus[a, b]
```

``UpValues`` returns a list of rules corresponding to any upvalues defined:

```wl
In[4]:= UpValues[mod]

Out[4]= {HoldPattern[a_mod + b_mod] :> modPlus[a, b]}
```

---

Delayed assignment introduces a scope that is not affected by global variables:

```wl
In[1]:= x = 5;

In[2]:= f[h[x_]] ^:= x ^ 2

In[3]:= {f[h[2]], x}

Out[3]= {4, 5}
```

Immediate assignment does not introduce a scope:

```wl
In[4]:= g[h[x_]] ^= x ^ 2;

In[5]:= {g[h[2]], x}

Out[5]= {25, 5}
```

## See Also

* [`UpSet`](https://reference.wolfram.com/language/ref/UpSet.en.md)
* [`TagSetDelayed`](https://reference.wolfram.com/language/ref/TagSetDelayed.en.md)
* [`SetDelayed`](https://reference.wolfram.com/language/ref/SetDelayed.en.md)
* [`UpValues`](https://reference.wolfram.com/language/ref/UpValues.en.md)
* [`Unset`](https://reference.wolfram.com/language/ref/Unset.en.md)
* [`ClearAll`](https://reference.wolfram.com/language/ref/ClearAll.en.md)

## Tech Notes

* [Associating Definitions with Different Symbols](https://reference.wolfram.com/language/tutorial/TransformationRulesAndDefinitions.en.md#6972)

## Related Guides

* [`Assignments`](https://reference.wolfram.com/language/guide/Assignments.en.md)

## Related Workflows

* [Clear Definitions for Symbols and Functions](https://reference.wolfram.com/language/workflow/ClearDefinitionsForSymbolsAndFunctions.en.md)
* [Find All Defined Functions](https://reference.wolfram.com/language/workflow/FindAllDefinedFunctions.en.md)

## History

* Introduced in 1988 (1.0)