4
$\begingroup$

I was working with a LocalSymbol, but after I deleted the cell I came back to the notebook hours later only to forget the name of the variable!

Is there anyway to see a full list of the named LocalSymbol objects that persist in a notebook?

I tried looking for them with Names[] but it doesn't show them.

$\endgroup$
7
  • $\begingroup$ They can in general be stored anywhere, but I imagine FileNames[$LocalSymbolBase] should get most of them. $\endgroup$ Jan 19, 2016 at 22:19
  • $\begingroup$ @PatrickStevens This isn't working for me: In[7]:= LocalSymbol["ab"] = 1 Out[7]= 1 In[8]:= FileNames[$LocalSymbolBase] Out[8]= {} $\endgroup$
    – M.R.
    Jan 19, 2016 at 22:28
  • $\begingroup$ Sorry, my bad - FileNames doesn't do what I remembered it doing. SetDirectory[$LocalSymbolBase]; FileNames[] would work instead, except that for some unearthly reason $LocalSymbolBase has a protocol on the front, so it isn't directly a directory. $\endgroup$ Jan 19, 2016 at 22:33
  • $\begingroup$ @PatrickStevens That is giving me a SetDirectory::cdir: Cannot set current directory to file:///Users/Library/Wolfram/Objects/LocalSymbols. >> $\endgroup$
    – M.R.
    Jan 19, 2016 at 22:35
  • $\begingroup$ Precisely my point. You should be able to just trim the file:// protocol from the front. $\endgroup$ Jan 19, 2016 at 22:40

2 Answers 2

6
$\begingroup$

I know of no better way than to just look in the local symbols directory. While it's not necessarily true that all local symbols are stored there, it should be true of the defaults (that is, those made as LocalSymbol["name"]).

Now, $LocalSymbolBase is a string with a protocol prefix (presumably to match it up with $CloudSymbolBase, although since that is a CloudObject anyway, I'm not sure that the matching-up is very good). Therefore, we can't SetDirectory to it immediately. I don't know of a way to get rid of that using a built-in, so I'll just do the following:

removePrefix[str_String] := If[StringTake[str, 7] === "file://", StringTake[str, 8;;], str]

Then the function you want is:

Module[{ret}, 
 SetDirectory[removePrefix@$LocalSymbolBase];
 ret = FileNames[];
 ResetDirectory[];
 ret
]
$\endgroup$
3
$\begingroup$

There is another way to view the local symbol directory that you might try.

SystemOpen[$LocalSymbolBase]

On my system, OS X, this opens a Finder window showing the folder containing the currently existing local symbols.

local_symbols

$\endgroup$
1
  • $\begingroup$ Works on windows 10 as well. Very nice! $\endgroup$ Dec 2, 2016 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.