PersistentSymbol
✖
PersistentSymbol
represents the persistent symbol associated with name stored in persistence location loc.
represents the persistent symbol associated with name at the first of the locations loci at which it occurs.
Details and Options



- PersistentSymbol["name",…] evaluates to give the corresponding persistent value.
- PersistentSymbol["name",…]=value sets a persistent value.
- PersistentSymbol allows the following options:
-
MergingFunction Automatic the function applied to the list of values found ValuePreprocessingFunction Identity the function applied to new values to be assigned ExpirationDate None when the value should expire PersistenceTime None how long the value should persist - In PersistentSymbol["name",loc], possible forms for the persistence location loc include:
-
PersistenceLocation["type"] "Local", "Cloud", "FrontEndSession", etc. locations "type" equivalent to PersistenceLocation["type"] PersistenceLocation["type","base"] location with a particular base (directory etc.) "type""base" equivalent to PersistenceLocation["type","base"] - Supported location types include:
-
"KernelSession" current invocation of the Wolfram Language kernel "FrontEndSession" current invocation of the Wolfram Notebook front end "Notebook" the notebook in which the current evaluation is being done "Local" local to a computer, based on user home directory "LocalShared" local to a computer, based on $BaseDirectory "Cloud" in the cloud defined by the current $CloudBase "Installation" installation defaults - PersistentSymbol["name"] is equivalent to PersistentSymbol["name",$PersistencePath].
- PersistentSymbol["name"]=value is equivalent to PersistentSymbol["name",$PersistenceBase]=value.
- PersistentSymbol["name",loc] is essentially PersistentObject["name",loc]["Value"].
- When a single persistence location is specified, as in PersistentSymbol["name",loc,…], the setting for MergingFunction is not used.
- Otherwise, with the setting MergingFunction->f, the final value returned is the result of applying the function f to the list of values found at all persistence locations.
- Unless specified otherwise by "MergingFunction" metadata in the PersistentObject, MergingFunction->Automatic is equivalent to MergingFunction->First.
- Before a new value is assigned in PersistentSymbol[sym]=value, any specified value preprocessing function is applied to value before the value is assigned.
- If the preprocessing function returns $Failed, the assignment is not performed.
- If no explicit setting for ValuePreprocessingFunction is given, the setting to use is looked up on $PersistencePath.
- An expired persistent symbol is treated as nonexistent, and the underlying persistent object may be removed.
- Persistent symbols can be removed with Remove. Remove[PersistentSymbol["name"]] is equivalent to Remove[PersistentSymbol["name",$PersistenceBase]].
Examples
open allclose allBasic Examples (3)Summary of the most common use cases

https://wolfram.com/xid/0yv8tnbcthf2-zfd0wp

Retrieve a previously saved value:

https://wolfram.com/xid/0yv8tnbcthf2-jy2s2b

Remember a value with front end session scope:

https://wolfram.com/xid/0yv8tnbcthf2-0oic9b
Use the saved value, even in a newly restarted kernel within the same front end session:

https://wolfram.com/xid/0yv8tnbcthf2-kemrac
Store values for the same name at different persistence locations:

https://wolfram.com/xid/0yv8tnbcthf2-y67lle
Retrieve the first value found:

https://wolfram.com/xid/0yv8tnbcthf2-70vj2x

Retrieve the list of all values on $PersistencePath:

https://wolfram.com/xid/0yv8tnbcthf2-qrlgbe

Scope (8)Survey of the scope of standard use cases
Persistence Locations (3)
Persistent symbols created in the "KernelSession" location disappear when the kernel quits:

https://wolfram.com/xid/0yv8tnbcthf2-6r0lyq

https://wolfram.com/xid/0yv8tnbcthf2-3z1nm3


https://wolfram.com/xid/0yv8tnbcthf2-0c8xoe

https://wolfram.com/xid/0yv8tnbcthf2-jvjvlh

Persistent symbols created in the "FrontEndSession" location survive a kernel restart:

https://wolfram.com/xid/0yv8tnbcthf2-25yx5w

https://wolfram.com/xid/0yv8tnbcthf2-64ee8d


https://wolfram.com/xid/0yv8tnbcthf2-08d95c

https://wolfram.com/xid/0yv8tnbcthf2-lynth0

These symbols disappear when the front end is restarted:

https://wolfram.com/xid/0yv8tnbcthf2-usbl96

Persistent symbols in the "Local" location are stored in a file in your account:

https://wolfram.com/xid/0yv8tnbcthf2-gmcwo1
These symbols are stored under the $LocalBase directory and remain indefinitely:

https://wolfram.com/xid/0yv8tnbcthf2-eglywm

Reassignment Functions (5)
Modify values of persistent symbols:

https://wolfram.com/xid/0yv8tnbcthf2-n800r1

https://wolfram.com/xid/0yv8tnbcthf2-p7li4y


https://wolfram.com/xid/0yv8tnbcthf2-c5eni6


https://wolfram.com/xid/0yv8tnbcthf2-456tzg


https://wolfram.com/xid/0yv8tnbcthf2-1u4nsd

https://wolfram.com/xid/0yv8tnbcthf2-gxhejo


https://wolfram.com/xid/0yv8tnbcthf2-0yts2j


https://wolfram.com/xid/0yv8tnbcthf2-5v2aji


https://wolfram.com/xid/0yv8tnbcthf2-bthbaf

https://wolfram.com/xid/0yv8tnbcthf2-9o4nuy


https://wolfram.com/xid/0yv8tnbcthf2-ma8nvq

https://wolfram.com/xid/0yv8tnbcthf2-y67mbm


https://wolfram.com/xid/0yv8tnbcthf2-gc9lbm


https://wolfram.com/xid/0yv8tnbcthf2-y9l9b4

https://wolfram.com/xid/0yv8tnbcthf2-x15wyn


https://wolfram.com/xid/0yv8tnbcthf2-wy09hl


https://wolfram.com/xid/0yv8tnbcthf2-5j2snj

Modify elements of association values:

https://wolfram.com/xid/0yv8tnbcthf2-7jmmtc

https://wolfram.com/xid/0yv8tnbcthf2-3vtzq5


https://wolfram.com/xid/0yv8tnbcthf2-3wt56t


https://wolfram.com/xid/0yv8tnbcthf2-bxd7yi

https://wolfram.com/xid/0yv8tnbcthf2-1z93g3


https://wolfram.com/xid/0yv8tnbcthf2-tauiee

https://wolfram.com/xid/0yv8tnbcthf2-v0l884

Options (8)Common values & functionality for each option
ExpirationDate (2)
Define a persistent value that expires at the beginning of the year 2020:

https://wolfram.com/xid/0yv8tnbcthf2-9fntf
Verify the expiration date of the underlying persistent object:

https://wolfram.com/xid/0yv8tnbcthf2-5zmt4q

Define a persistent value that expires at the beginning of next year:

https://wolfram.com/xid/0yv8tnbcthf2-j07py1
Verify the expiration date of the underlying persistent object:

https://wolfram.com/xid/0yv8tnbcthf2-v3isv9

MergingFunction (3)
Create a complement of persistent values with key "lval" at various locations:

https://wolfram.com/xid/0yv8tnbcthf2-cqxfrv
List all existing values for the key "lval" on $PersistencePath:

https://wolfram.com/xid/0yv8tnbcthf2-bvu4r6

By default, only the first value is returned:

https://wolfram.com/xid/0yv8tnbcthf2-7kqeo9

Join and flatten all sublists:

https://wolfram.com/xid/0yv8tnbcthf2-r8u53h


https://wolfram.com/xid/0yv8tnbcthf2-hpk530

Create a complement of persistent associations with name "aval" at various locations:

https://wolfram.com/xid/0yv8tnbcthf2-otm1fh
List all existing values on $PersistencePath:

https://wolfram.com/xid/0yv8tnbcthf2-ode0vg

Merge the values of identical keys in the associations:

https://wolfram.com/xid/0yv8tnbcthf2-wy6rat

Define a default value for "mylist" with a custom merging function:

https://wolfram.com/xid/0yv8tnbcthf2-byvsa7

https://wolfram.com/xid/0yv8tnbcthf2-xwynw2


https://wolfram.com/xid/0yv8tnbcthf2-66d0sf
Define additional values at different persistence locations:

https://wolfram.com/xid/0yv8tnbcthf2-2c29n1
For looking up values, the custom merging function is now used:

https://wolfram.com/xid/0yv8tnbcthf2-0kusfb

PersistenceTime (2)
Define a persistent value that expires in 5 seconds:

https://wolfram.com/xid/0yv8tnbcthf2-feydku
After 5 seconds, it is no longer used:

https://wolfram.com/xid/0yv8tnbcthf2-64fdyh


Define a persistent object that expires in 5 days:

https://wolfram.com/xid/0yv8tnbcthf2-gd6j5n
Verify the expiration date of the underlying persistent object:

https://wolfram.com/xid/0yv8tnbcthf2-3rai1q

ValuePreprocessingFunction (1)
Define a value preprocessing function that accepts only integers:

https://wolfram.com/xid/0yv8tnbcthf2-wy7p8l
Set up a default value and the value preprocessing function for a persistent value named "int":

https://wolfram.com/xid/0yv8tnbcthf2-3vhtnm

https://wolfram.com/xid/0yv8tnbcthf2-1gs9ga


https://wolfram.com/xid/0yv8tnbcthf2-b3ne4m
Assign an integer at any persistence location:

https://wolfram.com/xid/0yv8tnbcthf2-4y9vyv
Assigning anything else generates an error, and the assignment is not performed:

https://wolfram.com/xid/0yv8tnbcthf2-3p8rlt


https://wolfram.com/xid/0yv8tnbcthf2-8bwm3f

Applications (1)Sample problems that can be solved with this function
Properties & Relations (5)Properties of the function, and connections to other functions
Persistent values are stored in persistent objects:

https://wolfram.com/xid/0yv8tnbcthf2-znxbp5

https://wolfram.com/xid/0yv8tnbcthf2-ykv2li

The default location of a new persistent object is given by $PersistenceBase:

https://wolfram.com/xid/0yv8tnbcthf2-0rorvd

https://wolfram.com/xid/0yv8tnbcthf2-53t88y

Create a complement of persistent values with key "v" at various locations:

https://wolfram.com/xid/0yv8tnbcthf2-otdl6x
Persistent values are by default searched on all locations given in $PersistencePath:

https://wolfram.com/xid/0yv8tnbcthf2-ynro40

The first value found is returned:

https://wolfram.com/xid/0yv8tnbcthf2-ktafgq

With MergingFunction->Identity, all values found are returned in a list:

https://wolfram.com/xid/0yv8tnbcthf2-fr72sg

Specify an explicit list of locations to search for values:

https://wolfram.com/xid/0yv8tnbcthf2-hyzsk4

Expiration times specified with PersistenceTime are converted to absolute expiration dates:

https://wolfram.com/xid/0yv8tnbcthf2-4wzuuj

https://wolfram.com/xid/0yv8tnbcthf2-omrh0l

Persistent values can be removed with Remove:

https://wolfram.com/xid/0yv8tnbcthf2-xeaxv2

https://wolfram.com/xid/0yv8tnbcthf2-blsooy

https://wolfram.com/xid/0yv8tnbcthf2-j8o8qt

Possible Issues (1)Common pitfalls and unexpected behavior
Create two persistent values for "name" in different locations:

https://wolfram.com/xid/0yv8tnbcthf2-dhsrmc
Remove by default removes only the value in the location given by $PersistenceBase:

https://wolfram.com/xid/0yv8tnbcthf2-y8e29a

https://wolfram.com/xid/0yv8tnbcthf2-jdbo4p

Remove all values that might exist anywhere in the locations given by $PersistencePath:

https://wolfram.com/xid/0yv8tnbcthf2-6iica

https://wolfram.com/xid/0yv8tnbcthf2-3dvr9p

Wolfram Research (2021), PersistentSymbol, Wolfram Language function, https://reference.wolfram.com/language/ref/PersistentSymbol.html.
Text
Wolfram Research (2021), PersistentSymbol, Wolfram Language function, https://reference.wolfram.com/language/ref/PersistentSymbol.html.
Wolfram Research (2021), PersistentSymbol, Wolfram Language function, https://reference.wolfram.com/language/ref/PersistentSymbol.html.
CMS
Wolfram Language. 2021. "PersistentSymbol." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PersistentSymbol.html.
Wolfram Language. 2021. "PersistentSymbol." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PersistentSymbol.html.
APA
Wolfram Language. (2021). PersistentSymbol. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PersistentSymbol.html
Wolfram Language. (2021). PersistentSymbol. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PersistentSymbol.html
BibTeX
@misc{reference.wolfram_2025_persistentsymbol, author="Wolfram Research", title="{PersistentSymbol}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/PersistentSymbol.html}", note=[Accessed: 26-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_persistentsymbol, organization={Wolfram Research}, title={PersistentSymbol}, year={2021}, url={https://reference.wolfram.com/language/ref/PersistentSymbol.html}, note=[Accessed: 26-March-2025
]}