WOLFRAM

represents the persistent symbol associated with the key "name".

PersistentSymbol["name",loc]

represents the persistent symbol associated with name stored in persistence location loc.

PersistentSymbol["name",{loc1,}]

represents the persistent symbol associated with name at the first of the locations loci at which it occurs.

Details and Options

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Assign a persistent value:

Out[1]=1

Retrieve a previously saved value:

Out[2]=2

Remember a value with front end session scope:

Use the saved value, even in a newly restarted kernel within the same front end session:

Store values for the same name at different persistence locations:

Retrieve the first value found:

Out[2]=2

Retrieve the list of all values on $PersistencePath:

Out[3]=3

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:

Out[2]=2
Out[4]=4

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

Out[2]=2
Out[4]=4

These symbols disappear when the front end is restarted:

Out[5]=5

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

These symbols are stored under the $LocalBase directory and remain indefinitely:

Out[2]=2

Reassignment Functions  (5)

Modify values of persistent symbols:

Out[2]=2
Out[3]=3
Out[4]=4

Modify list values:

Out[2]=2
Out[3]=3
Out[4]=4

Modify parts of list values:

Out[2]=2
Out[4]=4
Out[5]=5

Modify association values:

Out[2]=2
Out[3]=3
Out[4]=4

Modify elements of association values:

Out[2]=2
Out[3]=3
Out[5]=5
Out[7]=7

Options  (8)Common values & functionality for each option

ExpirationDate  (2)

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

Verify the expiration date of the underlying persistent object:

Out[2]=2

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

Verify the expiration date of the underlying persistent object:

Out[2]=2

MergingFunction  (3)

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

List all existing values for the key "lval" on $PersistencePath:

Out[2]=2

By default, only the first value is returned:

Out[3]=3

Join and flatten all sublists:

Out[4]=4

Join all sublists:

Out[5]=5

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

List all existing values on $PersistencePath:

Out[2]=2

Merge the values of identical keys in the associations:

Out[3]=3

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

Out[2]=2

Define additional values at different persistence locations:

For looking up values, the custom merging function is now used:

Out[5]=5

PersistenceTime  (2)

Define a persistent value that expires in 5 seconds:

After 5 seconds, it is no longer used:

Out[2]=2
Out[2]=2

Define a persistent object that expires in 5 days:

Verify the expiration date of the underlying persistent object:

Out[2]=2

ValuePreprocessingFunction  (1)

Define a value preprocessing function that accepts only integers:

Set up a default value and the value preprocessing function for a persistent value named "int":

Out[3]=3

Assign an integer at any persistence location:

Assigning anything else generates an error, and the assignment is not performed:

Out[7]=7

Applications  (1)Sample problems that can be solved with this function

List all existing persistent objects for the key "lval":

Out[1]=1

Delete them:

Properties & Relations  (5)Properties of the function, and connections to other functions

Persistent values are stored in persistent objects:

Out[2]=2

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

Out[2]=2

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

Persistent values are by default searched on all locations given in $PersistencePath:

Out[2]=2

The first value found is returned:

Out[3]=3

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

Out[4]=4

Specify an explicit list of locations to search for values:

Out[5]=5

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

Out[2]=2

Persistent values can be removed with Remove:

Out[3]=3

Possible Issues  (1)Common pitfalls and unexpected behavior

Create two persistent values for "name" in different locations:

Remove by default removes only the value in the location given by $PersistenceBase:

Out[3]=3

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

Out[5]=5
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.

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 ]}

@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 ]}

@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 ]}